Chilkat Online Tools

unicodeC / Anypoint Platform APIs / Publish new asset on exchange

Back to Collection Items

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

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkHttpRequestW req;
    HCkJsonObjectW jsonFormData1;
    HCkJsonObjectW jsonFormData2;
    HCkHttpResponseW resp;

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

    http = CkHttpW_Create();

    req = CkHttpRequestW_Create();
    CkHttpRequestW_putHttpVerb(req,L"POST");
    CkHttpRequestW_putPath(req,L"/exchange/api/v1/assets");
    CkHttpRequestW_putContentType(req,L"multipart/form-data");

    jsonFormData1 = CkJsonObjectW_Create();
    CkHttpRequestW_AddStringForUpload2(req,L"organizationId",L"",jsonFormData1,L"utf-8",L"application/json");

    jsonFormData2 = CkJsonObjectW_Create();
    CkHttpRequestW_AddStringForUpload2(req,L"groupId",L"",jsonFormData2,L"utf-8",L"application/json");

    CkHttpRequestW_AddParam(req,L"assetId",L"{{organization_id}}{{organization_id}}mysoapapp");

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

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

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

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

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

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

    resp = CkHttpW_SynchronousRequest(http,L"domain.com",443,TRUE,req);
    if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkHttpRequestW_Dispose(req);
        CkJsonObjectW_Dispose(jsonFormData1);
        CkJsonObjectW_Dispose(jsonFormData2);
        return;
    }

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


    CkHttpW_Dispose(http);
    CkHttpRequestW_Dispose(req);
    CkJsonObjectW_Dispose(jsonFormData1);
    CkJsonObjectW_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": [
  ]
}