Chilkat Online Tools

unicodeC / Anypoint Platform APIs / Share asset

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkHttpResponseW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkJsonObjectW json;
    HCkStringBuilderW sbRequestBody;
    HCkHttpResponseW resp;

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

    http = CkHttpW_Create();

    // Use this online tool to generate code from sample JSON: Generate Code to Create JSON

    // The following JSON is sent in the request body.

    // {
    //   "added": [
    //     {
    //       "identityId": "af696110-60f8-4a47-9367-e2464a468949",
    //       "role": "viewer",
    //       "identityType": "organization",
    //       "organizationId": "{{organization_id}}"
    //     }
    //   ],
    //   "deleted": [
    //   ]
    // }

    json = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(json,L"added[0].identityId",L"af696110-60f8-4a47-9367-e2464a468949");
    CkJsonObjectW_UpdateString(json,L"added[0].role",L"viewer");
    CkJsonObjectW_UpdateString(json,L"added[0].identityType",L"organization");
    CkJsonObjectW_UpdateString(json,L"added[0].organizationId",L"{{organization_id}}");
    CkJsonObjectW_UpdateNewArray(json,L"deleted");

    // Adds the "Authorization: Bearer {{token}}" header.
    CkHttpW_putAuthToken(http,L"{{token}}");

    sbRequestBody = CkStringBuilderW_Create();
    CkJsonObjectW_EmitSb(json,sbRequestBody);

    resp = CkHttpW_PTextSb(http,L"PUT",L"https://domain.com/exchange/api/v2/assets/{{organization_id}}/{{app_Id}}/identities",sbRequestBody,L"utf-8",L"application/json",FALSE,FALSE);
    if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(json);
        CkStringBuilderW_Dispose(sbRequestBody);
        return;
    }

    wprintf(L"%d\n",CkHttpResponseW_getStatusCode(resp));
    wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));
    CkHttpResponseW_Dispose(resp);


    CkHttpW_Dispose(http);
    CkJsonObjectW_Dispose(json);
    CkStringBuilderW_Dispose(sbRequestBody);

    }

Curl Command

curl -X PUT
	-H "Authorization: Bearer {{token}}"
	-d '{
   "added":[
      {
         "identityId":"af696110-60f8-4a47-9367-e2464a468949",
         "role":"viewer",
         "identityType":"organization",
         "organizationId":"{{organization_id}}"
      }
   ],
   "deleted":[
      
   ]
}'
https://domain.com/exchange/api/v2/assets/{{organization_id}}/{{app_Id}}/identities

Postman Collection Item JSON

{
  "name": "Share asset",
  "request": {
    "method": "PUT",
    "header": [
      {
        "key": "Authorization",
        "value": "Bearer {{token}}",
        "type": "text"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\r\n   \"added\":[\r\n      {\r\n         \"identityId\":\"af696110-60f8-4a47-9367-e2464a468949\",\r\n         \"role\":\"viewer\",\r\n         \"identityType\":\"organization\",\r\n         \"organizationId\":\"{{organization_id}}\"\r\n      }\r\n   ],\r\n   \"deleted\":[\r\n      \r\n   ]\r\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{url}}/exchange/api/v2/assets/{{organization_id}}/{{app_Id}}/identities",
      "host": [
        "{{url}}"
      ],
      "path": [
        "exchange",
        "api",
        "v2",
        "assets",
        "{{organization_id}}",
        "{{app_Id}}",
        "identities"
      ]
    }
  },
  "response": [
  ]
}