Chilkat Online Tools

Swift3 / Egyptian eInvoicing SDK R1.5 / 2. Get Document Types

Back to Collection Items

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

    let http = CkoHttp()!
    var success: Bool

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

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

    // {
    //   "documentTypeCodeName": "creditupdated",
    //   "namePrimaryLang": "CreditEn",
    //   "nameSecondaryLang": "CreditAr",
    //   "descriptionPrimaryLang": "Des-creditEn",
    //   "descriptionSecondaryLang": "Des-creditAr",
    //   "activeFrom": "2020-06-09T07:38:54.836Z"
    // }

    let json = CkoJsonObject()!
    json.update("documentTypeCodeName", value: "creditupdated")
    json.update("namePrimaryLang", value: "CreditEn")
    json.update("nameSecondaryLang", value: "CreditAr")
    json.update("descriptionPrimaryLang", value: "Des-creditEn")
    json.update("descriptionSecondaryLang", value: "Des-creditAr")
    json.update("activeFrom", value: "2020-06-09T07:38:54.836Z")

    // Adds the "Authorization: Bearer <access_token>" header.
    http.authToken = "<access_token>"
    http.setRequestHeader("Accept-Language", value: "ar")

    let sbRequestBody = CkoStringBuilder()!
    json.emitSb(sbRequestBody)

    var resp: CkoHttpResponse? = http.pTextSb("GET", url: "https://domain.com/api/v1/documenttypes", textData: sbRequestBody, charset: "utf-8", contentType: "application/json", md5: false, gzip: false)
    if http.lastMethodSuccess == false {
        print("\(http.lastErrorText!)")
        return
    }

    print("\(resp!.statusCode.intValue)")
    print("\(resp!.bodyStr!)")
    resp = nil

}

Curl Command

curl -X GET
	-H "Authorization: Bearer <access_token>"
	-H "Accept-Language: ar"
	-d '{
    "documentTypeCodeName": "creditupdated",
    "namePrimaryLang": "CreditEn",
    "nameSecondaryLang": "CreditAr",
    "descriptionPrimaryLang": "Des-creditEn",
    "descriptionSecondaryLang": "Des-creditAr",
    "activeFrom": "2020-06-09T07:38:54.836Z"
}'
https://domain.com/api/v1/documenttypes

Postman Collection Item JSON

{
  "name": "2. Get Document Types",
  "protocolProfileBehavior": {
    "disableBodyPruning": true
  },
  "request": {
    "auth": {
      "type": "bearer",
      "bearer": [
        {
          "key": "token",
          "value": "{{generatedAccessToken}}",
          "type": "string"
        }
      ]
    },
    "method": "GET",
    "header": [
      {
        "key": "Accept-Language",
        "value": "ar",
        "type": "text"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\r\n    \"documentTypeCodeName\": \"creditupdated\",\r\n    \"namePrimaryLang\": \"CreditEn\",\r\n    \"nameSecondaryLang\": \"CreditAr\",\r\n    \"descriptionPrimaryLang\": \"Des-creditEn\",\r\n    \"descriptionSecondaryLang\": \"Des-creditAr\",\r\n    \"activeFrom\": \"2020-06-09T07:38:54.836Z\"\r\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{apiBaseUrl}}/api/v1/documenttypes",
      "host": [
        "{{apiBaseUrl}}"
      ],
      "path": [
        "api",
        "v1",
        "documenttypes"
      ]
    }
  },
  "response": [
  ]
}