Back to Collection Items
integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_Json
oleobject loo_SbRequestBody
oleobject loo_Resp
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Http = create oleobject
// Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
destroy loo_Http
MessageBox("Error","Connecting to COM object failed")
return
end if
// 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"
// }
// ]
// }
loo_Json = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
loo_Json.UpdateString("items[0].codetype","EGS")
loo_Json.UpdateString("items[0].itemCode","EG-113317713-5598542")
loo_Json.UpdateString("items[0].comment","create code usage reason")
loo_Json.UpdateString("items[1].codetype","EGS")
loo_Json.UpdateString("items[1].itemCode","EG-100000053-10015")
loo_Json.UpdateString("items[1].comment","create code usage reason")
loo_Http.SetRequestHeader("Content-Type","application/json")
loo_Http.SetRequestHeader("Accept-Language","en")
// Adds the "Authorization: Bearer <access_token>" header.
loo_Http.AuthToken = "<access_token>"
loo_SbRequestBody = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbRequestBody.ConnectToNewObject("Chilkat.StringBuilder")
loo_Json.EmitSb(loo_SbRequestBody)
loo_Resp = loo_Http.PTextSb("PUT","https://domain.com/api/v1.0/codetypes/requests/codeusages",loo_SbRequestBody,"utf-8","application/json",0,0)
if loo_Http.LastMethodSuccess = 0 then
Write-Debug loo_Http.LastErrorText
destroy loo_Http
destroy loo_Json
destroy loo_SbRequestBody
return
end if
Write-Debug string(loo_Resp.StatusCode)
Write-Debug loo_Resp.BodyStr
destroy loo_Resp
destroy loo_Http
destroy loo_Json
destroy loo_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": [
]
}