Chilkat Online Tools

Swift / Bond APIs / create webhook

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.

    // {
    //   "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": ""
    // }

    let json = CkoJsonObject()
    json.UpdateString("events[0]", value: "account.history.ready")
    json.UpdateString("events[1]", value: "card.created")
    json.UpdateString("events[2]", value: "card.status.active")
    json.UpdateString("events[3]", value: "card.status.closed")
    json.UpdateString("events[4]", value: "card.status.fraud")
    json.UpdateString("events[5]", value: "card.status.inactive")
    json.UpdateString("events[6]", value: "card.status.lost")
    json.UpdateString("events[7]", value: "card.status.reissue")
    json.UpdateString("events[8]", value: "card.status.stolen")
    json.UpdateString("events[9]", value: "card.wallet.add")
    json.UpdateString("events[10]", value: "card.wallet.add_failure")
    json.UpdateString("events[11]", value: "kyb.verification.approved")
    json.UpdateString("events[12]", value: "kyb.verification.error")
    json.UpdateString("events[13]", value: "kyb.verification.initiated")
    json.UpdateString("events[14]", value: "kyb.verification.rejected")
    json.UpdateString("events[15]", value: "kyb.verification.warning")
    json.UpdateString("events[16]", value: "kyc.verification.document_required")
    json.UpdateString("events[17]", value: "kyc.verification.error")
    json.UpdateString("events[18]", value: "kyc.verification.failure")
    json.UpdateString("events[19]", value: "kyc.verification.kba")
    json.UpdateString("events[20]", value: "kyc.verification.success")
    json.UpdateString("events[21]", value: "kyc.verification.timeout")
    json.UpdateString("events[22]", value: "kyc.verification.under_review")
    json.UpdateString("events[23]", value: "transactions")
    json.UpdateString("callback_url", value: "")
    json.UpdateString("description", value: "")

    http.SetRequestHeader("Identity", value: "{{identity}}")
    http.SetRequestHeader("Authorization", value: "{{authorization}}")

    var resp: CkoHttpResponse? = http.PostJson3("https://{{environment}}.bond.tech/api/v0/webhooks", 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 "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}"
    }
  ]
}