C
C
Yousign: Making your first API call
See more Yousign Examples
Demonstrates making the simplest of calls to test your API key. This example tests using the sandbox URLs.Chilkat C Downloads
#include <C_CkHttp.h>
#include <C_CkStringBuilder.h>
#include <C_CkJsonObject.h>
void ChilkatSample(void)
{
BOOL success;
HCkHttp http;
HCkStringBuilder sbResponseBody;
HCkJsonObject jResp;
int respStatusCode;
const char *name;
const char *strVal;
const char *id;
const char *firstname;
const char *lastname;
const char *email;
const char *title;
const char *phone;
const char *status;
const char *organization;
const char *permission;
const char *groupId;
const char *groupName;
const char *createdAt;
const char *updatedAt;
BOOL deleted;
const char *deletedAt;
const char *inweboUserRequest;
const char *samlNameId;
const char *defaultSignImage;
BOOL notificationsProcedure;
BOOL fastSign;
const char *fullName;
int i;
int count_i;
success = FALSE;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttp_Create();
// Implements the following CURL command:
// curl --location --request GET 'https://staging-api.yousign.com/users' \
// --header 'Authorization: Bearer YOUR_API_KEY' \
// --header 'Content-Type: application/json'
// 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 YOUR_API_KEY" header.
CkHttp_putAuthToken(http,"YOUR_API_KEY");
CkHttp_SetRequestHeader(http,"Content-Type","application/json");
sbResponseBody = CkStringBuilder_Create();
success = CkHttp_QuickGetSb(http,"https://staging-api.yousign.com/users",sbResponseBody);
if (success == FALSE) {
printf("%s\n",CkHttp_lastErrorText(http));
CkHttp_Dispose(http);
CkStringBuilder_Dispose(sbResponseBody);
return;
}
jResp = CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,sbResponseBody);
CkJsonObject_putEmitCompact(jResp,FALSE);
printf("Response Body:\n");
printf("%s\n",CkJsonObject_emit(jResp));
respStatusCode = CkHttp_getLastStatus(http);
printf("Response Status Code = %d\n",respStatusCode);
if (respStatusCode >= 400) {
printf("Response Header:\n");
printf("%s\n",CkHttp_lastHeader(http));
printf("Failed.\n");
CkHttp_Dispose(http);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);
return;
}
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "id": "/users/XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
// "firstname": "John",
// "lastname": "Doe",
// "email": "john.doe@yousign.fr",
// "title": "Developer",
// "phone": "+33612345678",
// "status": "activated",
// "organization": "/organizations/XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
// "workspaces": [
// {
// "id": "/workspaces/XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
// "name": "Acme"
// }
// ],
// "permission": "ROLE_ADMIN",
// "group": {
// "id": "/user_groups/XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
// "name": "Administrateur",
// "permissions": [
// "procedure_write",
// "procedure_template_write",
// "procedure_create_from_template",
// "contact",
// "sign",
// "organization",
// "user",
// "api_key",
// "procedure_custom_field",
// "signature_ui",
// "certificate",
// "archive"
// ]
// },
// "createdAt": "2018-12-01T09:42:25+01:00",
// "updatedAt": "2018-12-01T09:42:25+01:00",
// "deleted": false,
// "deletedAt": null,
// "config": [
// ],
// "inweboUserRequest": null,
// "samlNameId": null,
// "defaultSignImage": null,
// "notifications": {
// "procedure": true
// },
// "fastSign": false,
// "fullName": "John Doe"
// }
// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
// Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
// See this example explaining how this memory should be used: const char * functions.
id = CkJsonObject_stringOf(jResp,"id");
firstname = CkJsonObject_stringOf(jResp,"firstname");
lastname = CkJsonObject_stringOf(jResp,"lastname");
email = CkJsonObject_stringOf(jResp,"email");
title = CkJsonObject_stringOf(jResp,"title");
phone = CkJsonObject_stringOf(jResp,"phone");
status = CkJsonObject_stringOf(jResp,"status");
organization = CkJsonObject_stringOf(jResp,"organization");
permission = CkJsonObject_stringOf(jResp,"permission");
groupId = CkJsonObject_stringOf(jResp,"group.id");
groupName = CkJsonObject_stringOf(jResp,"group.name");
createdAt = CkJsonObject_stringOf(jResp,"createdAt");
updatedAt = CkJsonObject_stringOf(jResp,"updatedAt");
deleted = CkJsonObject_BoolOf(jResp,"deleted");
deletedAt = CkJsonObject_stringOf(jResp,"deletedAt");
inweboUserRequest = CkJsonObject_stringOf(jResp,"inweboUserRequest");
samlNameId = CkJsonObject_stringOf(jResp,"samlNameId");
defaultSignImage = CkJsonObject_stringOf(jResp,"defaultSignImage");
notificationsProcedure = CkJsonObject_BoolOf(jResp,"notifications.procedure");
fastSign = CkJsonObject_BoolOf(jResp,"fastSign");
fullName = CkJsonObject_stringOf(jResp,"fullName");
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"workspaces");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
id = CkJsonObject_stringOf(jResp,"workspaces[i].id");
name = CkJsonObject_stringOf(jResp,"workspaces[i].name");
i = i + 1;
}
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"group.permissions");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
strVal = CkJsonObject_stringOf(jResp,"group.permissions[i]");
i = i + 1;
}
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"config");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
i = i + 1;
}
CkHttp_Dispose(http);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);
}