Chilkat Online Tools

Swift3 / Egyptian eInvoicing SDK R1.5 / 3. Reject Document

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.

    // {
    //   "status": "rejected",
    //   "reason": "some reason for rejected document"
    // }

    let json = CkoJsonObject()!
    json.update("status", value: "rejected")
    json.update("reason", value: "some reason for rejected document")

    // Adds the "Authorization: Bearer <access_token>" header.
    http.authToken = "<access_token>"
    http.setRequestHeader("Content-Type", value: "application/json")

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

    var resp: CkoHttpResponse? = http.pTextSb("PUT", url: "https://domain.com/api/v1.0/documents/state/:documentUUID/state", 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 PUT
	-H "Authorization: Bearer <access_token>"
	-H "Content-Type: application/json"
	-d '{
	"status":"rejected",
	"reason":"some reason for rejected document"
}'
https://domain.com/api/v1.0/documents/state/:documentUUID/state

Postman Collection Item JSON

{
  "name": "3. Reject Document",
  "request": {
    "auth": {
      "type": "bearer",
      "bearer": [
        {
          "key": "token",
          "value": "{{generatedAccessToken}}",
          "type": "string"
        }
      ]
    },
    "method": "PUT",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n\t\"status\":\"rejected\",\n\t\"reason\":\"some reason for rejected document\"\n}"
    },
    "url": {
      "raw": "{{apiBaseUrl}}/api/v1.0/documents/state/:documentUUID/state",
      "host": [
        "{{apiBaseUrl}}"
      ],
      "path": [
        "api",
        "v1.0",
        "documents",
        "state",
        ":documentUUID",
        "state"
      ],
      "variable": [
        {
          "key": "documentUUID",
          "value": ""
        }
      ]
    }
  },
  "response": [
  ]
}