Back to Collection Items
Use ChilkatAx-win32.pkg
Procedure Test
Handle hoHttp
Boolean iSuccess
Handle hoJarr
Variant vJsonObj_1
Handle hoJsonObj_1
Variant vSbRequestBody
Handle hoSbRequestBody
Variant vResp
Handle hoResp
String sTemp1
Integer iTemp1
Boolean bTemp1
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
// Use this online tool to generate code from sample JSON: Generate Code to Create JSON
// The following JSON is sent in the request body.
// [
// {
// "context_params": {
// "org": "af696110-60f8-4a47-9367-e2464a468949"
// },
// "role_id": "821d84e6-ee22-4646-bf25-5461d49c9690"
// }
// ]
Get Create (RefClass(cComChilkatJsonArray)) To hoJarr
If (Not(IsComObjectCreated(hoJarr))) Begin
Send CreateComObject of hoJarr
End
Get ComAddObjectAt Of hoJarr -1 To iSuccess
Get ComSize Of hoJarr To iTemp1
Get ComObjectAt Of hoJarr (iTemp1 - 1) To vJsonObj_1
If (IsComObject(vJsonObj_1)) Begin
Get Create (RefClass(cComChilkatJsonObject)) To hoJsonObj_1
Set pvComObject Of hoJsonObj_1 To vJsonObj_1
End
Get ComUpdateString Of hoJsonObj_1 "context_params.org" "af696110-60f8-4a47-9367-e2464a468949" To iSuccess
Get ComUpdateString Of hoJsonObj_1 "role_id" "821d84e6-ee22-4646-bf25-5461d49c9690" To iSuccess
Send Destroy of hoJsonObj_1
// Adds the "Authorization: Bearer {{token}}" header.
Set ComAuthToken Of hoHttp To "{{token}}"
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbRequestBody
If (Not(IsComObjectCreated(hoSbRequestBody))) Begin
Send CreateComObject of hoSbRequestBody
End
Get pvComObject of hoSbRequestBody to vSbRequestBody
Get ComEmitSb Of hoJarr vSbRequestBody To iSuccess
Get pvComObject of hoSbRequestBody to vSbRequestBody
Get ComPTextSb Of hoHttp "POST" "https://domain.com/accounts/api/organizations/{{organization_id}}/rolegroups/{{rolegroup_Id}}/roles" vSbRequestBody "utf-8" "application/json" False False To vResp
If (IsComObject(vResp)) Begin
Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
Set pvComObject Of hoResp To vResp
End
Get ComLastMethodSuccess Of hoHttp To bTemp1
If (bTemp1 = False) Begin
Get ComLastErrorText Of hoHttp To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComStatusCode Of hoResp To iTemp1
Showln iTemp1
Get ComBodyStr Of hoResp To sTemp1
Showln sTemp1
Send Destroy of hoResp
End_Procedure
Curl Command
curl -X POST
-H "Authorization: Bearer {{token}}"
-d '[
{
"context_params":
{
"org":"af696110-60f8-4a47-9367-e2464a468949"
},
"role_id":"821d84e6-ee22-4646-bf25-5461d49c9690"
}
]'
https://domain.com/accounts/api/organizations/{{organization_id}}/rolegroups/{{rolegroup_Id}}/roles
Postman Collection Item JSON
{
"name": "Add a new role to rolegroup",
"request": {
"method": "POST",
"header": [
{
"key": "Authorization",
"value": "Bearer {{token}}",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "[\r\n {\r\n \"context_params\":\r\n {\r\n \"org\":\"af696110-60f8-4a47-9367-e2464a468949\"\r\n },\r\n \"role_id\":\"821d84e6-ee22-4646-bf25-5461d49c9690\"\r\n }\r\n]",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{url}}/accounts/api/organizations/{{organization_id}}/rolegroups/{{rolegroup_Id}}/roles",
"host": [
"{{url}}"
],
"path": [
"accounts",
"api",
"organizations",
"{{organization_id}}",
"rolegroups",
"{{rolegroup_Id}}",
"roles"
]
}
},
"response": [
]
}