I am making a call to the EchoSign REST API and I need to get the signing URL of the most recently signed document using an EchoSign query. I am using the following:
HttpRequest req = new HttpRequest();
req.setEndpoint('https://api.echosign.com:443/api/rest/v3/agreements?query=Agreement%20for%20APEX%20Test%20Account%20-%202015-04-02');
req.setMethod('GET');
req.setHeader('Access-Token', OAuthToken);
req.setHeader('Content-Type', 'application/json');
req.setHeader('Charset', 'UTF-8');
HttpResponse res = new HttpResponse();
Http http = new Http();
res = http.send(req);
System.debug(res.getBody());
The issue is due to the name format of the docs, if several are sent in a day from the same account they will all have the same name generated automatically for them...
So I am trying to get the body of the response and work out which agreement was sent at which time according to the EchoSign system and match this up to the agreements that I have to work out which ID matched which Agreement.
JSON Response:
{
"userAgreementList": [
{
"displayDate": "2015-04-02T09:32:23-07:00",
"displayUserInfo": {
"company": "TEST",
"fullNameOrEmail": "Tim 1234"
},
"esign": true,
"agreementId": "AGREEMENT ID",
"latestVersionId": "VERSION ID",
"name": "Agreement for APEX Test Account - 2015-04-02",
"status": "OUT_FOR_SIGNATURE"
},
{
"displayDate": "2015-04-02T03:32:57-07:00",
"displayUserInfo": {
"company": "TEST",
"fullNameOrEmail": "Tim 1234"
},
"esign": true,
"agreementId": "AGREEMENT ID",
"latestVersionId": "VERSION ID",
"name": "Agreement for APEX Test Account - 2015-04-02",
"status": "OUT_FOR_SIGNATURE"
},
{
"displayDate": "2015-03-31T09:15:11-07:00",
"displayUserInfo": {
"company": "TEST",
"fullNameOrEmail": "Tim 1234"
},
"esign": true,
"agreementId": "AGREEMENT ID",
"latestVersionId": "VERSION ID",
"name": "Agreement for APEX Test Account - 2015-04-02",
"status": "RECALLED"
}
]
}
I can't for the life of me work out how to convert the JSON into something that is readable... I have tried using JSON.deserialize and JSON.deserializeuntyped however I am getting errors constantly with both. I managed to get the JSON.deserializeuntyped working, however I could only get it to work when I converted this to to a Map of string and objects (Map<String, Object>
), but I can't work with this data how I want to be able to work with it :/