Chilkat Online Tools

delphiDll / Anypoint Platform APIs / Create API from Exchange

Back to Collection Items

var
http: HCkHttp;
success: Boolean;
json: HCkJsonObject;
resp: HCkHttpResponse;

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

http := CkHttp_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.

// {
//   "endpoint": {
//     "deploymentType": "CH",
//     "isCloudHub": null,
//     "muleVersion4OrAbove": null,
//     "proxyUri": null,
//     "referencesUserDomain": null,
//     "responseTimeout": null,
//     "type": "raml",
//     "uri": null
//   },
//   "providerId": null,
//   "instanceLabel": null,
//   "spec": {
//     "assetId": "hello-word",
//     "groupId": "af696110-60f8-4a47-9367-e2464a468949",
//     "version": "0.0.1"
//   }
// }

json := CkJsonObject_Create();
CkJsonObject_UpdateString(json,'endpoint.deploymentType','CH');
CkJsonObject_UpdateNull(json,'endpoint.isCloudHub');
CkJsonObject_UpdateNull(json,'endpoint.muleVersion4OrAbove');
CkJsonObject_UpdateNull(json,'endpoint.proxyUri');
CkJsonObject_UpdateNull(json,'endpoint.referencesUserDomain');
CkJsonObject_UpdateNull(json,'endpoint.responseTimeout');
CkJsonObject_UpdateString(json,'endpoint.type','raml');
CkJsonObject_UpdateNull(json,'endpoint.uri');
CkJsonObject_UpdateNull(json,'providerId');
CkJsonObject_UpdateNull(json,'instanceLabel');
CkJsonObject_UpdateString(json,'spec.assetId','hello-word');
CkJsonObject_UpdateString(json,'spec.groupId','af696110-60f8-4a47-9367-e2464a468949');
CkJsonObject_UpdateString(json,'spec.version','0.0.1');

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

resp := CkHttp_PostJson3(http,'https://domain.com/apimanager/api/v1/organizations/{{organization_id}}/environments/{{environment_id}}/apis','application/json',json);
if (CkHttp_getLastMethodSuccess(http) = False) then
  begin
    Memo1.Lines.Add(CkHttp__lastErrorText(http));
    Exit;
  end;

Memo1.Lines.Add(IntToStr(CkHttpResponse_getStatusCode(resp)));
Memo1.Lines.Add(CkHttpResponse__bodyStr(resp));
CkHttpResponse_Dispose(resp);

CkHttp_Dispose(http);
CkJsonObject_Dispose(json);

Curl Command

curl -X POST
	-H "Authorization: Bearer {{token}}"
	-d '{
   "endpoint":{
      "deploymentType":"CH",
      "isCloudHub":null,
      "muleVersion4OrAbove":null,
      "proxyUri":null,
      "referencesUserDomain":null,
      "responseTimeout":null,
      "type":"raml",
      "uri":null
   },
   "providerId":null,
   "instanceLabel":null,
   "spec":{
      "assetId":"hello-word",
      "groupId":"af696110-60f8-4a47-9367-e2464a468949",
      "version":"0.0.1"
   }
}'
https://domain.com/apimanager/api/v1/organizations/{{organization_id}}/environments/{{environment_id}}/apis

Postman Collection Item JSON

{
  "name": "Create API from Exchange",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Authorization",
        "value": "Bearer {{token}}",
        "type": "text"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\r\n   \"endpoint\":{\r\n      \"deploymentType\":\"CH\",\r\n      \"isCloudHub\":null,\r\n      \"muleVersion4OrAbove\":null,\r\n      \"proxyUri\":null,\r\n      \"referencesUserDomain\":null,\r\n      \"responseTimeout\":null,\r\n      \"type\":\"raml\",\r\n      \"uri\":null\r\n   },\r\n   \"providerId\":null,\r\n   \"instanceLabel\":null,\r\n   \"spec\":{\r\n      \"assetId\":\"hello-word\",\r\n      \"groupId\":\"af696110-60f8-4a47-9367-e2464a468949\",\r\n      \"version\":\"0.0.1\"\r\n   }\r\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{url}}/apimanager/api/v1/organizations/{{organization_id}}/environments/{{environment_id}}/apis",
      "host": [
        "{{url}}"
      ],
      "path": [
        "apimanager",
        "api",
        "v1",
        "organizations",
        "{{organization_id}}",
        "environments",
        "{{environment_id}}",
        "apis"
      ]
    }
  },
  "response": [
  ]
}