Updating "SENT" to existing DRAFT Package
Monday, May 30, 2016 at 08:37amHi
I'm trying to update the STATUS from "DRAFT" to "SENT" but getting an error. Here is my snippet... Am i missing anything?
try
{
string url = eslBaseURL + NamedConstants.Packages + "/" + documentId;
var serializer = new JavaScriptSerializer();
string jsonStr = serializer.Serialize(new { status = "SENT" });
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", NamedConstants.ESL_API_KEY);
client.DefaultRequestHeaders.Add("Accept", "application/json");
HttpResponseMessage response = await client.PutAsJsonAsync(new Uri(url), jsonStr);
LoggingTools.WriteToLog("PUT " + jsonStr + " to " + url, LoggingCategories.WebServiceTrace);
return response;
}
}
catch (Exception ex)
{
throw ex;
}
This is my REQUEST from log
PUT https://sandbox.e-signlive.com/api/packages/413d272f-80c9-40f7-a8a3-a6332bbbbdf2 HTTP/1.1
Authorization: Basic api_key
Accept: application/json
Content-Type: application/json; charset=utf-8
Host: sandbox.e-signlive.com
Content-Length: 23
Expect: 100-continue
Connection: Keep-Alive
"{\"status\":\"SENT\"}"
This is the RESPONSE from the logs.
HTTP/1.1 400 Bad Request
Server: nginx
Date: Mon, 30 May 2016 17:31:51 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: keep-alive
X-Powered-By: Undertow 1
190
{"messageKey":"error.validation.invalidJson","entity":null,"technical":"Can not instantiate value of type [simple type, class com.silanis.esl.api.model.Package] from String value ('{\"status\":\"SENT\"}'); no single-String constructor/factory method\n at [Source: \"{\\\"status\\\":\\\"SENT\\\"}\"; line: 1, column: 1]","packageId":null,"code":400,"message":"Invalid JSON.","name":"Validation Error"}
0
Reply to: Updating "SENT" to existing DRAFT Package
Monday, May 30, 2016 at 09:28amPUT /api/packages/aKs59kI-wJoKj0VAt9HttSaCChk= HTTP/1.1 Host: sandbox.esignlive.com Authorization: Basic api_key Accept: application/json Content-Type: application/json Cache-Control: no-cache {"status":"SENT"}And a working sample code:var serializer = new JavaScriptSerializer(); string jsonString = serializer.Serialize(new { status = "SENT" }); StringContent jsonContent = new StringContent(jsonString, Encoding.UTF8, "application/json"); HttpClient myClient = new HttpClient(); myClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", apiKey); myClient.DefaultRequestHeaders.Add("Accept", "application/json"); var response = myClient.PutAsync(new Uri(apiUrl + "/packages/aKs59kI-wJoKj0VAt9HttSaCChk="), jsonContent).Result; Debug.WriteLine(response.Content.ReadAsStringAsync().Result);Hope this helps :)