xref: /expo/docs/pages/eas/webhooks.mdx (revision c615fa2e)
1---
2title: Webhooks
3description: Learn how to configure webhooks to get alerts on EAS Build and EAS submit completion.
4---
5
6import { ConfigClassic } from '~/components/plugins/ConfigSection';
7import { Collapsible } from '~/ui/components/Collapsible';
8
9EAS can alert you as soon as your build or submission has completed via a webhook. Webhooks need to be configured per-project, so if you want to be alerted for both `@johndoe/awesomeApp` and `@johndoe/coolApp`, you need to run `eas webhook:create` in each directory.
10
11<ConfigClassic>
12
13Webhooks function almost exactly the same for both EAS Build and the classic `expo build` system, _except_ that for `expo build` webhooks, you'll use `expo-cli` to interact with them, and **not** `eas-cli`. For `expo build` webhooks, you'll use:
14
15- `expo webhooks [path]`: List all webhooks for a project
16- `expo webhooks:add [path]`: Add a webhook to a project
17- `expo webhooks:remove [path]`: Delete a webhook
18- `expo webhooks:update [path]`: Update an existing webhook
19
20</ConfigClassic>
21
22After running `eas webhook:create`, you'll be prompted to choose the webhook event type (unless you provide the `--event BUILD|SUBMIT` parameter). Next, provide the webhook URL (or specify it with the `--url` flag) that handles HTTP POST requests. Additionally, you'll have to input a webhook signing secret, if you have not already provided it with the `--secret` flag. It must be at least 16 characters long, and it will be used to calculate the signature of the request body which we send as the value of the `expo-signature` HTTP header. You can use the signature to verify a webhook request is genuine (example code below).
23
24EAS calls your webhook using an HTTP POST request. All the data is passed in the request body. EAS sends the data as a JSON object.
25
26Additionally, we send an `expo-signature` HTTP header with the hash signature of the payload. You can use this signature to verify the authenticity of the request. The signature is a hex-encoded HMAC-SHA1 digest of the request body, using your webhook secret as the HMAC key.
27
28> If you want to test the above webhook locally, you have to use a service like [ngrok](https://ngrok.com/docs) to forward `localhost:8080` via a tunnel and make it publicly accessible with the URL `ngrok` gives you.
29
30You can always change your webhook URL and/or webhook secret using `eas webhook:update --id WEBHOOK_ID`. You can find the webhook ID by running `eas webhook:list`. If you would like us to stop sending requests to your webhook, run `eas webhook:delete` and choose the webhook from the list.
31
32## Webhook payload
33
34<Collapsible summary="Build webhook payload">
35
36The build webhook payload looks something like this:
37
38```json
39{
40  "id": "147a3212-49fd-446f-b4e3-a6519acf264a",
41  "accountName": "dsokal",
42  "projectName": "example",
43  "buildDetailsPageUrl": "https://expo.dev/accounts/dsokal/projects/example/builds/147a3212-49fd-446f-b4e3-a6519acf264a",
44  "parentBuildId": "75ac0be7-0d90-46d5-80ec-9423fa0aaa6b", // available for build retries
45  "appId": "bc0a82de-65a5-4497-ad86-54ff1f53edf7",
46  "initiatingUserId": "d1041496-1a59-423a-8caf-479bb978203a",
47  "cancelingUserId": null, // available for canceled builds
48  "platform": "android", // or "ios"
49  "status": "errored", // or: "finished", "canceled"
50  "artifacts": {
51    "buildUrl": "https://expo.dev/artifacts/eas/wyodu9tua2ZuKKiaJ1Nbkn.aab", // available for successful builds
52    "logsS3KeyPrefix": "production/f9609423-5072-4ea2-a0a5-c345eedf2c2a"
53  },
54  "metadata": {
55    "appName": "example",
56    "username": "dsokal",
57    "workflow": "managed",
58    "appVersion": "1.0.2",
59    "appBuildVersion": "123",
60    "cliVersion": "0.37.0",
61    "sdkVersion": "41.0.0",
62    "buildProfile": "production",
63    "distribution": "store",
64    "appIdentifier": "com.expo.example",
65    "gitCommitHash": "564b61ebdd403d28b5dc616a12ce160b91585b5b",
66    "gitCommitMessage": "Add home screen",
67    "runtimeVersion": "1.0.2",
68    "channel": "default", // available for EAS Update
69    "releaseChannel": "default", // available for legacy updates
70    "reactNativeVersion": "0.60.0",
71    "appBuildVersion": "6",
72    "trackingContext": {
73      "platform": "android",
74      "account_id": "7c34cbf1-efd4-4964-84a1-c13ed297aaf9",
75      "dev_client": false,
76      "project_id": "bc0a82de-65a5-4497-ad86-54ff1f53edf7",
77      "tracking_id": "a3fdefa7-d129-42f2-9432-912050ab0f10",
78      "project_type": "managed",
79      "dev_client_version": "0.6.2"
80    },
81    "credentialsSource": "remote",
82    "isGitWorkingTreeDirty": false,
83    "message": "release build", // message attached to the build
84    "runFromCI": false
85  },
86  "metrics": {
87    "memory": 895070208,
88    "buildEndTimestamp": 1637747861168,
89    "totalDiskReadBytes": 692224,
90    "buildStartTimestamp": 1637747834445,
91    "totalDiskWriteBytes": 14409728,
92    "cpuActiveMilliseconds": 12117.540078,
93    "buildEnqueuedTimestamp": 1637747792476,
94    "totalNetworkEgressBytes": 355352,
95    "totalNetworkIngressBytes": 78781667
96  },
97  // available for failed builds
98  "error": {
99    "message": "Unknown error. Please see logs.",
100    "errorCode": "UNKNOWN_ERROR"
101  },
102  "createdAt": "2021-11-24T09:53:01.155Z",
103  "enqueuedAt": "2021-11-24T09:53:01.155Z",
104  "provisioningStartedAt": "2021-11-24T09:54:01.155Z",
105  "workerStartedAt": "2021-11-24T09:54:11.155Z",
106  "completedAt": "2021-11-24T09:57:42.715Z",
107  "updatedAt": "2021-11-24T09:57:42.715Z",
108  "expirationDate": "2021-12-24T09:53:01.155Z",
109  "priority": "high", // or: "normal", "low"
110  "resourceClass": "android-n2-1.3-12",
111  "actualResourceClass": "android-n2-1.3-12",
112  "maxRetryTimeMinutes": 3600 // max retry time for failed/canceled builds
113}
114```
115
116</Collapsible>
117
118<Collapsible summary="Submit webhook payload">
119
120The submit webhook payload looks something like this:
121
122```json
123{
124  "id": "0374430d-7776-44ad-be7d-8513629adc54",
125  "accountName": "dsokal",
126  "projectName": "example",
127  "submissionDetailsPageUrl": "https://expo.dev/accounts/dsokal/projects/example/builds/0374430d-7776-44ad-be7d-8513629adc54",
128  "parentSubmissionId": "75ac0be7-0d90-46d5-80ec-9423fa0aaa6b", // available for submission retries
129  "appId": "23c0e405-d282-4399-b280-5689c3e1ea85",
130  "archiveUrl": "http://archive.url/abc.apk",
131  "initiatingUserId": "7bee4c21-3eaa-4011-a0fd-3678b6537f47",
132  "cancelingUserId": null, // available for canceled submissions
133  "turtleBuildId": "8c84111e-6d39-449c-9895-071d85fd3e61", // available when submitting a build from EAS
134  "platform": "android", // or "ios"
135  "status": "errored", // or: "finished", "canceled"
136  "submissionInfo": {
137    // available for failed submissions
138    "error": {
139      "message": "Android version code needs to be updated",
140      "errorCode": "SUBMISSION_SERVICE_ANDROID_OLD_VERSION_CODE_ERROR"
141    },
142    "logsUrl": "https://submission-service-logs.s3-us-west-1.amazonaws.com/production/submission_728aa20b-f7a9-4da7-9b64-39911d427b19.txt"
143  },
144  "createdAt": "2021-11-24T10:15:32.822Z",
145  "updatedAt": "2021-11-24T10:17:32.822Z",
146  "completedAt": "2021-11-24T10:17:32.822Z",
147  "maxRetryTimeMinutes": 3600 // max retry time for failed/canceled submissions
148}
149```
150
151</Collapsible>
152
153## Webhook server
154
155Here's an example of how you can implement your server:
156
157```javascript
158const crypto = require('crypto');
159const express = require('express');
160const bodyParser = require('body-parser');
161const safeCompare = require('safe-compare');
162
163const app = express();
164app.use(bodyParser.text({ type: '*/*' }));
165app.post('/webhook', (req, res) => {
166  const expoSignature = req.headers['expo-signature'];
167  // process.env.SECRET_WEBHOOK_KEY has to match SECRET value set with `eas webhook:create` command
168  const hmac = crypto.createHmac('sha1', process.env.SECRET_WEBHOOK_KEY);
169  hmac.update(req.body);
170  const hash = `sha1=${hmac.digest('hex')}`;
171  if (!safeCompare(expoSignature, hash)) {
172    res.status(500).send("Signatures didn't match!");
173  } else {
174    // do something here, like send a notification to Slack!
175    // console.log(req.body);
176    res.send('OK!');
177  }
178});
179app.listen(8080, () => console.log('Listening on port 8080'));
180```
181