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 Procedure Creation Basic Mode Upload FileDemonstrates the 1st step of Yousign procedure creation, which is to upload a PDF file. For more information, see https://dev.yousign.com/?version=latest#0889a9c5-aa1e-4de0-9b35-4d6621b4eb20
#include <C_CkHttpW.h> #include <C_CkBinDataW.h> #include <C_CkJsonObjectW.h> #include <C_CkHttpResponseW.h> #include <C_CkStringBuilderW.h> void ChilkatSample(void) { HCkHttpW http; BOOL success; HCkBinDataW pdfData; HCkJsonObjectW json; HCkHttpResponseW resp; HCkStringBuilderW sbResponseBody; HCkJsonObjectW jResp; int respStatusCode; const wchar_t *id; const wchar_t *name; const wchar_t *v_type; const wchar_t *contentType; const wchar_t *description; const wchar_t *createdAt; const wchar_t *updatedAt; const wchar_t *sha256; const wchar_t *workspace; const wchar_t *creator; BOOL v_protected; int position; const wchar_t *parent; 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 POST 'https://staging-api.yousign.com/files' \ // --header 'Authorization: Bearer YOUR_API_KEY' \ // --header 'Content-Type: application/json' \ // --data-raw '{ // "name": "The best name for my file.pdf", // "content": "JVBERi0..." }' // Load a PDF file to be uploaded. pdfData = CkBinDataW_Create(); success = CkBinDataW_LoadFile(pdfData,L"qa_data/pdf/helloWorld.pdf"); if (success == FALSE) { wprintf(L"Failed to load PDF local file.\n"); CkHttpW_Dispose(http); CkBinDataW_Dispose(pdfData); return; } // Use the following online tool to generate HTTP code from a CURL command // Convert a cURL Command to HTTP Source Code // Use this online tool to generate code from sample JSON: // Generate Code to Create JSON // The following JSON is sent in the request body. // { // "name": "The best name for my file.pdf", // "content": "JVBERi0..." // } json = CkJsonObjectW_Create(); CkJsonObjectW_UpdateString(json,L"name",L"helloWorld.pdf"); CkJsonObjectW_UpdateString(json,L"content",CkBinDataW_getEncoded(pdfData,L"base64")); // Adds the "Authorization: Bearer YOUR_API_KEY" header. CkHttpW_putAuthToken(http,L"YOUR_API_KEY"); CkHttpW_SetRequestHeader(http,L"Content-Type",L"application/json"); resp = CkHttpW_PostJson3(http,L"https://staging-api.yousign.com/files",L"application/json",json); if (CkHttpW_getLastMethodSuccess(http) == FALSE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkHttpW_Dispose(http); CkBinDataW_Dispose(pdfData); CkJsonObjectW_Dispose(json); return; } sbResponseBody = CkStringBuilderW_Create(); CkHttpResponseW_GetBodySb(resp,sbResponseBody); jResp = CkJsonObjectW_Create(); CkJsonObjectW_LoadSb(jResp,sbResponseBody); CkJsonObjectW_putEmitCompact(jResp,FALSE); wprintf(L"Response Body:\n"); wprintf(L"%s\n",CkJsonObjectW_emit(jResp)); respStatusCode = CkHttpResponseW_getStatusCode(resp); wprintf(L"Response Status Code = %d\n",respStatusCode); if (respStatusCode >= 400) { wprintf(L"Response Header:\n"); wprintf(L"%s\n",CkHttpResponseW_header(resp)); wprintf(L"Failed.\n"); CkHttpResponseW_Dispose(resp); CkHttpW_Dispose(http); CkBinDataW_Dispose(pdfData); CkJsonObjectW_Dispose(json); CkStringBuilderW_Dispose(sbResponseBody); CkJsonObjectW_Dispose(jResp); return; } CkHttpResponseW_Dispose(resp); // Sample JSON response: // (Sample code for parsing the JSON response is shown below) // { // "id": "/files/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", // "name": "The best name for my file.pdf", // "type": "signable", // "contentType": "application/pdf", // "description": null, // "createdAt": "2018-12-01T11:36:20+01:00", // "updatedAt": "2018-12-01T11:36:20+01:00", // "sha256": "bb57ae2b2ca6ad0133a699350d1a6f6c8cdfde3cf872cf526585d306e4675cc2", // "metadata": [ // ], // "workspace": "/workspaces/XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", // "creator": null, // "protected": false, // "position": 0, // "parent": null // } // 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"); name = CkJsonObjectW_stringOf(jResp,L"name"); v_type = CkJsonObjectW_stringOf(jResp,L"type"); contentType = CkJsonObjectW_stringOf(jResp,L"contentType"); description = CkJsonObjectW_stringOf(jResp,L"description"); createdAt = CkJsonObjectW_stringOf(jResp,L"createdAt"); updatedAt = CkJsonObjectW_stringOf(jResp,L"updatedAt"); sha256 = CkJsonObjectW_stringOf(jResp,L"sha256"); workspace = CkJsonObjectW_stringOf(jResp,L"workspace"); creator = CkJsonObjectW_stringOf(jResp,L"creator"); v_protected = CkJsonObjectW_BoolOf(jResp,L"protected"); position = CkJsonObjectW_IntOf(jResp,L"position"); parent = CkJsonObjectW_stringOf(jResp,L"parent"); i = 0; count_i = CkJsonObjectW_SizeOfArray(jResp,L"metadata"); while (i < count_i) { CkJsonObjectW_putI(jResp,i); i = i + 1; } CkHttpW_Dispose(http); CkBinDataW_Dispose(pdfData); CkJsonObjectW_Dispose(json); CkStringBuilderW_Dispose(sbResponseBody); CkJsonObjectW_Dispose(jResp); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.