Chilkat Online Tools

Node.js / Anypoint Platform APIs / Publish new asset on exchange

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;

    var req = new chilkat.HttpRequest();
    req.HttpVerb = "POST";
    req.Path = "/exchange/api/v1/assets";
    req.ContentType = "multipart/form-data";

    var jsonFormData1 = new chilkat.JsonObject();
    req.AddParam("organizationId",jsonFormData1.Emit());

    var jsonFormData2 = new chilkat.JsonObject();
    req.AddParam("groupId",jsonFormData2.Emit());

    req.AddParam("assetId","{{organization_id}}{{organization_id}}mysoapapp");

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

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

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

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

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

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

    // resp: HttpResponse
    var resp = http.SynchronousRequest("domain.com",443,true,req);
    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}}"
	--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": [
  ]
}