# Starting a Raid

Starting and cancelling raids with the Twitch API

Source: https://dev.twitch.tv/docs/api/raids/

A Raid is a Twitch feature that lets a broadcaster send their viewers over to watch another broadcaster's stream. Raiding is a great way to make connections and network with other broadcasters by sharing audiences and growing your communities.

## To raid another broadcaster

To raid another broadcaster, your chatbot or Extension POSTs a request to the [Start a raid](https://dev.twitch.tv/docs/api/reference/raids.md#start-a-raid) endpoint. Set the request's *from_broadcaster_id* query parameter to the broadcaster that's sending the raiding party and set the *to_broadcaster_id* query parameter to the broadcaster that's being raided.

```shell
curl -X POST 'https://api.twitch.tv/helix/raids?from_broadcaster_id=12345678&to_broadcaster_id=87654321' \
-H 'Authorization: Bearer kpvy3cjboyptmdkiacwr0c19hotn5s' \
-H 'Client-Id: hof5gwx0su6owfnys0nyan9c87zr6t'
```

The request doesn't actually start the raid but instead pops up a window at the top of the raiding broadcaster's chat room that shows the number of viewers in the raid. The raid occurs when the broadcaster clicks **Raid Now** or after the 90 seconds countdown expires.

Here's what the response looks like to the previous request:

```json
{
  "data": [
    {
      "created_at": "2022-02-18T07:20:50.52Z",
      "is_mature": false
    }
  ]
}
```

You can use the `is_mature` field in the response to let viewers know that the targeted channel contains mature content. The Twitch UX also lets viewers know that the targeted channel restricts chat to subscribers only or followers only. If you want to provide the same information in your experience, use the [Get Chat Settings](https://dev.twitch.tv/docs/api/reference/chat.md#get-chat-settings) endpoint and check the `subscriber_mode` and `follower_mode` fields.

## Get notified when a raid begins

The [Start a raid](https://dev.twitch.tv/docs/api/reference/raids.md#start-a-raid) response just lets you know that the request was queued. To determine whether the raid actually took place, you must subscribe to the [Channel Raid](https://dev.twitch.tv/docs/eventsub/reference/channel.md#channel-raid) event. For details about subscribing to an event, see [EventSub](https://dev.twitch.tv/docs/eventsub/manage-subscriptions.md).

To know whether the raid event is for your raid, compare the *from* and *to* broadcaster IDs in your request to the *from* and *to* IDs in the event.

## Canceling the raid

To cancel a raid, send a DELETE request to the [Cancel a raid](https://dev.twitch.tv/docs/api/reference/raids.md#cancel-a-raid) endpoint. You can cancel a raid at any point up until the broadcaster clicks **Raid Now** in the Twitch UX or the 90 seconds countdown expires.

The following example shows a request that cancels a raid. Set the *broadcaster_id* query parameter to the ID of the broadcaster that initiated the raid.

```bash
curl -X DELETE 'https://api.twitch.tv/helix/raids?broadcaster_id=12345678' \
-H 'Authorization: Bearer kpvy3cjboyptmdkiacwr0c19hotn5s' \
-H 'Client-Id: hof5gwx0su6owfnys0nyan9c87zr6t'
```

If the raid hasn't started and the raid was successfully canceled, the HTTP response code is 204 No Content; otherwise, if the raid has already started, the response code is 404 Not Found.

Note that calling this endpoint effectively clicks the Cancel button in the Twitch UX, dismissing the Raid pop up window.
