Unicode C
Unicode C
Yousign: Download Information about Previously Uploaded File
See more Yousign Examples
Demonstrates how to download the information (in JSON format) about a file previously uploaded.Chilkat Unicode C Downloads
#include <C_CkHttpW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkJsonObjectW.h>
void ChilkatSample(void)
{
BOOL success;
HCkHttpW http;
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;
success = FALSE;
// 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/files/{{id}}' \
// --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/files/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",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": "/files/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
// "name": "The best name for my file.pdf",
// "type": "signable",
// "contentType": "application/pdf",
// "description": null,
// "createdAt": "2018-12-07T08:10:21+01:00",
// "updatedAt": "2018-12-07T08:10:21+01:00",
// "sha256": "bb57ae2b2ca6ad0133a699350d1a6f6c8cdfde3cf872cf526585d306e4675cc2",
// "metadata": [
// ],
// "workspace": "/workspaces/XXXXXXXX-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);
CkStringBuilderW_Dispose(sbResponseBody);
CkJsonObjectW_Dispose(jResp);
}