Chilkat Online Tools

Objective-C / Egyptian eInvoicing SDK R1.5 / 3. Reject Document

Back to Collection Items

#import <CkoHttp.h>
#import <CkoJsonObject.h>
#import <CkoStringBuilder.h>
#import <CkoHttpResponse.h>

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

CkoHttp *http = [[CkoHttp alloc] init];
BOOL 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.

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

CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json UpdateString: @"status" value: @"rejected"];
[json UpdateString: @"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"];

CkoStringBuilder *sbRequestBody = [[CkoStringBuilder alloc] init];
[json EmitSb: sbRequestBody];

CkoHttpResponse *resp = [http PTextSb: @"PUT" url: @"https://domain.com/api/v1.0/documents/state/:documentUUID/state" textData: sbRequestBody charset: @"utf-8" contentType: @"application/json" md5: NO gzip: NO];
if (http.LastMethodSuccess == NO) {
    NSLog(@"%@",http.LastErrorText);
    return;
}

NSLog(@"%d",[resp.StatusCode intValue]);
NSLog(@"%@",resp.BodyStr);

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