Sample code for 30+ languages & platforms
Swift

Aruba Fatturazione Elettronica Upload Invoice

See more Aruba Fatturazione Examples

This method must be used by the EO to send an invoice in XML format in accordance with AGID standards, but not yet digitally signed.

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

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

    let http = CkoHttp()!

    // Implements the following CURL command:

    // curl -X POST https://ws.fatturazioneelettronica.aruba.it/services/invoice/upload \
    //   -H "Accept: application/json" \
    //   -H "Authorization: Bearer NLOGDVXLVaF3tzmnVPkTwpkuh7dG0i09uSCcog3u+rE=" \
    //   -H "Content-Type: application/json;charset=UTF-8" \
    //   -d '{
    //   "dataFile" : "dGVzdA==",
    //   "credential" : "",
    //   "domain" : ""
    // }'

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

    // {
    //   "dataFile": "dGVzdA==",
    //   "credential": "",
    //   "domain": ""
    // }

    // The dataFile field must contain an XML invoice not yet digitally signed.
    let sbInvoiceXml = CkoStringBuilder()!
    success = sbInvoiceXml.loadFile(path: "qa_data/aruba/invoice123.xml", charset: "utf-8")

    let json = CkoJsonObject()!
    json.updateString(jsonPath: "dataFile", value: sbInvoiceXml.getEncoded(encoding: "base64", charset: "utf-8"))
    json.updateString(jsonPath: "credential", value: "")
    json.updateString(jsonPath: "domain", value: "")

    http.setRequestHeader(name: "Accept", value: "application/json")
    // Adds the "Authorization: Bearer NLOGDVXLVaF3tzmnVPkTwpkuh7dG0i09uSCcog3u+rE=" header.
    http.authToken = "NLOGDVXLVaF3tzmnVPkTwpkuh7dG0i09uSCcog3u+rE="
    http.setRequestHeader(name: "Content-Type", value: "application/json;charset=UTF-8")

    let resp = CkoHttpResponse()!
    success = http.httpJson(verb: "POST", url: "https://ws.fatturazioneelettronica.aruba.it/services/invoice/upload", json: json, contentType: "application/json", response: resp)
    if success == false {
        print("\(http.lastErrorText!)")
        return
    }

    let sbResponseBody = CkoStringBuilder()!
    resp.getBodySb(sb: sbResponseBody)
    let jResp = CkoJsonObject()!
    jResp.loadSb(sb: sbResponseBody)
    jResp.emitCompact = false

    print("Response Body:")
    print("\(jResp.emit()!)")

    var respStatusCode: Int = resp.statusCode.intValue
    print("Response Status Code = \(respStatusCode)")
    if respStatusCode >= 400 {
        print("Response Header:")
        print("\(resp.header!)")
        print("Failed.")
        return
    }

    // Sample JSON response:
    // (Sample code for parsing the JSON response is shown below)

    // {
    //   "errorCode": "0000",
    //   "errorDescription": "Operazione effettuata - 521e052902be7b879d41e0fd586f0e21",
    //   "uploadFileName": "IT06491598644_zbvbd.xml.p7m"
    // }

    // Sample code for parsing the JSON response...
    // Use the following online tool to generate parsing code from sample JSON:
    // Generate Parsing Code from JSON

    var errorCode: String? = jResp.string(of: "errorCode")
    var errorDescription: String? = jResp.string(of: "errorDescription")
    var uploadFileName: String? = jResp.string(of: "uploadFileName")

}