Create X activity subscription
Creates a subscription for an X activity event. OAuth2 user-context tokens must hold the scope matching the requested event_type: dm.read for chat.* and dm.* events, like.read for like.* events, mute.read for mute.* events, block.read for block.* events, follows.read for subscriptions.* events, and tweet.read for all other event types. Mute and block subscriptions are actor-only: filter.user_id must identify the authenticated user and direction is not supported. subscriptions.* events require a user-context token and filter.user_id must identify the authenticated user. Optional filter.qualifiers further narrow supported chat, follow, unfollow, like, and subscriptions events.
curl --request POST \
--url https://api.x.com/2/activity/subscriptions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"filter": {
"keyword": "<string>",
"qualifiers": {},
"user_id": "<string>"
},
"expires_at": "<string>",
"tag": "<string>",
"webhook_id": "<string>"
}
'import requests
url = "https://api.x.com/2/activity/subscriptions"
payload = {
"filter": {
"keyword": "<string>",
"qualifiers": {},
"user_id": "<string>"
},
"expires_at": "<string>",
"tag": "<string>",
"webhook_id": "<string>"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
filter: {keyword: '<string>', qualifiers: {}, user_id: '<string>'},
expires_at: '<string>',
tag: '<string>',
webhook_id: '<string>'
})
};
fetch('https://api.x.com/2/activity/subscriptions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.x.com/2/activity/subscriptions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'filter' => [
'keyword' => '<string>',
'qualifiers' => [
],
'user_id' => '<string>'
],
'expires_at' => '<string>',
'tag' => '<string>',
'webhook_id' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.x.com/2/activity/subscriptions"
payload := strings.NewReader("{\n \"filter\": {\n \"keyword\": \"<string>\",\n \"qualifiers\": {},\n \"user_id\": \"<string>\"\n },\n \"expires_at\": \"<string>\",\n \"tag\": \"<string>\",\n \"webhook_id\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.x.com/2/activity/subscriptions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"filter\": {\n \"keyword\": \"<string>\",\n \"qualifiers\": {},\n \"user_id\": \"<string>\"\n },\n \"expires_at\": \"<string>\",\n \"tag\": \"<string>\",\n \"webhook_id\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.x.com/2/activity/subscriptions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"filter\": {\n \"keyword\": \"<string>\",\n \"qualifiers\": {},\n \"user_id\": \"<string>\"\n },\n \"expires_at\": \"<string>\",\n \"tag\": \"<string>\",\n \"webhook_id\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"data": {
"subscription": {
"created_at": "<string>",
"event_type": "<string>",
"expires_at": "<string>",
"filter": {
"direction": "<string>",
"keyword": "<string>",
"qualifiers": {},
"user_id": "<string>"
},
"subscription_id": "<string>",
"tag": "<string>",
"updated_at": "<string>",
"webhook_id": "<string>"
}
},
"errors": [
{
"detail": "<string>",
"resource_type": "<string>",
"title": "<string>",
"type": "https://api.x.com/2/problems/resource-not-found",
"parameter": "<string>",
"resource_id": "<string>",
"status": 123,
"value": "<string>"
}
]
}{
"code": 123,
"message": "<string>"
}Authorizations
The access token received from the authorization server in the OAuth 2.0 flow.
Body
Activity event type in dot notation. chat.conversation_join is a deprecated alias of chat.conversation.join; responses always use the canonical name.
profile.update.bio, profile.update.profile_picture, profile.update.banner_picture, profile.update.screenname, profile.update.geo, profile.update.url, profile.update.verified_badge, profile.update.affiliate_badge, profile.update.handle, news.new, follow.follow, follow.unfollow, subscriptions.subscribe, subscriptions.unsubscribe, spaces.start, spaces.end, broadcast.start, broadcast.end, broadcast.chat, chat.received, chat.sent, chat.conversation.join, chat.conversation_join, chat.conversation.member_added, chat.conversation.member_removed, chat.conversation.admin_added, chat.conversation.admin_removed, chat.update.group_name, chat.update.restrictions, dm.sent, dm.received, dm.indicate_typing, dm.read, post.create, post.delete, post.mention.create, post.reply.create, post.quote.create, post.repost.create, like.create, mute.mute, mute.unmute, block.block, block.unblock Subscription filter.
Show child attributes
Show child attributes
Optional RFC 3339 expiration time. Re-creating the same subscription refreshes this value; omitting it makes the subscription permanent.
Optional caller-defined tag.
1 - 200Webhook to deliver the subscription events to.
^[0-9]{1,19}$curl --request POST \
--url https://api.x.com/2/activity/subscriptions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"filter": {
"keyword": "<string>",
"qualifiers": {},
"user_id": "<string>"
},
"expires_at": "<string>",
"tag": "<string>",
"webhook_id": "<string>"
}
'import requests
url = "https://api.x.com/2/activity/subscriptions"
payload = {
"filter": {
"keyword": "<string>",
"qualifiers": {},
"user_id": "<string>"
},
"expires_at": "<string>",
"tag": "<string>",
"webhook_id": "<string>"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
filter: {keyword: '<string>', qualifiers: {}, user_id: '<string>'},
expires_at: '<string>',
tag: '<string>',
webhook_id: '<string>'
})
};
fetch('https://api.x.com/2/activity/subscriptions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.x.com/2/activity/subscriptions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'filter' => [
'keyword' => '<string>',
'qualifiers' => [
],
'user_id' => '<string>'
],
'expires_at' => '<string>',
'tag' => '<string>',
'webhook_id' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.x.com/2/activity/subscriptions"
payload := strings.NewReader("{\n \"filter\": {\n \"keyword\": \"<string>\",\n \"qualifiers\": {},\n \"user_id\": \"<string>\"\n },\n \"expires_at\": \"<string>\",\n \"tag\": \"<string>\",\n \"webhook_id\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.x.com/2/activity/subscriptions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"filter\": {\n \"keyword\": \"<string>\",\n \"qualifiers\": {},\n \"user_id\": \"<string>\"\n },\n \"expires_at\": \"<string>\",\n \"tag\": \"<string>\",\n \"webhook_id\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.x.com/2/activity/subscriptions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"filter\": {\n \"keyword\": \"<string>\",\n \"qualifiers\": {},\n \"user_id\": \"<string>\"\n },\n \"expires_at\": \"<string>\",\n \"tag\": \"<string>\",\n \"webhook_id\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"data": {
"subscription": {
"created_at": "<string>",
"event_type": "<string>",
"expires_at": "<string>",
"filter": {
"direction": "<string>",
"keyword": "<string>",
"qualifiers": {},
"user_id": "<string>"
},
"subscription_id": "<string>",
"tag": "<string>",
"updated_at": "<string>",
"webhook_id": "<string>"
}
},
"errors": [
{
"detail": "<string>",
"resource_type": "<string>",
"title": "<string>",
"type": "https://api.x.com/2/problems/resource-not-found",
"parameter": "<string>",
"resource_id": "<string>",
"status": 123,
"value": "<string>"
}
]
}{
"code": 123,
"message": "<string>"
}