Chilkat Online Tools

Node.js / Egyptian eInvoicing SDK R1.5 / 5.1 Request Document Package as intermediary

Back to Collection Items

var os = require('os');
if (os.platform() == 'win32') {  
    if (os.arch() == 'ia32') {
        var chilkat = require('@chilkat/ck-node21-win-ia32');
    } else {
        var chilkat = require('@chilkat/ck-node21-win64'); 
    }
} else if (os.platform() == 'linux') {
    if (os.arch() == 'arm') {
        var chilkat = require('@chilkat/ck-node21-arm');
    } else if (os.arch() == 'x86') {
        var chilkat = require('@chilkat/ck-node21-linux32');
    } else {
        var chilkat = require('@chilkat/ck-node21-linux64');
    }
} else if (os.platform() == 'darwin') {
    if (os.arch() == 'arm64') {
        var chilkat = require('@chilkat/ck-node21-mac-m1');
    } else {
        var chilkat = require('@chilkat/ck-node21-macosx');
    }
}


function chilkatExample() {

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

    var http = new chilkat.Http();
    var success;

    // Use this online tool to generate code from sample JSON: Generate Code to Create JSON

    // The following JSON is sent in the request body.

    // {
    //   "type": "Full",
    //   "format": "XML",
    //   "queryParameters": {
    //     "dateFrom": "2021-01-01T00:00:00.000Z",
    //     "dateTo": "2021-01-31T00:00:00.000Z",
    //     "statuses": [
    //       "Valid"
    //     ],
    //     "productsInternalCodes": [
    //     ],
    //     "receiverSenderType": "0",
    //     "documentTypeNames": [
    //       "C",
    //       "D",
    //       "I"
    //     ],
    //     "representedTaxpayerFilterType": "1",
    //     "representeeRin": "",
    //     "branchNumber": "",
    //     "itemCodes": [
    //       {
    //         "codeValue": "",
    //         "codeType": ""
    //       }
    //     ]
    //   }
    // }

    var json = new chilkat.JsonObject();
    json.UpdateString("type","Full");
    json.UpdateString("format","XML");
    json.UpdateString("queryParameters.dateFrom","2021-01-01T00:00:00.000Z");
    json.UpdateString("queryParameters.dateTo","2021-01-31T00:00:00.000Z");
    json.UpdateString("queryParameters.statuses[0]","Valid");
    json.UpdateNewArray("queryParameters.productsInternalCodes");
    json.UpdateString("queryParameters.receiverSenderType","0");
    json.UpdateString("queryParameters.documentTypeNames[0]","C");
    json.UpdateString("queryParameters.documentTypeNames[1]","D");
    json.UpdateString("queryParameters.documentTypeNames[2]","I");
    json.UpdateString("queryParameters.representedTaxpayerFilterType","1");
    json.UpdateString("queryParameters.representeeRin","");
    json.UpdateString("queryParameters.branchNumber","");
    json.UpdateString("queryParameters.itemCodes[0].codeValue","");
    json.UpdateString("queryParameters.itemCodes[0].codeType","");

    // Adds the "Authorization: Bearer <access_token>" header.
    http.AuthToken = "<access_token>";

    // resp: HttpResponse
    var resp = http.PostJson3("https://domain.com/api/v1/documentPackages/requests","application/json",json);
    if (http.LastMethodSuccess == false) {
        console.log(http.LastErrorText);
        return;
    }

    console.log(resp.StatusCode);
    console.log(resp.BodyStr);


}

chilkatExample();

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-d '{
    "type": "Full",
    "format": "XML",
    "queryParameters": {
        "dateFrom": "2021-01-01T00:00:00.000Z",
        "dateTo": "2021-01-31T00:00:00.000Z",
        "statuses": [
            "Valid"
        ],
        "productsInternalCodes": [],
        "receiverSenderType": "0",
        "documentTypeNames": [
            "C",
            "D",
            "I"
        ],
        "representedTaxpayerFilterType": "1",
        "representeeRin": "",
        "branchNumber": "",
        "itemCodes": [
            {
                "codeValue": "",
                "codeType": ""
            }
        ]
    }
}'
https://domain.com/api/v1/documentPackages/requests

Postman Collection Item JSON

{
  "name": "5.1 Request Document Package as intermediary",
  "request": {
    "auth": {
      "type": "bearer",
      "bearer": [
        {
          "key": "token",
          "value": "{{generatedAccessToken}}",
          "type": "string"
        }
      ]
    },
    "method": "POST",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "{\r\n    \"type\": \"Full\",\r\n    \"format\": \"XML\",\r\n    \"queryParameters\": {\r\n        \"dateFrom\": \"2021-01-01T00:00:00.000Z\",\r\n        \"dateTo\": \"2021-01-31T00:00:00.000Z\",\r\n        \"statuses\": [\r\n            \"Valid\"\r\n        ],\r\n        \"productsInternalCodes\": [],\r\n        \"receiverSenderType\": \"0\",\r\n        \"documentTypeNames\": [\r\n            \"C\",\r\n            \"D\",\r\n            \"I\"\r\n        ],\r\n        \"representedTaxpayerFilterType\": \"1\",\r\n        \"representeeRin\": \"\",\r\n        \"branchNumber\": \"\",\r\n        \"itemCodes\": [\r\n            {\r\n                \"codeValue\": \"\",\r\n                \"codeType\": \"\"\r\n            }\r\n        ]\r\n    }\r\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{apiBaseUrl}}/api/v1/documentPackages/requests",
      "host": [
        "{{apiBaseUrl}}"
      ],
      "path": [
        "api",
        "v1",
        "documentPackages",
        "requests"
      ]
    }
  },
  "response": [
  ]
}