Chilkat Online Tools

Swift3 / EPC 2.0 - Partner Sandbox - 19.4 November [External] / [Partner] Create a New Product

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

    // Use this online tool to generate code from sample JSON: Generate Code to Create JSON

    // The following JSON is sent in the request body.

    // {
    //   "partnerId": "{{partner_id}}",
    //   "name": "{{product_name}}",
    //   "listingName": "{{product_listing_name}}",
    //   "tags": {
    //     "applications": [
    //       "LO Connect",
    //       "Encompass Smart Client"
    //     ],
    //     "categories": [
    //       "{{service_category}}"
    //     ],
    //     "workflows": [
    //       "interactive"
    //     ]
    //   },
    //   "integrationType": "ASYNC",
    //   "interfaceUrl": "{{product_interface_url}}",
    //   "webhooks": [
    //     {
    //       "resource": "urn:elli:epc:transaction",
    //       "events": [
    //         "created",
    //         "updated"
    //       ],
    //       "signingkey": "qwertyuiop1234567890!@#$f*()",
    //       "url": "{{webhook_url}}"
    //     },
    //     {
    //       "resource": "urn:elli:epc:transaction:event",
    //       "events": [
    //         "created"
    //       ],
    //       "signingkey": "qwertyuiop1234567890!@#$f*()",
    //       "url": "{{webhook_url}}"
    //     }
    //   ],
    //   "requestTypes": [
    //     "{{request_type}}"
    //   ],
    //   "entitlements": {
    //     "access": {
    //       "allow": [
    //         "urn:elli:encompass:{{encompass_instance_id}}"
    //       ],
    //       "deny": [
    //       ]
    //     }
    //   },
    //   "credential": {
    //     "required": [
    //       "username",
    //       "password"
    //     ],
    //     "properties": {
    //       "username": {
    //         "type": "String",
    //         "title": "Username"
    //       },
    //       "password": {
    //         "type": "String",
    //         "title": "Password",
    //         "secret": true
    //       }
    //     }
    //   }
    // }

    let json = CkoJsonObject()!
    json.update("partnerId", value: "{{partner_id}}")
    json.update("name", value: "{{product_name}}")
    json.update("listingName", value: "{{product_listing_name}}")
    json.update("tags.applications[0]", value: "LO Connect")
    json.update("tags.applications[1]", value: "Encompass Smart Client")
    json.update("tags.categories[0]", value: "{{service_category}}")
    json.update("tags.workflows[0]", value: "interactive")
    json.update("integrationType", value: "ASYNC")
    json.update("interfaceUrl", value: "{{product_interface_url}}")
    json.update("webhooks[0].resource", value: "urn:elli:epc:transaction")
    json.update("webhooks[0].events[0]", value: "created")
    json.update("webhooks[0].events[1]", value: "updated")
    json.update("webhooks[0].signingkey", value: "qwertyuiop1234567890!@#$f*()")
    json.update("webhooks[0].url", value: "{{webhook_url}}")
    json.update("webhooks[1].resource", value: "urn:elli:epc:transaction:event")
    json.update("webhooks[1].events[0]", value: "created")
    json.update("webhooks[1].signingkey", value: "qwertyuiop1234567890!@#$f*()")
    json.update("webhooks[1].url", value: "{{webhook_url}}")
    json.update("requestTypes[0]", value: "{{request_type}}")
    json.update("entitlements.access.allow[0]", value: "urn:elli:encompass:{{encompass_instance_id}}")
    json.updateNewArray("entitlements.access.deny")
    json.update("credential.required[0]", value: "username")
    json.update("credential.required[1]", value: "password")
    json.update("credential.properties.username.type", value: "String")
    json.update("credential.properties.username.title", value: "Username")
    json.update("credential.properties.password.type", value: "String")
    json.update("credential.properties.password.title", value: "Password")
    json.updateBool("credential.properties.password.secret", value: true)

    // Adds the "Authorization: Bearer {{partner_token}}" header.
    http.authToken = "{{partner_token}}"
    http.setRequestHeader("Content-Type", value: "application/json")

    var resp: CkoHttpResponse? = http.postJson3("https://domain.com/partner/v2/products?view=complete", contentType: "application/json", json: json)
    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 {{partner_token}}"
	-H "Content-Type: application/json"
	-d '{
    "partnerId": "{{partner_id}}",
    "name": "{{product_name}}",
    "listingName": "{{product_listing_name}}",
    "tags": {
        "applications": [
            "LO Connect",
            "Encompass Smart Client"
        ],
        "categories": [
            "{{service_category}}"
        ],
        "workflows": [
            "interactive"
        ]
    },
    "integrationType": "ASYNC",
    "interfaceUrl": "{{product_interface_url}}",
    "webhooks": [
        {
            "resource": "urn:elli:epc:transaction",
            "events": [
                "created",
                "updated"
            ],
            "signingkey": "qwertyuiop1234567890!@#$%^&*()",
            "url": "{{webhook_url}}"
        },
        {
            "resource": "urn:elli:epc:transaction:event",
            "events": [
                "created"
            ],
            "signingkey": "qwertyuiop1234567890!@#$%^&*()",
            "url": "{{webhook_url}}"
        }
    ],
    "requestTypes": [
        "{{request_type}}"
    ],
    "entitlements": {
        "access": {
            "allow": [
                "urn:elli:encompass:{{encompass_instance_id}}"
            ],
            "deny": []
        }
    },
    "credential": {
        "required": [
            "username",
            "password"
        ],
        "properties": {
            "username": {
                "type": "String",
                "title": "Username"
            },
            "password": {
                "type": "String",
                "title": "Password",
                "secret": true
            }
        }
    }
}'
https://domain.com/partner/v2/products?view=complete

