DocuSign API SetBody Objective C

时间:2014-03-20 11:41:18

标签: iphone objective-c docusignapi

我正在尝试在objective C项目中使用DocuSign API服务。这个link显示了我要添加到正文中的数据,但我仍然从objective C开始开始,我不知道它是怎么做的。

我尝试了以下但我收到了无数据

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

其中envelopesPending是一个数组,我用DDBB中的envelopepesId填充。

NSMutableArray *envelopesPending = [NSMutableArray array];

这是我用来调用服务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];

编辑:

错误是PUT方法,因此请求是:

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

有了这个改变,我有一个错误,上面写着:

errorCode =“INVALID_REQUEST_PARAMETER”; message =“请求包含至少一个无效参数。查询参数'from_date'必须设置为有效的DateTime,或者必须指定'envelope_ids'或'transaction_ids'。”;

解决此错误,将envelope_ids参数添加到请求中:

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

我将字典传递给包含以下代码的字符串:

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];

2 个答案:

答案 0 :(得分:1)

看起来你已经想到了这一点,但基本上这里是你需要做的REST API调用的细节:


获取多个信封的信封状态

这将返回所请求信封的信封状态。

URL

/accounts/{accountId}/envelopes/status

格式

XML, JSON

HTTP方法

PUT

必需的网址参数

?envelope_ids=request_body

请求正文

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

所以示例请求看起来像是:

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-...................."
  ],
}

答案 1 :(得分:1)

错误是PUT方法,因此请求是:

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

有了这个改变,我有一个错误,上面写着:

errorCode =“INVALID_REQUEST_PARAMETER”; message =“请求包含至少一个无效参数。查询参数'from_date'必须设置为有效的DateTime,或者必须指定'envelope_ids'或'transaction_ids'。”;

解决此错误,将envelope_ids参数添加到请求中:

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

我将字典传递给包含以下代码的字符串:

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];