Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Unicode C) Yousign: Making your first API callDemonstrates making the simplest of calls to test your API key. This example tests using the sandbox URLs. For more information, see https://dev.yousign.com/?version=latest#c803dbec-2afb-4b2d-b70b-b42e5c8cbc9a
#include <C_CkHttpW.h> #include <C_CkStringBuilderW.h> #include <C_CkJsonObjectW.h> void ChilkatSample(void) { HCkHttpW http; BOOL success; HCkStringBuilderW sbResponseBody; HCkJsonObjectW jResp; int respStatusCode; const wchar_t *name; const wchar_t *strVal; const wchar_t *id; const wchar_t *firstname; const wchar_t *lastname; const wchar_t *email; const wchar_t *title; const wchar_t *phone; const wchar_t *status; const wchar_t *organization; const wchar_t *permission; const wchar_t *groupId; const wchar_t *groupName; const wchar_t *createdAt; const wchar_t *updatedAt; BOOL deleted; const wchar_t *deletedAt; const wchar_t *inweboUserRequest; const wchar_t *samlNameId; const wchar_t *defaultSignImage; BOOL notificationsProcedure; BOOL fastSign; const wchar_t *fullName; int i; int count_i; // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. http = CkHttpW_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. CkHttpW_putAuthToken(http,L"YOUR_API_KEY"); CkHttpW_SetRequestHeader(http,L"Content-Type",L"application/json"); sbResponseBody = CkStringBuilderW_Create(); success = CkHttpW_QuickGetSb(http,L"https://staging-api.yousign.com/users",sbResponseBody); if (success == FALSE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkHttpW_Dispose(http); CkStringBuilderW_Dispose(sbResponseBody); return; } jResp = CkJsonObjectW_Create(); CkJsonObjectW_LoadSb(jResp,sbResponseBody); CkJsonObjectW_putEmitCompact(jResp,FALSE); wprintf(L"Response Body:\n"); wprintf(L"%s\n",CkJsonObjectW_emit(jResp)); respStatusCode = CkHttpW_getLastStatus(http); wprintf(L"Response Status Code = %d\n",respStatusCode); if (respStatusCode >= 400) { wprintf(L"Response Header:\n"); wprintf(L"%s\n",CkHttpW_lastHeader(http)); wprintf(L"Failed.\n"); CkHttpW_Dispose(http); CkStringBuilderW_Dispose(sbResponseBody); CkJsonObjectW_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 = CkJsonObjectW_stringOf(jResp,L"id"); firstname = CkJsonObjectW_stringOf(jResp,L"firstname"); lastname = CkJsonObjectW_stringOf(jResp,L"lastname"); email = CkJsonObjectW_stringOf(jResp,L"email"); title = CkJsonObjectW_stringOf(jResp,L"title"); phone = CkJsonObjectW_stringOf(jResp,L"phone"); status = CkJsonObjectW_stringOf(jResp,L"status"); organization = CkJsonObjectW_stringOf(jResp,L"organization"); permission = CkJsonObjectW_stringOf(jResp,L"permission"); groupId = CkJsonObjectW_stringOf(jResp,L"group.id"); groupName = CkJsonObjectW_stringOf(jResp,L"group.name"); createdAt = CkJsonObjectW_stringOf(jResp,L"createdAt"); updatedAt = CkJsonObjectW_stringOf(jResp,L"updatedAt"); deleted = CkJsonObjectW_BoolOf(jResp,L"deleted"); deletedAt = CkJsonObjectW_stringOf(jResp,L"deletedAt"); inweboUserRequest = CkJsonObjectW_stringOf(jResp,L"inweboUserRequest"); samlNameId = CkJsonObjectW_stringOf(jResp,L"samlNameId"); defaultSignImage = CkJsonObjectW_stringOf(jResp,L"defaultSignImage"); notificationsProcedure = CkJsonObjectW_BoolOf(jResp,L"notifications.procedure"); fastSign = CkJsonObjectW_BoolOf(jResp,L"fastSign"); fullName = CkJsonObjectW_stringOf(jResp,L"fullName"); i = 0; count_i = CkJsonObjectW_SizeOfArray(jResp,L"workspaces"); while (i < count_i) { CkJsonObjectW_putI(jResp,i); id = CkJsonObjectW_stringOf(jResp,L"workspaces[i].id"); name = CkJsonObjectW_stringOf(jResp,L"workspaces[i].name"); i = i + 1; } i = 0; count_i = CkJsonObjectW_SizeOfArray(jResp,L"group.permissions"); while (i < count_i) { CkJsonObjectW_putI(jResp,i); strVal = CkJsonObjectW_stringOf(jResp,L"group.permissions[i]"); i = i + 1; } i = 0; count_i = CkJsonObjectW_SizeOfArray(jResp,L"config"); while (i < count_i) { CkJsonObjectW_putI(jResp,i); i = i + 1; } CkHttpW_Dispose(http); CkStringBuilderW_Dispose(sbResponseBody); CkJsonObjectW_Dispose(jResp); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.