Chilkat Online Tools

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

Back to Collection Items

IncludeFile "CkJsonObject.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkHttpResponse.pb"

Procedure ChilkatExample()

    ; 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

    success.i

    ; 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": ""
    ;       }
    ;     ]
    ;   }
    ; }

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

    CkJsonObject::ckUpdateString(json,"type","Full")
    CkJsonObject::ckUpdateString(json,"format","XML")
    CkJsonObject::ckUpdateString(json,"queryParameters.dateFrom","2021-01-01T00:00:00.000Z")
    CkJsonObject::ckUpdateString(json,"queryParameters.dateTo","2021-01-31T00:00:00.000Z")
    CkJsonObject::ckUpdateString(json,"queryParameters.statuses[0]","Valid")
    CkJsonObject::ckUpdateNewArray(json,"queryParameters.productsInternalCodes")
    CkJsonObject::ckUpdateString(json,"queryParameters.receiverSenderType","0")
    CkJsonObject::ckUpdateString(json,"queryParameters.documentTypeNames[0]","C")
    CkJsonObject::ckUpdateString(json,"queryParameters.documentTypeNames[1]","D")
    CkJsonObject::ckUpdateString(json,"queryParameters.documentTypeNames[2]","I")
    CkJsonObject::ckUpdateString(json,"queryParameters.representedTaxpayerFilterType","1")
    CkJsonObject::ckUpdateString(json,"queryParameters.representeeRin","")
    CkJsonObject::ckUpdateString(json,"queryParameters.branchNumber","")
    CkJsonObject::ckUpdateString(json,"queryParameters.itemCodes[0].codeValue","")
    CkJsonObject::ckUpdateString(json,"queryParameters.itemCodes[0].codeType","")

    ; Adds the "Authorization: Bearer <access_token>" header.
    CkHttp::setCkAuthToken(http, "<access_token>")

    resp.i = CkHttp::ckPostJson3(http,"https://domain.com/api/v1/documentPackages/requests","application/json",json)
    If CkHttp::ckLastMethodSuccess(http) = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(json)
        ProcedureReturn
    EndIf

    Debug Str(CkHttpResponse::ckStatusCode(resp))
    Debug CkHttpResponse::ckBodyStr(resp)
    CkHttpResponse::ckDispose(resp)



    CkHttp::ckDispose(http)
    CkJsonObject::ckDispose(json)


    ProcedureReturn
EndProcedure

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": [
  ]
}