Postman Collection Item JSON

{
  "name": "[Partner] Create a New Product",
  "event": [
    {
      "listen": "test",
      "script": {
        "type": "text/javascript",
        "exec": [
          "// Extract Product identifier from response body",
          "var jsonData = JSON.parse(responseBody);",
          "var productId = jsonData.id;",
          "",
          "// Set to an environment variable",
          "postman.setEnvironmentVariable(\"product_id\", productId);"
        ]
      }
    }
  ],
  "_postman_id": "677a22b1-31ae-4dde-a759-f6a27216e2d5",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Authorization",
        "type": "text",
        "value": "Bearer {{partner_token}}"
      },
      {
        "key": "Content-Type",
        "name": "Content-Type",
        "value": "application/json",
        "type": "text"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"partnerId\": \"{{partner_id}}\",\n    \"name\": \"{{product_name}}\",\n    \"listingName\": \"{{product_listing_name}}\",\n    \"tags\": {\n        \"applications\": [\n            \"LO Connect\",\n            \"Encompass Smart Client\"\n        ],\n        \"categories\": [\n            \"{{service_category}}\"\n        ],\n        \"workflows\": [\n            \"interactive\"\n        ]\n    },\n    \"integrationType\": \"ASYNC\",\n    \"interfaceUrl\": \"{{product_interface_url}}\",\n    \"webhooks\": [\n        {\n            \"resource\": \"urn:elli:epc:transaction\",\n            \"events\": [\n                \"created\",\n                \"updated\"\n            ],\n            \"signingkey\": \"qwertyuiop1234567890!@#$%^&*()\",\n            \"url\": \"{{webhook_url}}\"\n        },\n        {\n            \"resource\": \"urn:elli:epc:transaction:event\",\n            \"events\": [\n                \"created\"\n            ],\n            \"signingkey\": \"qwertyuiop1234567890!@#$%^&*()\",\n            \"url\": \"{{webhook_url}}\"\n        }\n    ],\n    \"requestTypes\": [\n        \"{{request_type}}\"\n    ],\n    \"entitlements\": {\n        \"access\": {\n            \"allow\": [\n                \"urn:elli:encompass:{{encompass_instance_id}}\"\n            ],\n            \"deny\": []\n        }\n    },\n    \"credential\": {\n        \"required\": [\n            \"username\",\n            \"password\"\n        ],\n        \"properties\": {\n            \"username\": {\n                \"type\": \"String\",\n                \"title\": \"Username\"\n            },\n            \"password\": {\n                \"type\": \"String\",\n                \"title\": \"Password\",\n                \"secret\": true\n            }\n        }\n    }\n}"
    },
    "url": {
      "raw": "{{api_host}}/partner/v2/products?view=complete",
      "host": [
        "{{api_host}}"
      ],
      "path": [
        "partner",
        "v2",
        "products"
      ],
      "query": [
        {
          "key": "view",
          "value": "complete"
        }
      ]
    }
  },
  "response": [
  ]
}