# Get webhook events from Apple at your server

> Have an Agent set up an App Store Connect webhook so Apple tells your server when a build, a version or TestFlight feedback changes, send a test ping, read the deliveries and resend one your server missed.

Source: https://air.build/docs/app-store/get-webhook-events-from-apple/

A webhook makes App Store Connect call your own server when something happens to your app: a build upload's state changes, a version's state changes, a tester sends feedback. Apple sends each event to an address you choose, and your server decides what to do with it.

> [!NOTE]
> AirBuild has no screen for webhooks. You ask an Agent in the Project's chat, and it uses `asc webhooks` (listed in [asc: automation](https://air.build/docs/cli/asc-automation/#webhooks)). To look at them yourself, use App Store Connect on the web: Apple's [Manage webhooks](https://developer.apple.com/help/app-store-connect/manage-your-team/manage-webhooks) help says they're under Users and Access, then Integrations, then Webhooks.

You don't need a webhook to follow your app in AirBuild: AirBuild already notifies you when Apple changes a version's review state. See [Submit to App Review and release](https://air.build/docs/app-store/submit-for-review/#follow-the-review).

## Before you start

- A server you control, at a public address, ready to take the events. This page doesn't cover building it: Apple's [Configuring and parsing App Store Connect API webhook notifications](https://developer.apple.com/documentation/appstoreconnectapi/configuring-webhook-notifications) explains what Apple sends.
- A secret: a phrase you choose, that your server also knows. Apple's help says your server uses it to check that a delivery really comes from App Store Connect.
- Your app's App Store Connect record. A webhook is for one app. See [Create your app's App Store Connect record](https://air.build/docs/app-store/create-your-app-record/).

## Choose the events

A webhook sends only the event types you pick. `asc` accepts these:

| Event type | When Apple sends it |
| --- | --- |
| `BUILD_UPLOAD_STATE_UPDATED` | A build upload's state changes. |
| `BUILD_BETA_DETAIL_EXTERNAL_BUILD_STATE_UPDATED` | A build's state for external TestFlight testers changes. |
| `APP_STORE_VERSION_APP_VERSION_STATE_UPDATED` | An App Store version's state changes. |
| `BETA_FEEDBACK_SCREENSHOT_SUBMISSION_CREATED` | A tester sends TestFlight feedback with a screenshot. |
| `BETA_FEEDBACK_CRASH_SUBMISSION_CREATED` | A tester sends a crash report from TestFlight. |
| `BACKGROUND_ASSET_VERSION_STATE_UPDATED`, `BACKGROUND_ASSET_VERSION_INTERNAL_BETA_RELEASE_CREATED`, `BACKGROUND_ASSET_VERSION_EXTERNAL_BETA_RELEASE_STATE_UPDATED`, `BACKGROUND_ASSET_VERSION_APP_STORE_RELEASE_STATE_UPDATED` | An asset pack version changes. See [Download extra content after your app is installed](https://air.build/docs/app-store/deliver-content-after-install/). |
| `ALTERNATIVE_DISTRIBUTION_PACKAGE_AVAILABLE_UPDATED`, `ALTERNATIVE_DISTRIBUTION_PACKAGE_VERSION_CREATED`, `ALTERNATIVE_DISTRIBUTION_TERRITORY_AVAILABILITY_UPDATED` | Distribution outside the App Store changes: a package's availability, a new package version, or the countries or regions where it's available. See [Distribute your app from your own website in the EU](https://air.build/docs/app-store/distribute-from-your-website-in-the-eu/). |

Apple's [Understanding webhook events](https://developer.apple.com/documentation/appstoreconnectapi/webhook-events) says what each event carries.

## Create the webhook

Ask in the Project's chat with your own address, and your server's secret in place of `YOUR_SECRET`, for example:

```text
Create a webhook called Build Updates at https://example.com/apple/webhook with the secret YOUR_SECRET, for build upload and version state events.
```

1. The Agent creates it with `asc webhooks create`, with a name, the address, the secret, the event types and whether it's on (`--enabled true` or `false`). All of them are needed, so say if you want it off to begin with.
2. It tells you in the chat what it made: the webhook's name, address, event types and whether it's on. `asc` doesn't show the secret again, so keep your own copy on your server.

> [!NOTE]
> The secret you type stays in the chat, where everyone in it can read it. To keep it out, save it in your Team's **Passwords** and tell the Agent its title instead: the Agent reads it with [password-book](https://air.build/docs/cli/password-book/) and passes it straight to `--secret`. The same goes for a new secret when you change it. See [Save logins for Agents](https://air.build/docs/agents/save-logins-for-agents/#add-a-login-yourself). The Passwords screen says: "Everyone on the Team and all of its Agents can see these. A value filled into a preview stays there as plain text. Save test accounts only, not personal accounts or production keys."

To list your app's webhooks later, ask "Which webhooks does this app have?" The Agent uses `asc webhooks list`.

## Send a test

Ask:

```text
Ping the Build Updates webhook.
```

The Agent sends a test with `asc webhooks ping`. Apple's help says the test shows in App Store Connect under Recent Deliveries with the Ping event. Check that your server got it, or ask the Agent for the deliveries (below) to see what your server answered.

## Read the deliveries

Each event Apple sends is a delivery. Ask, for example:

```text
Show the Build Updates webhook's deliveries since yesterday.
```

The Agent lists them with `asc webhooks deliveries`, and can limit them to a time range (`--created-after`, `--created-before`). For each delivery it shows:

- when it was made and when it was sent
- its delivery state, and the error, if there was one
- whether it was sent again
- the address it went to
- the HTTP status code your server answered with, and what your server sent back

## Resend a delivery

If your server was down or answered with an error, fix it first, then ask:

```text
Resend the failed deliveries from this morning.
```

The Agent sends each one again with `asc webhooks deliveries redeliver`. Check the deliveries again to see your server's new answer.

## Change, turn off or delete it

| Ask | `asc` |
| --- | --- |
| "Point the webhook at https://example.com/new-hook." | `webhooks update --url` |
| "Add TestFlight feedback to the webhook's events." | `webhooks update --events`, with the full list of event types it should have. |
| "Change the webhook's secret to YOUR_NEW_SECRET." | `webhooks update --secret`. Put the new secret on your server too. |
| "Turn off the webhook for now." | `webhooks update --enabled false`. Turn it back on with `--enabled true`. |
| "Delete the webhook." | `webhooks delete`, only with `--confirm`, so the Agent asks you first. |

`webhooks update` can't move a webhook to another app. Apple's help says to make a new webhook for that app instead.

## Questions

**Can I set up a webhook in AirBuild?**

No. Ask an Agent, or use App Store Connect on the web, under Users and Access, then Integrations, then Webhooks.

**The Agent says an --events value is invalid.**

The message is `invalid --events value "…"; must be one of:` and the list. Pick event types from [Choose the events](https://air.build/docs/app-store/get-webhook-events-from-apple/#choose-the-events).

**The Agent says --events must include at least one value.**

A webhook needs at least one event type. Say which events you want.

**The Agent says --name, --url, --secret, --events, or --enabled is required.**

There was nothing to change. Say what should change: the name, address, secret, events, or whether it's on.

**Apple refused the webhook.**

The Agent shows Apple's reason after "webhooks create: failed to create:" or "webhooks update: failed to update:". Check the address and the event types, then ask again.

**My server didn't get anything.**

Ask the Agent for the webhook's deliveries. If none are listed, check that the webhook is on and has the events you expect. If they're listed with an error or an error status code, fix your server, then ask the Agent to resend them.
