Chilkat Online Tools

SQL Server / Bond APIs / create webhook

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.

    -- {
    --   "events": [
    --     "account.history.ready",
    --     "card.created",
    --     "card.status.active",
    --     "card.status.closed",
    --     "card.status.fraud",
    --     "card.status.inactive",
    --     "card.status.lost",
    --     "card.status.reissue",
    --     "card.status.stolen",
    --     "card.wallet.add",
    --     "card.wallet.add_failure",
    --     "kyb.verification.approved",
    --     "kyb.verification.error",
    --     "kyb.verification.initiated",
    --     "kyb.verification.rejected",
    --     "kyb.verification.warning",
    --     "kyc.verification.document_required",
    --     "kyc.verification.error",
    --     "kyc.verification.failure",
    --     "kyc.verification.kba",
    --     "kyc.verification.success",
    --     "kyc.verification.timeout",
    --     "kyc.verification.under_review",
    --     "transactions"
    --   ],
    --   "callback_url": "",
    --   "description": ""
    -- }

    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, 'events[0]', 'account.history.ready'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'events[1]', 'card.created'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'events[2]', 'card.status.active'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'events[3]', 'card.status.closed'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'events[4]', 'card.status.fraud'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'events[5]', 'card.status.inactive'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'events[6]', 'card.status.lost'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'events[7]', 'card.status.reissue'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'events[8]', 'card.status.stolen'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'events[9]', 'card.wallet.add'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'events[10]', 'card.wallet.add_failure'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'events[11]', 'kyb.verification.approved'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'events[12]', 'kyb.verification.error'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'events[13]', 'kyb.verification.initiated'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'events[14]', 'kyb.verification.rejected'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'events[15]', 'kyb.verification.warning'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'events[16]', 'kyc.verification.document_required'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'events[17]', 'kyc.verification.error'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'events[18]', 'kyc.verification.failure'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'events[19]', 'kyc.verification.kba'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'events[20]', 'kyc.verification.success'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'events[21]', 'kyc.verification.timeout'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'events[22]', 'kyc.verification.under_review'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'events[23]', 'transactions'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'callback_url', ''
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'description', ''

    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Identity', '{{identity}}'
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Authorization', '{{authorization}}'

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://{{environment}}.bond.tech/api/v0/webhooks', '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 "Identity: {{identity}}"
	-H "Authorization: {{authorization}}"
	-d '{
    "events": [
        "account.history.ready",
        "card.created",
        "card.status.active",
        "card.status.closed",
        "card.status.fraud",
        "card.status.inactive",
        "card.status.lost",
        "card.status.reissue",
        "card.status.stolen",
        "card.wallet.add",
        "card.wallet.add_failure",
        "kyb.verification.approved",
        "kyb.verification.error",
        "kyb.verification.initiated",
        "kyb.verification.rejected",
        "kyb.verification.warning",
        "kyc.verification.document_required",
        "kyc.verification.error",
        "kyc.verification.failure",
        "kyc.verification.kba",
        "kyc.verification.success",
        "kyc.verification.timeout",
        "kyc.verification.under_review",
        "transactions"

    ],
    "callback_url": "",
    "description": ""
}'
https://{{environment}}.bond.tech/api/v0/webhooks

Postman Collection Item JSON

{
  "name": "create webhook",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Identity",
        "value": "{{identity}}",
        "type": "text"
      },
      {
        "key": "Authorization",
        "value": "{{authorization}}",
        "type": "text"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"events\": [\n        \"account.history.ready\",\n        \"card.created\",\n        \"card.status.active\",\n        \"card.status.closed\",\n        \"card.status.fraud\",\n        \"card.status.inactive\",\n        \"card.status.lost\",\n        \"card.status.reissue\",\n        \"card.status.stolen\",\n        \"card.wallet.add\",\n        \"card.wallet.add_failure\",\n        \"kyb.verification.approved\",\n        \"kyb.verification.error\",\n        \"kyb.verification.initiated\",\n        \"kyb.verification.rejected\",\n        \"kyb.verification.warning\",\n        \"kyc.verification.document_required\",\n        \"kyc.verification.error\",\n        \"kyc.verification.failure\",\n        \"kyc.verification.kba\",\n        \"kyc.verification.success\",\n        \"kyc.verification.timeout\",\n        \"kyc.verification.under_review\",\n        \"transactions\"\n\n    ],\n    \"callback_url\": \"\",\n    \"description\": \"\"\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "https://{{environment}}.bond.tech/api/v0/webhooks",
      "protocol": "https",
      "host": [
        "{{environment}}",
        "bond",
        "tech"
      ],
      "path": [
        "api",
        "v0",
        "webhooks"
      ]
    }
  },
  "response": [
    {
      "name": "create webhook example",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "key": "Identity",
            "value": "{{identity}}",
            "type": "text"
          },
          {
            "key": "Authorization",
            "value": "{{authorization}}",
            "type": "text"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"events\": [\n        \"kyc.verification.success\",\n        \"kyc.verification.failure\",\n        \"kyc.verification.error\",\n        \"kyc.verification.timeout\",\n        \"kyc.verification.kba\"\n    ],\n    \"callback_url\": \"http://bond.tech\",\n    \"description\": \"Event listener NA\"\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "https://{{environment}}.bond.tech/api/v0/webhooks",
          "protocol": "https",
          "host": [
            "{{environment}}",
            "bond",
            "tech"
          ],
          "path": [
            "api",
            "v0",
            "webhooks"
          ]
        }
      },
      "_postman_previewlanguage": "json",
      "header": null,
      "cookie": [
      ],
      "body": "{\n  \"date_created\": \"2020-11-17T11:13:06.568119\",\n  \"webhook_id\": \"522e9ec7-b17d-4d92-8270-c2e1741dd6e0\",\n  \"callback_url\": \"https://hostname.com/webhook/route\",\n  \"description\": \"KYC state changes.\",\n  \"events\": [\n    \"kyc.verification.success\",\n    \"kyc.verification.failure\",\n    \"kyc.verification.kba\",\n    \"kyc.verification.error\",\n    \"kyc.verification.timeout\"\n  ],\n  \"status\": \"enabled\",\n  \"secret\": \"whsec_XqTEJtniwuEhp0A1c1cTJNsmpR/qgOfB\"\n}"
    }
  ]
}