Chilkat Online Tools

TCL / Egyptian eInvoicing SDK R1.5 / 8. Request Code Reuse

Back to Collection Items

load ./chilkat.dll

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

set http [new_CkHttp]

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

# The following JSON is sent in the request body.

# {
#   "items": [
#     {
#       "codetype": "EGS",
#       "itemCode": "EG-113317713-5598542",
#       "comment": "create code usage reason"
#     },
#     {
#       "codetype": "EGS",
#       "itemCode": "EG-100000053-10015",
#       "comment": "create code usage reason"
#     }
#   ]
# }

set json [new_CkJsonObject]

CkJsonObject_UpdateString $json "items[0].codetype" "EGS"
CkJsonObject_UpdateString $json "items[0].itemCode" "EG-113317713-5598542"
CkJsonObject_UpdateString $json "items[0].comment" "create code usage reason"
CkJsonObject_UpdateString $json "items[1].codetype" "EGS"
CkJsonObject_UpdateString $json "items[1].itemCode" "EG-100000053-10015"
CkJsonObject_UpdateString $json "items[1].comment" "create code usage reason"

CkHttp_SetRequestHeader $http "Content-Type" "application/json"
CkHttp_SetRequestHeader $http "Accept-Language" "en"
# Adds the "Authorization: Bearer <access_token>" header.
CkHttp_put_AuthToken $http "<access_token>"

set sbRequestBody [new_CkStringBuilder]

CkJsonObject_EmitSb $json $sbRequestBody

# resp is a CkHttpResponse
set resp [CkHttp_PTextSb $http "PUT" "https://domain.com/api/v1.0/codetypes/requests/codeusages" $sbRequestBody "utf-8" "application/json" 0 0]
if {[CkHttp_get_LastMethodSuccess $http] == 0} then {
    puts [CkHttp_lastErrorText $http]
    delete_CkHttp $http
    delete_CkJsonObject $json
    delete_CkStringBuilder $sbRequestBody
    exit
}

puts [CkHttpResponse_get_StatusCode $resp]
puts [CkHttpResponse_bodyStr $resp]
delete_CkHttpResponse $resp


delete_CkHttp $http
delete_CkJsonObject $json
delete_CkStringBuilder $sbRequestBody

Curl Command

curl -X PUT
	-H "Authorization: Bearer <access_token>"
	-H "Content-Type: application/json"
	-H "Accept-Language: en"
	-d '{
    "items": [
        {
            "codetype": "EGS",
            "itemCode": "EG-113317713-5598542",
            "comment": "create code usage reason"
        },
        {
            "codetype": "EGS",
            "itemCode": "EG-100000053-10015",
            "comment": "create code usage reason"
        }
    ]
}'
https://domain.com/api/v1.0/codetypes/requests/codeusages

Postman Collection Item JSON

{
  "name": "8. Request Code Reuse",
  "request": {
    "auth": {
      "type": "bearer",
      "bearer": [
        {
          "key": "token",
          "value": "{{generatedAccessToken}}",
          "type": "string"
        }
      ]
    },
    "method": "PUT",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      },
      {
        "key": "Accept-Language",
        "value": "en",
        "type": "text"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"items\": [\n        {\n            \"codetype\": \"EGS\",\n            \"itemCode\": \"EG-113317713-5598542\",\n            \"comment\": \"create code usage reason\"\n        },\n        {\n            \"codetype\": \"EGS\",\n            \"itemCode\": \"EG-100000053-10015\",\n            \"comment\": \"create code usage reason\"\n        }\n    ]\n}"
    },
    "url": {
      "raw": "{{apiBaseUrl}}/api/v1.0/codetypes/requests/codeusages",
      "host": [
        "{{apiBaseUrl}}"
      ],
      "path": [
        "api",
        "v1.0",
        "codetypes",
        "requests",
        "codeusages"
      ]
    }
  },
  "response": [
  ]
}