Chilkat Online Tools

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

Back to Collection Items

IncludeFile "CkJsonObject.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkHttpResponse.pb"

Procedure ChilkatExample()

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

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

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

    json.i = CkJsonObject::ckCreate()
    If json.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

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

    ; Adds the "Authorization: Bearer {{partner_token}}" header.
    CkHttp::setCkAuthToken(http, "{{partner_token}}")
    CkHttp::ckSetRequestHeader(http,"Content-Type","application/json")

    resp.i = CkHttp::ckPostJson3(http,"https://domain.com/partner/v2/products?view=complete","application/json",json)
    If CkHttp::ckLastMethodSuccess(http) = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(json)
        ProcedureReturn
    EndIf

    Debug Str(CkHttpResponse::ckStatusCode(resp))
    Debug CkHttpResponse::ckBodyStr(resp)
    CkHttpResponse::ckDispose(resp)



    CkHttp::ckDispose(http)
    CkJsonObject::ckDispose(json)


    ProcedureReturn
EndProcedure

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