Sample code for 30+ languages & platforms
Unicode C++

Aruba Fatturazione Elettronica CreateTransmissionRequestList

See more Aruba Fatturazione Examples

Creation of "Financial Communications" transmission request in zip format.

Chilkat Unicode C++ Downloads

Unicode C++
#include <CkHttpW.h>
#include <CkZipW.h>
#include <CkBinDataW.h>
#include <CkJsonObjectW.h>
#include <CkHttpResponseW.h>
#include <CkStringBuilderW.h>

void ChilkatSample(void)
    {
    bool success = false;

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkHttpW http;

    // 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.

    CkZipW zip;

    // Initialize the zip object.  Because we will never actually write a zip file to the filesystem,
    // the filepath passed to NewZip does not matter.
    zip.NewZip(L"x.zip");

    // Append references to XML files to the zip object in memory.
    bool recurse = false;
    success = zip.AppendFiles(L"qa_data/aruba/*.xml",recurse);
    if (success == false) {
        wprintf(L"%s\n",zip.lastErrorText());
        return;
    }

    // Write the zip archive into the bdZip object.
    CkBinDataW bdZip;
    success = zip.WriteBd(bdZip);
    if (success == false) {
        wprintf(L"%s\n",zip.lastErrorText());
        return;
    }

    // Get the zip in base64 format.
    const wchar_t *zipAsBase64 = bdZip.getEncoded(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=="
    // }

    CkJsonObjectW json;
    json.UpdateString(L"userName",L"ARUBA0000");
    json.UpdateString(L"password",L"ArubaPwd");
    json.UpdateString(L"userID",L"ARUBA0000");
    json.UpdateString(L"comunicationType",L"LI");
    json.UpdateString(L"dataFile",zipAsBase64);

    http.SetRequestHeader(L"Content-Type",L"application/json;charset=UTF-8");
    http.SetRequestHeader(L"Accept",L"application/json");

    CkHttpResponseW resp;
    success = http.HttpJson(L"POST",L"https://ws.fatturazioneelettronica.aruba.it/services/ClientRequest/CreateTransmissionRequestList",json,L"application/json",resp);
    if (success == false) {
        wprintf(L"%s\n",http.lastErrorText());
        return;
    }

    CkStringBuilderW sbResponseBody;
    resp.GetBodySb(sbResponseBody);
    CkJsonObjectW jResp;
    jResp.LoadSb(sbResponseBody);
    jResp.put_EmitCompact(false);

    wprintf(L"Response Body:\n");
    wprintf(L"%s\n",jResp.emit());

    int respStatusCode = resp.get_StatusCode();
    wprintf(L"Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",resp.header());
        wprintf(L"Failed.\n");
        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.

    const wchar_t *fileName = 0;

    const wchar_t *errorCode = jResp.stringOf(L"errorCode");
    const wchar_t *errorDescription = jResp.stringOf(L"errorDescription");
    const wchar_t *requestID = jResp.stringOf(L"requestID");
    int i = 0;
    int count_i = jResp.SizeOfArray(L"requestIDList");
    while (i < count_i) {
        jResp.put_I(i);
        fileName = jResp.stringOf(L"requestIDList[i].fileName");
        requestID = jResp.stringOf(L"requestIDList[i].requestID");
        i = i + 1;
    }
    }