Chilkat Online Tools

Objective-C / Egyptian eInvoicing SDK R1.5 / 8. Request Code Reuse

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.

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

CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json UpdateString: @"items[0].codetype" value: @"EGS"];
[json UpdateString: @"items[0].itemCode" value: @"EG-113317713-5598542"];
[json UpdateString: @"items[0].comment" value: @"create code usage reason"];
[json UpdateString: @"items[1].codetype" value: @"EGS"];
[json UpdateString: @"items[1].itemCode" value: @"EG-100000053-10015"];
[json UpdateString: @"items[1].comment" value: @"create code usage reason"];

[http SetRequestHeader: @"Content-Type" value: @"application/json"];
[http SetRequestHeader: @"Accept-Language" value: @"en"];
// Adds the "Authorization: Bearer <access_token>" header.
http.AuthToken = @"<access_token>";

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

CkoHttpResponse *resp = [http PTextSb: @"PUT" url: @"https://domain.com/api/v1.0/codetypes/requests/codeusages" 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"
	-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": [
  ]
}