Chilkat Online Tools

Swift3 / Anypoint Platform APIs / Publish new asset on exchange

Back to Collection Items

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

    let http = CkoHttp()!
    var success: Bool

    let req = CkoHttpRequest()!
    req.httpVerb = "POST"
    req.path = "/exchange/api/v1/assets"
    req.contentType = "multipart/form-data"

    let jsonFormData1 = CkoJsonObject()!
    req.addString(forUpload2: "organizationId", filename: "", strData: jsonFormData1, charset: "utf-8", contentType: "application/json")

    let jsonFormData2 = CkoJsonObject()!
    req.addString(forUpload2: "groupId", filename: "", strData: jsonFormData2, charset: "utf-8", contentType: "application/json")

    req.addParam("assetId", value: "{{organization_id}}{{organization_id}}mysoapapp")

    req.addParam("version", value: "{{organization_id}}{{organization_id}}mysoapapp1.0.0")

    req.addParam("{{organization_id}}{{organization_id}}mysoapapp1.0.0my soap app", value: "")

    req.addParam("classifier", value: "{{organization_id}}{{organization_id}}mysoapapp1.0.0my soap appwsdl")

    req.addParam("apiVersion", value: "{{organization_id}}{{organization_id}}mysoapapp1.0.0my soap appwsdlv1")

    success = req.addFile(forUpload2: "asset", path: " path to file", contentType: "application/octet-stream")

    req.addHeader("Authorization", value: "Bearer {{token}}")
    req.addHeader("Expect", value: "100-continue")

    var resp: CkoHttpResponse? = http.synchronousRequest("domain.com", port: 443, ssl: true, req: req)
    if http.lastMethodSuccess == false {
        print("\(http.lastErrorText!)")
        return
    }

    print("\(resp!.statusCode.intValue)")
    print("\(resp!.bodyStr!)")
    resp = nil

}

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": [
  ]
}