Unicode C
Unicode C
Aruba Fatturazione Elettronica CreateTransmissionRequestList
See more Aruba Fatturazione Examples
Creation of "Financial Communications" transmission request in zip format.Chilkat Unicode C Downloads
#include <C_CkHttpW.h>
#include <C_CkZipW.h>
#include <C_CkBinDataW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>
#include <C_CkStringBuilderW.h>
void ChilkatSample(void)
{
BOOL success;
HCkHttpW http;
HCkZipW zip;
BOOL recurse;
HCkBinDataW bdZip;
const wchar_t *zipAsBase64;
HCkJsonObjectW json;
HCkHttpResponseW resp;
HCkStringBuilderW sbResponseBody;
HCkJsonObjectW jResp;
int respStatusCode;
const wchar_t *fileName;
const wchar_t *errorCode;
const wchar_t *errorDescription;
const wchar_t *requestID;
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 -X POST https://ws.fatturazioneelettronica.aruba.it/services/ClientRequest/CreateTransmissionRequestList \
// -H "Accept: application/json" \
// -H "Content-Type: application/json;charset=UTF-8" \
// -d '{
// "userName" : "ARUBA0000",
// "password" : "ArubaPwd",
// "userID" : "ARUBA0000",
// "comunicationType" : "LI",
// "dataFile" : "dGVzdA=="
// }'
// The dataFile must contain a Zip file, containing xml files which conform to the Revenue Agency specifications.
// The archive file must be Base64 codified and contain a CADES-based electronic signature.
zip = CkZipW_Create();
// Initialize the zip object. Because we will never actually write a zip file to the filesystem,
// the filepath passed to NewZip does not matter.
CkZipW_NewZip(zip,L"x.zip");
// Append references to XML files to the zip object in memory.
recurse = FALSE;
success = CkZipW_AppendFiles(zip,L"qa_data/aruba/*.xml",recurse);
if (success == FALSE) {
wprintf(L"%s\n",CkZipW_lastErrorText(zip));
CkHttpW_Dispose(http);
CkZipW_Dispose(zip);
return;
}
// Write the zip archive into the bdZip object.
bdZip = CkBinDataW_Create();
success = CkZipW_WriteBd(zip,bdZip);
if (success == FALSE) {
wprintf(L"%s\n",CkZipW_lastErrorText(zip));
CkHttpW_Dispose(http);
CkZipW_Dispose(zip);
CkBinDataW_Dispose(bdZip);
return;
}
// Get the zip in base64 format.
zipAsBase64 = CkBinDataW_getEncoded(bdZip,L"base64");
// 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.
// {
// "userName": "ARUBA0000",
// "password": "ArubaPwd",
// "userID": "ARUBA0000",
// "comunicationType": "LI",
// "dataFile": "dGVzdA=="
// }
json = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(json,L"userName",L"ARUBA0000");
CkJsonObjectW_UpdateString(json,L"password",L"ArubaPwd");
CkJsonObjectW_UpdateString(json,L"userID",L"ARUBA0000");
CkJsonObjectW_UpdateString(json,L"comunicationType",L"LI");
CkJsonObjectW_UpdateString(json,L"dataFile",zipAsBase64);
CkHttpW_SetRequestHeader(http,L"Content-Type",L"application/json;charset=UTF-8");
CkHttpW_SetRequestHeader(http,L"Accept",L"application/json");
resp = CkHttpResponseW_Create();
success = CkHttpW_HttpJson(http,L"POST",L"https://ws.fatturazioneelettronica.aruba.it/services/ClientRequest/CreateTransmissionRequestList",json,L"application/json",resp);
if (success == FALSE) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
CkHttpW_Dispose(http);
CkZipW_Dispose(zip);
CkBinDataW_Dispose(bdZip);
CkJsonObjectW_Dispose(json);
CkHttpResponseW_Dispose(resp);
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");
CkHttpW_Dispose(http);
CkZipW_Dispose(zip);
CkBinDataW_Dispose(bdZip);
CkJsonObjectW_Dispose(json);
CkHttpResponseW_Dispose(resp);
CkStringBuilderW_Dispose(sbResponseBody);
CkJsonObjectW_Dispose(jResp);
return;
}
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "errorCode": "",
// "errorDescription": "",
// "requestID": "C70WC0SIPQ1JISWQ",
// "requestIDList": [
// {
// "fileName": "ITADFSREETDSD_LI_0001.xml",
// "requestID": "TXZWQPVYVFJHRUKN"
// },
// {
// "fileName": "ITADFSREETDSD_LI_0002.xml",
// "requestID": "PRSGFITDHFPTJ8OO"
// },
// {
// "fileName": "ITADFSREETDSD_LI_0003.xml",
// "requestID": "QNJ9E2MWGYGSM22Q"
// }
// ]
// }
// 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.
errorCode = CkJsonObjectW_stringOf(jResp,L"errorCode");
errorDescription = CkJsonObjectW_stringOf(jResp,L"errorDescription");
requestID = CkJsonObjectW_stringOf(jResp,L"requestID");
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jResp,L"requestIDList");
while (i < count_i) {
CkJsonObjectW_putI(jResp,i);
fileName = CkJsonObjectW_stringOf(jResp,L"requestIDList[i].fileName");
requestID = CkJsonObjectW_stringOf(jResp,L"requestIDList[i].requestID");
i = i + 1;
}
CkHttpW_Dispose(http);
CkZipW_Dispose(zip);
CkBinDataW_Dispose(bdZip);
CkJsonObjectW_Dispose(json);
CkHttpResponseW_Dispose(resp);
CkStringBuilderW_Dispose(sbResponseBody);
CkJsonObjectW_Dispose(jResp);
}