Chilkat Online Tools

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

Back to Collection Items

-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    -- This example assumes the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @http int
    -- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    -- 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
    --       }
    --     }
    --   }
    -- }

    DECLARE @json int
    -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT

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

    -- Adds the "Authorization: Bearer {{partner_token}}" header.
    EXEC sp_OASetProperty @http, 'AuthToken', '{{partner_token}}'
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'application/json'

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://domain.com/partner/v2/products?view=complete', 'application/json', @json
    EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @json
        RETURN
      END

    EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
    PRINT @iTmp0
    EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
    PRINT @sTmp0
    EXEC @hr = sp_OADestroy @resp


    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @json


END
GO

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