Back to Collection Items
var os = require('os');
if (os.platform() == 'win32') {
if (os.arch() == 'ia32') {
var chilkat = require('@chilkat/ck-node21-win-ia32');
} else {
var chilkat = require('@chilkat/ck-node21-win64');
}
} else if (os.platform() == 'linux') {
if (os.arch() == 'arm') {
var chilkat = require('@chilkat/ck-node21-arm');
} else if (os.arch() == 'x86') {
var chilkat = require('@chilkat/ck-node21-linux32');
} else {
var chilkat = require('@chilkat/ck-node21-linux64');
}
} else if (os.platform() == 'darwin') {
if (os.arch() == 'arm64') {
var chilkat = require('@chilkat/ck-node21-mac-m1');
} else {
var chilkat = require('@chilkat/ck-node21-macosx');
}
}
function chilkatExample() {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
var http = new chilkat.Http();
var success;
// 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"
// }
// }
var json = new chilkat.JsonObject();
json.UpdateString("endpoint.deploymentType","CH");
json.UpdateNull("endpoint.isCloudHub");
json.UpdateNull("endpoint.muleVersion4OrAbove");
json.UpdateNull("endpoint.proxyUri");
json.UpdateNull("endpoint.referencesUserDomain");
json.UpdateNull("endpoint.responseTimeout");
json.UpdateString("endpoint.type","raml");
json.UpdateNull("endpoint.uri");
json.UpdateNull("providerId");
json.UpdateNull("instanceLabel");
json.UpdateString("spec.assetId","hello-word");
json.UpdateString("spec.groupId","af696110-60f8-4a47-9367-e2464a468949");
json.UpdateString("spec.version","0.0.1");
// Adds the "Authorization: Bearer {{token}}" header.
http.AuthToken = "{{token}}";
// resp: HttpResponse
var resp = http.PostJson3("https://domain.com/apimanager/api/v1/organizations/{{organization_id}}/environments/{{environment_id}}/apis","application/json",json);
if (http.LastMethodSuccess == false) {
console.log(http.LastErrorText);
return;
}
console.log(resp.StatusCode);
console.log(resp.BodyStr);
}
chilkatExample();
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": [
]
}