Back to Collection Items
#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>
void ChilkatSample(void)
{
HCkHttpW http;
BOOL success;
HCkJsonObjectW json;
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.
// {
// "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 = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(json,L"endpoint.deploymentType",L"CH");
CkJsonObjectW_UpdateNull(json,L"endpoint.isCloudHub");
CkJsonObjectW_UpdateNull(json,L"endpoint.muleVersion4OrAbove");
CkJsonObjectW_UpdateNull(json,L"endpoint.proxyUri");
CkJsonObjectW_UpdateNull(json,L"endpoint.referencesUserDomain");
CkJsonObjectW_UpdateNull(json,L"endpoint.responseTimeout");
CkJsonObjectW_UpdateString(json,L"endpoint.type",L"raml");
CkJsonObjectW_UpdateNull(json,L"endpoint.uri");
CkJsonObjectW_UpdateNull(json,L"providerId");
CkJsonObjectW_UpdateNull(json,L"instanceLabel");
CkJsonObjectW_UpdateString(json,L"spec.assetId",L"hello-word");
CkJsonObjectW_UpdateString(json,L"spec.groupId",L"af696110-60f8-4a47-9367-e2464a468949");
CkJsonObjectW_UpdateString(json,L"spec.version",L"0.0.1");
// Adds the "Authorization: Bearer {{token}}" header.
CkHttpW_putAuthToken(http,L"{{token}}");
resp = CkHttpW_PostJson3(http,L"https://domain.com/apimanager/api/v1/organizations/{{organization_id}}/environments/{{environment_id}}/apis",L"application/json",json);
if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(json);
return;
}
wprintf(L"%d\n",CkHttpResponseW_getStatusCode(resp));
wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));
CkHttpResponseW_Dispose(resp);
CkHttpW_Dispose(http);
CkJsonObjectW_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": [
]
}