Skip to content

Commit 9093d04

Browse files
committed
Added webhooks chapter.
1 parent c8a9b6a commit 9093d04

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

api/api/client.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,51 @@ Client errors include a unique code number, error message and original thrown er
8484
}
8585
```
8686

87+
## Webhooks
88+
89+
Client uses webhooks for event notifications. Webhooks are HTTP callbacks that receive notification messages for occurred events. You can set up your account's webhook and subscribe to different events with function [updateAccountWebhook(url, events)](client.html#updateaccountwebhook-url-events). Webhooks will be sent to your chosen URL with a HTTP method `POST`, so your webhook handler should be configured properly.
90+
91+
### Events
92+
93+
Webhook events are triggered when either Order request, Approve request or Deployment request is changed. Client supports six different kind of events based on changes in Order / Deployment / Approve requests.
94+
95+
| Event kind | Description
96+
|-|-
97+
| 0 | Order request changed - Event triggers when Order object changes during processing.
98+
| 1 | Order request error - Event triggers when an error occurs during processing of the Order.
99+
| 2 | Deployment request changed - Event triggers when Deployment object changes during processing.
100+
| 3 | Deployment request error - Event triggers when an error occurs during processing of the Deployment.
101+
| 4 | Approve request changed - Event triggers when Approve request object changes during processing.
102+
| 5 | Approve request error - Event triggers when an error occurs during processing of the Approve request.
103+
104+
### Webhook response body
105+
106+
Webhook response body includes three important parameters:
107+
108+
| Parameter | Description
109+
|-|-
110+
| requestRef | A `string` representing either Order request, Approve request or Deployment request reference.
111+
| requestKind | A `integer` representing the kind of the request on which errors or changes occurred. Can be one of the [Request kinds](client.html#request-kinds).
112+
| kind | A `integer` representing the kind of the event that occurred. Event kinds can be found in previous chapter [Events](client.html#events).
113+
114+
##### Request kinds
115+
116+
| Number | Description
117+
|-|-
118+
| 0 | Order request.
119+
| 1 | Deployment request.
120+
| 2 | Approve request.
121+
122+
With these parameters we can determine which of our requests was changed. Based on the `requestKind` we can decide which function should we use for obtaining our changed request. We provide `requestRef` from received webhook, to our getter function.
123+
124+
| Request kind | Function for obtaining request object
125+
|-|-
126+
| 0 | [getOrder(requestRef)](client.html#getorder-orderref).
127+
| 1 | [getDeployment(requestRef)](client.html#getdeployment-deploymentref).
128+
| 2 | [getApproval(requestRef)](client.html#getapproval-approvalref).
129+
130+
We can also decide which function should we use for obtaining our changed request with event `kind` parameter.
131+
87132
## Client(options)
88133

89134
A class providing communication with the 0xcert API.
@@ -192,6 +237,8 @@ const accountWebhook = await client.getAccountWebhook();
192237
| 400001 | Provided signature is not valid.
193238
| 400014 | Account is not identified. Before you start using API on Ethereum mainnet you must provide information about yourself using update account route.
194239

240+
You can learn more about webhooks in chapter [Webhooks](client.html#webhooks).
241+
195242
## updateAccountWebhook(url, events)
196243

197244
An `asynchronous` class instance `function` which updates currently authenticated account's webhook data.
@@ -211,6 +258,8 @@ An `asynchronous` class instance `function` which updates currently authenticate
211258
| 1 | Order request error.
212259
| 2 | Deployment request changed.
213260
| 3 | Deployment request error.
261+
| 4 | Approve request changed.
262+
| 5 | Approve request error.
214263

215264
**Result:**
216265

@@ -235,6 +284,8 @@ const accountWebhook = await client.updateAccountWebhook('https://api.0xcert.org
235284
| 422067 | Webhook validation failed because `url` is not present.
236285
| 422114 | Webhook validation failed because `url` is not valid.
237286

287+
You can learn more about webhooks in chapter [Webhooks](client.html#webhooks).
288+
238289
## updateAccountInformation(accountInformation)
239290

240291
An `asynchronous` class instance `function` which updates currently authenticated account's information.

0 commit comments

Comments
 (0)