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) Retrieve User Account DataSee more DocuSign ExamplesTo make an API call to the DocuSign platform, your application needs both an access token (which you obtained in the previous step), and base URI that is unique to the user on whose behalf your application is making the API call. To get the base URI, call the/oauth/userinfoendpoint, supplying your application’s access token as a header. For more information, see https://developers.docusign.com/esign-rest-api/guides/authentication/oauth2-jsonwebtoken
#include <C_CkHttpW.h> #include <C_CkJsonObjectW.h> #include <C_CkStringBuilderW.h> void ChilkatSample(void) { HCkHttpW http; BOOL success; HCkJsonObjectW jsonToken; HCkStringBuilderW sbResponseBody; HCkJsonObjectW jResp; int respStatusCode; const wchar_t *account_id; BOOL is_default; const wchar_t *account_name; const wchar_t *base_uri; const wchar_t *sub; const wchar_t *name; const wchar_t *given_name; const wchar_t *family_name; const wchar_t *created; const wchar_t *email; 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 --header "Authorization: Bearer eyJ0eXAi.....UE8Kl_V8KroQ" https://account-d.docusign.com/oauth/userinfo // 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. jsonToken = CkJsonObjectW_Create(); // Load a previously obtained OAuth2 access token. success = CkJsonObjectW_LoadFile(jsonToken,L"qa_data/tokens/docusign.json"); if (success == FALSE) { wprintf(L"%s\n",CkJsonObjectW_lastErrorText(jsonToken)); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(jsonToken); return; } CkHttpW_putAuthToken(http,CkJsonObjectW_stringOf(jsonToken,L"access_token")); sbResponseBody = CkStringBuilderW_Create(); success = CkHttpW_QuickGetSb(http,L"https://account-d.docusign.com/oauth/userinfo",sbResponseBody); if (success == FALSE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(jsonToken); 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); CkJsonObjectW_Dispose(jsonToken); CkStringBuilderW_Dispose(sbResponseBody); CkJsonObjectW_Dispose(jResp); return; } // Sample JSON response: // (Sample code for parsing the JSON response is shown below) // { // "sub": "564f7988-xxxx-xxxx-xxxx-781ee556ab7a", // "name": "Example J Smith", // "given_name": "Example", // "family_name": "Smith", // "created": "2018-04-13T22:03:03.45", // "email": "Example.Smith@exampledomain.com", // "accounts": [ // { // "account_id": "18b4799a-xxxx-xxxx-xxxx-b5b4b8a97604", // "is_default": true, // "account_name": "ExampleAccount", // "base_uri": "https://demo.docusign.net" // } // ] // } // 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. sub = CkJsonObjectW_stringOf(jResp,L"sub"); name = CkJsonObjectW_stringOf(jResp,L"name"); given_name = CkJsonObjectW_stringOf(jResp,L"given_name"); family_name = CkJsonObjectW_stringOf(jResp,L"family_name"); created = CkJsonObjectW_stringOf(jResp,L"created"); email = CkJsonObjectW_stringOf(jResp,L"email"); i = 0; count_i = CkJsonObjectW_SizeOfArray(jResp,L"accounts"); while (i < count_i) { CkJsonObjectW_putI(jResp,i); account_id = CkJsonObjectW_stringOf(jResp,L"accounts[i].account_id"); is_default = CkJsonObjectW_BoolOf(jResp,L"accounts[i].is_default"); account_name = CkJsonObjectW_stringOf(jResp,L"accounts[i].account_name"); base_uri = CkJsonObjectW_stringOf(jResp,L"accounts[i].base_uri"); i = i + 1; } CkHttpW_Dispose(http); CkJsonObjectW_Dispose(jsonToken); CkStringBuilderW_Dispose(sbResponseBody); CkJsonObjectW_Dispose(jResp); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.