Chilkat Online Tools

PowerBuilder / Anypoint Platform APIs / Publish new asset on exchange

Back to Collection Items

integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_Req
oleobject loo_JsonFormData1
oleobject loo_JsonFormData2
oleobject loo_Resp

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

loo_Http = create oleobject
// Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

loo_Req = create oleobject
// Use "Chilkat_9_5_0.HttpRequest" for versions of Chilkat < 10.0.0
li_rc = loo_Req.ConnectToNewObject("Chilkat.HttpRequest")

loo_Req.HttpVerb = "POST"
loo_Req.Path = "/exchange/api/v1/assets"
loo_Req.ContentType = "multipart/form-data"

loo_JsonFormData1 = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_JsonFormData1.ConnectToNewObject("Chilkat.JsonObject")

loo_Req.AddStringForUpload2("organizationId","",loo_JsonFormData1,"utf-8","application/json")

loo_JsonFormData2 = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_JsonFormData2.ConnectToNewObject("Chilkat.JsonObject")

loo_Req.AddStringForUpload2("groupId","",loo_JsonFormData2,"utf-8","application/json")

loo_Req.AddParam("assetId","{{organization_id}}{{organization_id}}mysoapapp")

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

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

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

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

li_Success = loo_Req.AddFileForUpload2("asset"," path to file","application/octet-stream")

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

loo_Resp = loo_Http.SynchronousRequest("domain.com",443,1,loo_Req)
if loo_Http.LastMethodSuccess = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_Req
    destroy loo_JsonFormData1
    destroy loo_JsonFormData2
    return
end if

Write-Debug string(loo_Resp.StatusCode)
Write-Debug loo_Resp.BodyStr
destroy loo_Resp


destroy loo_Http
destroy loo_Req
destroy loo_JsonFormData1
destroy loo_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": [
  ]
}