Overview
Learn how to use Argyle's webhooks.
Webhooks let you stay up-to-date with any new data added, updated, or deleted in real-time. For example, when the user connects a new payroll account, Argyle will immediately call an HTTP
endpoint on your system to let you know about the event.
You can find the full list of webhook events in this Webhooks reference.
Argyle webhooks are delivered from four static IP addresses:
34.27.251.226
34.122.50.253
35.188.163.115
35.226.53.251
Subscribing to webhooks#
Using the API#
The webhook events you subscribe to are delivered for all accounts. Each time a new account is connected or an existing one is updated, a corresponding webhook will notify your system.
- You can subscribe to webhooks by sending a POST request to Argyle's webhooks endpoint with the event name you want to subscribe to. This Webhooks reference contains the list of examples for all webhook subscription calls.
- To subscribe to all webhooks, use an asterisk for events:
"events": "*"
.
Subscribing to the activities.fully_synced
webhook:
1curl -X POST https://api-sandbox.argyle.com/v1/webhooks \ 2 -u api_key_id:api_key_secret \ 3 -H "Content-Type: application/json" \ 4 -d '{ 5 "events": ["activities.fully_synced"], \ 6 "secret": "<secret for signature verification>", \ 7 "name": "name-of-the-webhook", \ 8 "url": "https://mybackend.com/callback/argyle" 9 }'
While optional, we suggest choosing a random value for the secret
parameter when subscribing to webhooks. You will use this value during signature validation to determine the authenticity of the webhook.
- For example, if you subscribe to the
activities.fully_synced
webhook, every time all activities have finished syncing during the initial scan, the specified url will be invoked with the JSON payload specific to that event.
Example payload for activities.fully_synced
:
1{
2 "event": "activities.fully_synced",
3 "name": "Fully synced",
4 "data": {
5 "account": "12db5af4-fd5f-4d1f-bd98-0360df770aa8",
6 "user": "abdb5af4-fd5f-4d1f-bd10-0360df77012c",
7 "available_from": "2017-07-15T00:00:00",
8 "available_to": "2019-10-01T15:47:00",
9 "available_count": 324
10 }
11}
Using Console#
Visit the Webhooks tab in the Developers section of Console to view and manage your existing webhook subscriptions as well as create new ones.
Signature validation#
When you subscribe to a webhook, you may choose to include a secret
to ensure the authenticity of the webhooks you receive. If you do, each webhook you receive will include a signature in the header that you can use to verify that the webhook is genuine.
To verify the authenticity of a webhook, directly encode the received payload body without any added adjustments by using HMAC-SHA512
with the secret
that you provided when subscribing to the webhook as the secret key. If the encoded payload matches the signature in the header, you can be confident that the webhook and its payload are genuine.
Signature example#
For example, if your secret
was my little secret
, you would expect the following signature:
1'X-Argyle-Signature': '13b68c651cdf714d8d00e88d3c9997d2ea2cb6ffcc57ba2d9164af5898169124e75505f354ded4350c96b03b2cddf01cbe71bc26cb2dc656a69ef670bcda0f86'
For the following body:
1{"name": "Account added", "event": "accounts.added"}
Verification example in Node#
1const http = require('http');
2const crypto = require('crypto');
3
4const serverPort = 80
5const requestListener = function (req, res) {
6 // the client secret is being configured when a webhook is created
7 const client_secret = 'my little secret';
8 var requestBody = '';
9 req.on('readable', () => {
10 var read = req.read()
11 if (read != null) {
12 requestBody += read;
13 }
14 });
15 req.on('end', () => {
16 signature = crypto.createHmac('sha512', client_secret).update(requestBody).digest('hex');
17 console.log('Signature:' + signature);
18 res.writeHead(200);
19 res.end(signature);
20 })
21}
22const server = http.createServer(requestListener);
23server.listen(serverPort);
Verifying webhook authenticity via IP address is not recommended and should only be used as a fallback method, given the addresses may change in the future.
Account connection status#
If an account becomes disconnected, some events will not trigger their associated webhook until the account connection is re-established.
- Check the account object's
connection.status
attribute to see if an account is connected. - You can also subscribe to the
accounts.updated
webhook to be notified when an account becomes disconnected, as the account object'sconnection.status
changing fromconnected
toerror
triggers theaccounts.updated
webhook.When subscribing to the
accounts.updated
webhook, settinginclude_resource
totrue
allows you to view the account object directly in the webhook payload.
Example: Keeping activities synced between your server and Argyle's API#
Webhooks can help you to keep all activity data downloaded on your servers and synced with the Argyle API:
-
Subscribe to
activities.fully_synced
to get notified when the initial account sync of all historical data is finished. Whenever the webhook is invoked, query the activities from the API with the following query:/activities?from_start_date=available_from&account=account_id&to_start_date=available_to
whereaccount
is the account ID, andavailable_from
andavailable_to
are timestamps from the webhook payload. -
Subscribe to
activities.added
to get notified when new activities are added after the initial sync. Argyle scans all accounts periodically for new activities and other changes in data. Use the same API call, but withadded_from
andadded_to
timestamps from the webhook payload. -
Subscribe to
activities.updated
to get notified when existing activities change. An example of this would be when additional information about a completed activity is passed along at a later time (e.g. tips for a completed delivery or ride). The webhook payload provides the date range that was updated (updated_from
andupdated_to
) along with an array of activity IDs that were updated (updated_activities
) to make syncing of the data more convenient. -
Subscribe to
activities.removed
to get notified when activities are removed by a payroll provider. This webhook is an indication to make sure that the activities are removed from your database to avoid duplicate data for a specific account. The webhook payload provides the date range when activities were removed (removed_from
andremoved_to
), the number of activities that were removed (removed_count
), along with an array of activity IDs that were removed (removed_activities
).