Sample code for 30+ languages & platforms
Objective-C

Docusign: Return Brand Data Associated with a User

See more DocuSign Examples

Demonstrates a call using an OAuth2 access token in combination with the account ID for which we have authorization.

Chilkat Objective-C Downloads

Objective-C
#import <CkoHttp.h>
#import <CkoJsonObject.h>
#import <CkoStringBuilder.h>
#import <NSString.h>

BOOL success = NO;

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

CkoHttp *http = [[CkoHttp alloc] init];

// Implements the following CURL command:

// curl --request GET https://account-d.docusign.com/restapi/v2/accounts/18b4799a-xxxx-xxxx-xxxx-b5b4b8a97604/brands --header "Authorization: Bearer eyJ0eXAi.....UE8Kl_V8KroQ"

// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code

// Adds the "Authorization: Bearer eyJ0eXAi.....UE8Kl_V8KroQ" header.
CkoJsonObject *jsonToken = [[CkoJsonObject alloc] init];
// Load a previously obtained OAuth2 access token.
success = [jsonToken LoadFile: @"qa_data/tokens/docusign.json"];
if (success == NO) {
    NSLog(@"%@",jsonToken.LastErrorText);
    return;
}

http.AuthToken = [jsonToken StringOf: @"access_token"];

// Use an account ID obtained from DocuSign Get User Account Data
CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init];
success = [http QuickGetSb: @"https://account-d.docusign.com/restapi/v2/accounts/18b4799a-xxxx-xxxx-xxxx-b5b4b8a97604/brands" sbContent: sbResponseBody];
if (success == NO) {
    NSLog(@"%@",http.LastErrorText);
    return;
}

CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json LoadSb: sbResponseBody];
json.EmitCompact = NO;

NSLog(@"%@",@"Response Body:");
NSLog(@"%@",[json Emit]);

int respStatusCode = [http.LastStatus intValue];
NSLog(@"%@%d",@"Response Status Code = ",respStatusCode);
if (respStatusCode >= 400) {
    NSLog(@"%@",@"Response Header:");
    NSLog(@"%@",http.LastHeader);
    NSLog(@"%@",@"Failed.");
    return;
}

// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)

// {
//   "recipientBrandIdDefault": "sample string 1",
//   "senderBrandIdDefault": "sample string 2",
//   "brands": [
//     {
//       "brandCompany": "sample string 1",
//       "brandId": "sample string 2",
//       "brandName": "sample string 3",
//       "colors": [
//         {}
//       ],
//       "errorDetails": {
//         "errorCode": "sample string 1",
//         "message": "sample string 2"
//       },
//       "isOverridingCompanyName": "sample string 4",
//       "isSendingDefault": "sample string 5",
//       "isSigningDefault": "sample string 6",
//       "landingPages": [
//         {}
//       ],
//       "links": [
//         {
//           "linkType": "sample string 1",
//           "urlOrMailTo": "sample string 2",
//           "linkText": "sample string 3",
//           "showLink": "sample string 4"
//         }
//       ],
//       "emailContent": [
//         {
//           "emailContentType": "sample string 1",
//           "content": "sample string 2",
//           "emailToLink": "sample string 3",
//           "linkText": "sample string 4"
//         }
//       ],
//       "logos": {
//         "primary": "sample string 1",
//         "secondary": "sample string 2",
//         "email": "sample string 3"
//       },
//       "resources": {
//         "email": "sample string 1",
//         "sending": "sample string 2",
//         "signing": "sample string 3",
//         "signingCaptive": "sample string 4"
//       }
//     }
//   ]
// }

// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON

NSString *brandCompany = 0;
NSString *brandId = 0;
NSString *brandName = 0;
NSString *errorDetailsErrorCode = 0;
NSString *errorDetailsMessage = 0;
NSString *isOverridingCompanyName = 0;
NSString *isSendingDefault = 0;
NSString *isSigningDefault = 0;
NSString *logosPrimary = 0;
NSString *logosSecondary = 0;
NSString *logosEmail = 0;
NSString *resourcesEmail = 0;
NSString *resourcesSending = 0;
NSString *resourcesSigning = 0;
NSString *resourcesSigningCaptive = 0;
int j;
int count_j;
NSString *linkType = 0;
NSString *urlOrMailTo = 0;
NSString *linkText = 0;
NSString *showLink = 0;
NSString *emailContentType = 0;
NSString *content = 0;
NSString *emailToLink = 0;

NSString *recipientBrandIdDefault = [json StringOf: @"recipientBrandIdDefault"];
NSString *senderBrandIdDefault = [json StringOf: @"senderBrandIdDefault"];
int i = 0;
int count_i = [[json SizeOfArray: @"brands"] intValue];
while (i < count_i) {
    json.I = [NSNumber numberWithInt: i];
    brandCompany = [json StringOf: @"brands[i].brandCompany"];
    brandId = [json StringOf: @"brands[i].brandId"];
    brandName = [json StringOf: @"brands[i].brandName"];
    errorDetailsErrorCode = [json StringOf: @"brands[i].errorDetails.errorCode"];
    errorDetailsMessage = [json StringOf: @"brands[i].errorDetails.message"];
    isOverridingCompanyName = [json StringOf: @"brands[i].isOverridingCompanyName"];
    isSendingDefault = [json StringOf: @"brands[i].isSendingDefault"];
    isSigningDefault = [json StringOf: @"brands[i].isSigningDefault"];
    logosPrimary = [json StringOf: @"brands[i].logos.primary"];
    logosSecondary = [json StringOf: @"brands[i].logos.secondary"];
    logosEmail = [json StringOf: @"brands[i].logos.email"];
    resourcesEmail = [json StringOf: @"brands[i].resources.email"];
    resourcesSending = [json StringOf: @"brands[i].resources.sending"];
    resourcesSigning = [json StringOf: @"brands[i].resources.signing"];
    resourcesSigningCaptive = [json StringOf: @"brands[i].resources.signingCaptive"];
    j = 0;
    count_j = [[json SizeOfArray: @"brands[i].colors"] intValue];
    while (j < count_j) {
        json.J = [NSNumber numberWithInt: j];
        j = j + 1;
    }

    j = 0;
    count_j = [[json SizeOfArray: @"brands[i].landingPages"] intValue];
    while (j < count_j) {
        json.J = [NSNumber numberWithInt: j];
        j = j + 1;
    }

    j = 0;
    count_j = [[json SizeOfArray: @"brands[i].links"] intValue];
    while (j < count_j) {
        json.J = [NSNumber numberWithInt: j];
        linkType = [json StringOf: @"brands[i].links[j].linkType"];
        urlOrMailTo = [json StringOf: @"brands[i].links[j].urlOrMailTo"];
        linkText = [json StringOf: @"brands[i].links[j].linkText"];
        showLink = [json StringOf: @"brands[i].links[j].showLink"];
        j = j + 1;
    }

    j = 0;
    count_j = [[json SizeOfArray: @"brands[i].emailContent"] intValue];
    while (j < count_j) {
        json.J = [NSNumber numberWithInt: j];
        emailContentType = [json StringOf: @"brands[i].emailContent[j].emailContentType"];
        content = [json StringOf: @"brands[i].emailContent[j].content"];
        emailToLink = [json StringOf: @"brands[i].emailContent[j].emailToLink"];
        linkText = [json StringOf: @"brands[i].emailContent[j].linkText"];
        j = j + 1;
    }

    i = i + 1;
}