Chilkat Online Tools

C / Anypoint Platform APIs / Publish new asset on exchange

Back to Collection Items

#include <C_CkHttp.h>
#include <C_CkHttpRequest.h>
#include <C_CkJsonObject.h>
#include <C_CkHttpResponse.h>

void ChilkatSample(void)
    {
    HCkHttp http;
    BOOL success;
    HCkHttpRequest req;
    HCkJsonObject jsonFormData1;
    HCkJsonObject jsonFormData2;
    HCkHttpResponse resp;

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

    http = CkHttp_Create();

    req = CkHttpRequest_Create();
    CkHttpRequest_putHttpVerb(req,"POST");
    CkHttpRequest_putPath(req,"/exchange/api/v1/assets");
    CkHttpRequest_putContentType(req,"multipart/form-data");

    jsonFormData1 = CkJsonObject_Create();
    CkHttpRequest_AddStringForUpload2(req,"organizationId","",jsonFormData1,"utf-8","application/json");

    jsonFormData2 = CkJsonObject_Create();
    CkHttpRequest_AddStringForUpload2(req,"groupId","",jsonFormData2,"utf-8","application/json");

    CkHttpRequest_AddParam(req,"assetId","{{organization_id}}{{organization_id}}mysoapapp");

    CkHttpRequest_AddParam(req,"version","{{organization_id}}{{organization_id}}mysoapapp1.0.0");

    CkHttpRequest_AddParam(req,"{{organization_id}}{{organization_id}}mysoapapp1.0.0my soap app","");

    CkHttpRequest_AddParam(req,"classifier","{{organization_id}}{{organization_id}}mysoapapp1.0.0my soap appwsdl");

    CkHttpRequest_AddParam(req,"apiVersion","{{organization_id}}{{organization_id}}mysoapapp1.0.0my soap appwsdlv1");

    success = CkHttpRequest_AddFileForUpload2(req,"asset"," path to file","application/octet-stream");

    CkHttpRequest_AddHeader(req,"Authorization","Bearer {{token}}");
    CkHttpRequest_AddHeader(req,"Expect","100-continue");

    resp = CkHttp_SynchronousRequest(http,"domain.com",443,TRUE,req);
    if (CkHttp_getLastMethodSuccess(http) == FALSE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        CkHttpRequest_Dispose(req);
        CkJsonObject_Dispose(jsonFormData1);
        CkJsonObject_Dispose(jsonFormData2);
        return;
    }

    printf("%d\n",CkHttpResponse_getStatusCode(resp));
    printf("%s\n",CkHttpResponse_bodyStr(resp));
    CkHttpResponse_Dispose(resp);


    CkHttp_Dispose(http);
    CkHttpRequest_Dispose(req);
    CkJsonObject_Dispose(jsonFormData1);
    CkJsonObject_Dispose(jsonFormData2);

    }

Curl Command

curl -X POST
	-H "Authorization: Bearer {{token}}"
	--form 'organizationId={{organization_id}}'
	--form 'groupId={{organization_id}}{{organization_id}}'
	--form 'assetId={{organization_id}}{{organization_id}}mysoapapp'
	--form 'version={{organization_id}}{{organization_id}}mysoapapp1.0.0'
	--form 'name={{organization_id}}{{organization_id}}mysoapapp1.0.0my soap app'
	--form 'classifier={{organization_id}}{{organization_id}}mysoapapp1.0.0my soap appwsdl'
	--form 'apiVersion={{organization_id}}{{organization_id}}mysoapapp1.0.0my soap appwsdlv1'
	--form 'asset=@"/path/to/file"'
https://domain.com/exchange/api/v1/assets

Postman Collection Item JSON

{
  "name": "Publish new asset on exchange",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Authorization",
        "value": "Bearer {{token}}",
        "type": "text"
      }
    ],
    "body": {
      "mode": "formdata",
      "formdata": [
        {
          "key": "organizationId",
          "value": "{{organization_id}}",
          "type": "text"
        },
        {
          "key": "groupId",
          "value": "{{organization_id}}",
          "type": "text"
        },
        {
          "key": "assetId",
          "value": "mysoapapp",
          "type": "text"
        },
        {
          "key": "version",
          "value": "1.0.0",
          "type": "text"
        },
        {
          "key": "name",
          "value": "my soap app",
          "type": "text"
        },
        {
          "key": "classifier",
          "value": "wsdl",
          "type": "text"
        },
        {
          "key": "apiVersion",
          "value": "v1",
          "type": "text"
        },
        {
          "key": "asset",
          "type": "file",
          "src": "/C:/Users/khanamir/Downloads/tshirts.demos.mulesoft.com.wsdl"
        }
      ]
    },
    "url": {
      "raw": "{{url}}/exchange/api/v1/assets",
      "host": [
        "{{url}}"
      ],
      "path": [
        "exchange",
        "api",
        "v1",
        "assets"
      ]
    }
  },
  "response": [
  ]
}