Sample code for 30+ languages & platforms
PureBasic

Aruba Fatturazione Elettronica CreateTransmissionRequestList

See more Aruba Fatturazione Examples

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

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkJsonObject.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkZip.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkHttpResponse.pb"
IncludeFile "CkBinData.pb"

Procedure ChilkatExample()

    success.i = 0

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

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    ; 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.i = CkZip::ckCreate()
    If zip.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

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

    ; Append references to XML files to the zip object in memory.
    recurse.i = 0
    success = CkZip::ckAppendFiles(zip,"qa_data/aruba/*.xml",recurse)
    If success = 0
        Debug CkZip::ckLastErrorText(zip)
        CkHttp::ckDispose(http)
        CkZip::ckDispose(zip)
        ProcedureReturn
    EndIf

    ; Write the zip archive into the bdZip object.
    bdZip.i = CkBinData::ckCreate()
    If bdZip.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkZip::ckWriteBd(zip,bdZip)
    If success = 0
        Debug CkZip::ckLastErrorText(zip)
        CkHttp::ckDispose(http)
        CkZip::ckDispose(zip)
        CkBinData::ckDispose(bdZip)
        ProcedureReturn
    EndIf

    ; Get the zip in base64 format.
    zipAsBase64.s = CkBinData::ckGetEncoded(bdZip,"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.i = CkJsonObject::ckCreate()
    If json.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckUpdateString(json,"userName","ARUBA0000")
    CkJsonObject::ckUpdateString(json,"password","ArubaPwd")
    CkJsonObject::ckUpdateString(json,"userID","ARUBA0000")
    CkJsonObject::ckUpdateString(json,"comunicationType","LI")
    CkJsonObject::ckUpdateString(json,"dataFile",zipAsBase64)

    CkHttp::ckSetRequestHeader(http,"Content-Type","application/json;charset=UTF-8")
    CkHttp::ckSetRequestHeader(http,"Accept","application/json")

    resp.i = CkHttpResponse::ckCreate()
    If resp.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkHttp::ckHttpJson(http,"POST","https://ws.fatturazioneelettronica.aruba.it/services/ClientRequest/CreateTransmissionRequestList",json,"application/json",resp)
    If success = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkZip::ckDispose(zip)
        CkBinData::ckDispose(bdZip)
        CkJsonObject::ckDispose(json)
        CkHttpResponse::ckDispose(resp)
        ProcedureReturn
    EndIf

    sbResponseBody.i = CkStringBuilder::ckCreate()
    If sbResponseBody.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkHttpResponse::ckGetBodySb(resp,sbResponseBody)
    jResp.i = CkJsonObject::ckCreate()
    If jResp.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckLoadSb(jResp,sbResponseBody)
    CkJsonObject::setCkEmitCompact(jResp, 0)

    Debug "Response Body:"
    Debug CkJsonObject::ckEmit(jResp)

    respStatusCode.i = CkHttpResponse::ckStatusCode(resp)
    Debug "Response Status Code = " + Str(respStatusCode)
    If respStatusCode >= 400
        Debug "Response Header:"
        Debug CkHttpResponse::ckHeader(resp)
        Debug "Failed."
        CkHttp::ckDispose(http)
        CkZip::ckDispose(zip)
        CkBinData::ckDispose(bdZip)
        CkJsonObject::ckDispose(json)
        CkHttpResponse::ckDispose(resp)
        CkStringBuilder::ckDispose(sbResponseBody)
        CkJsonObject::ckDispose(jResp)
        ProcedureReturn
    EndIf

    ; 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

    fileName.s

    errorCode.s = CkJsonObject::ckStringOf(jResp,"errorCode")
    errorDescription.s = CkJsonObject::ckStringOf(jResp,"errorDescription")
    requestID.s = CkJsonObject::ckStringOf(jResp,"requestID")
    i.i = 0
    count_i.i = CkJsonObject::ckSizeOfArray(jResp,"requestIDList")
    While i < count_i
        CkJsonObject::setCkI(jResp, i)
        fileName = CkJsonObject::ckStringOf(jResp,"requestIDList[i].fileName")
        requestID = CkJsonObject::ckStringOf(jResp,"requestIDList[i].requestID")
        i = i + 1
    Wend


    CkHttp::ckDispose(http)
    CkZip::ckDispose(zip)
    CkBinData::ckDispose(bdZip)
    CkJsonObject::ckDispose(json)
    CkHttpResponse::ckDispose(resp)
    CkStringBuilder::ckDispose(sbResponseBody)
    CkJsonObject::ckDispose(jResp)


    ProcedureReturn
EndProcedure