1

I'm trying to use a service of DocuSign API in an objective C project. This link shows what data I've to add to body but I'm still starting with objective C development and I can't know how do it.

I tried the following but I received nil data

NSDictionary *EnvelopesStatusRequestData = @{@"envelopeIds": envelopesPending};

where envelopesPending is an array that I fill with envelopesId that I have in a DDBB.

NSMutableArray *envelopesPending = [NSMutableArray array];

This is the code that I use to call service API:

NSDictionary *authenticationHeader = @{ @"Username": email, @"Password" : password, @"IntegratorKey" : integratorKey };
NSDictionary *EnvelopesStatusRequestData = @{@"envelopeIds": envelopesPending};

NSData* dataStatus = [[self jsonStringFromObject:EnvelopesStatusRequestData] dataUsingEncoding:NSUTF8StringEncoding];
NSString *envelopesURL = [NSMutableString stringWithFormat:@"%@/envelopes/status",baseUrl];

NSMutableURLRequest *envelopeRequest = [self initializeRequest:envelopesURL setMethod:@"GET" setBody:dataStatus];
[envelopeRequest setValue:[self jsonStringFromObject:authenticationHeader] forHTTPHeaderField:@"X-DocuSign-Authentication"];
[envelopeRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];

NSURLResponse *envelopesResponse = nil;
NSError *envelopesError = nil;
NSData *envelopeData = [NSURLConnection sendSynchronousRequest:envelopeRequest returningResponse:&envelopesResponse error:&envelopesError];

EDIT:

The error was that is a PUT method, so the request is:

NSMutableURLRequest *envelopeRequest = [self initializeRequest:envelopesURL setMethod:@"PUT" setBody:dataStatus];

With this change I have an error that says:

errorCode = "INVALID_REQUEST_PARAMETER"; message = "The request contained at least one invalid parameter. Query parameter 'from_date' must be set to a valid DateTime, or 'envelope_ids' or 'transaction_ids' must be specified.";

This error is solved adding the envelope_ids parameter to request:

PUT https://{server}/restapi/{apiVersion}/accounts/{accountId}/envelopes/status?envelope_ids=request_body

I pass the dictionary to a string with this code:

NSData *dataEnv = [NSJSONSerialization dataWithJSONObject:envelopesPending options:NSJSONReadingMutableLeaves error:&error];

NSString *querystring = [[NSString alloc] initWithData:dataEnv encoding:NSUTF8StringEncoding];

querystring = [querystring stringByReplacingOccurrencesOfString:@"[" withString:@""];
querystring = [querystring stringByReplacingOccurrencesOfString:@"]" withString:@""];
querystring = [querystring stringByReplacingOccurrencesOfString:@"\"" withString:@""];

NSString *envelopesURL = [NSMutableString stringWithFormat:@"%@/envelopes/status?envelope_ids=%@",baseUrl, querystring];
nsanchez
  • 132
  • 2
  • 12
  • So does that mean you've got this working now? If so you should answer your own question so that the community benefits from this... – Ergin Mar 20 '14 at 17:50

2 Answers2

1

It looks like you've figured this out, but basically here are the details of the REST API call you need to make:


Get Envelope Status for more than One Envelope

This returns envelope status for the requested envelopes.

URL:

/accounts/{accountId}/envelopes/status

Formats:

XML, JSON

HTTP Method:

PUT

Required URL Parameter:

?envelope_ids=request_body

Request Body:

{
  "envelopeIds":[
    "String content",
    "String content"
  ],
}

So a sample request would look like:

PUT https://{server}/restapi/{apiVersion}/accounts/{accountId}/envelopes/status?envelope_ids=request_body

X-DocuSign-Authentication: <DocuSignCredentials><Username>{name}</Username><Password>{password}</Password><IntegratorKey>{integrator_key}</IntegratorKey></DocuSignCredentials>
Accept: application/json
Content-Type: application/json
{
  "envelopeIds":[
    "12af49cd-....................",
    "b342c324-...................."
  ],
}
Ergin
  • 9,254
  • 1
  • 19
  • 28
1

The error was that is a PUT method, so the request is:

NSMutableURLRequest *envelopeRequest = [self initializeRequest:envelopesURL setMethod:@"PUT" setBody:dataStatus];

With this change I have an error that says:

errorCode = "INVALID_REQUEST_PARAMETER"; message = "The request contained at least one invalid parameter. Query parameter 'from_date' must be set to a valid DateTime, or 'envelope_ids' or 'transaction_ids' must be specified.";

This error is solved adding the envelope_ids parameter to request:

PUT https://{server}/restapi/{apiVersion}/accounts/{accountId}/envelopes/status?envelope_ids=request_body

I pass the dictionary to a string with this code:

NSData *dataEnv = [NSJSONSerialization dataWithJSONObject:envelopesPending options:NSJSONReadingMutableLeaves error:&error];

NSString *querystring = [[NSString alloc] initWithData:dataEnv encoding:NSUTF8StringEncoding];

querystring = [querystring stringByReplacingOccurrencesOfString:@"[" withString:@""];
querystring = [querystring stringByReplacingOccurrencesOfString:@"]" withString:@""];
querystring = [querystring stringByReplacingOccurrencesOfString:@"\"" withString:@""];

NSString *envelopesURL = [NSMutableString stringWithFormat:@"%@/envelopes/status?envelope_ids=%@",baseUrl, querystring];
nsanchez
  • 132
  • 2
  • 12