POST /2/tweets/search/stream/rules
Add or delete rules to your stream.
Once you've added a rule or rules to your stream, you can retrieve all of the Tweets that match these rules by using the GET /tweets/search/stream endpoint.
To learn how to build a rule, please read our guide on building a rule.
To create one or more rules, submit an add
JSON body with an array of rules and operators. Similarly, to delete one or more rules, submit a delete
JSON body with an array of list of existing rule IDs.
Endpoint URL
https://api.x.com/2/tweets/search/stream/rules
Authentication and rate limits
Authentication methods supported by this endpoint | |
---|---|
Rate limit | App rate limit (Application-only): 450 requests per 15-minute window shared among all users of your app |
Query parameters
Name | Type | Description |
---|---|---|
delete_all Optional | boolean | Set to true to delete all existing rules. |
dry_run Optional | boolean | Set to true to test the syntax of your rule without submitting it. This is useful if you want to check the syntax of a rule before removing one or more of your existing rules. |
JSON body parameters
Name | Type | Description |
---|---|---|
add Required | array | Specifies the operation you want to perform on the rules. |
add.value Required | string | The rule text. You can learn how to build a rule by following our guide on how to build a rule. If you have Essential access, you can use basic operators to build your rule, can add up to 5 rules to your stream concurrently, and each rule can be 512 characters long. If you have Elevated access, you can use basic operators, can add up to 25 rules to your stream, and each rule can be 512 characters long If you have Academic Research access, you can use all operators, can add up to 1000 rules to your stream, and each rule can be 1024 characters long. To learn more about Twitter API access levels, please visit our about Twitter API page. |
delete Required | object | Specifies the operation you want to perform on the rules. |
delete.ids Required | array | Array of rule IDs, each one representing a rule already active in your stream. IDs must be submitted as strings. You can find a rule ID by using the GET /tweets/search/stream/rules endpoint. |
add.tag Optional | string | The tag label. This is a free-form text you can use to identify the rules that matched a specific Tweet in the streaming response. Tags can be the same across rules. Learn more about tags from our matching returned Tweets guide. |
Example code with offical SDKs
Example responses
Response fields
Name | Type | Description |
---|---|---|
id | string | Unique identifier of this rule. This is returned as a string in order to avoid complications with languages and tools that cannot handle large integers. |
value | string | The rule text as submitted when creating the rule. |
tag | string | The tag label as defined when creating the rule. |
meta Default | object | Contains information about when the rule was created, and whether the rule was either created or not created, or deleted or not deleted. |
meta.sent Default | number | The time when the request body was returned. |
meta.summary Default | object | Contains fields that describe whether you were successful or unsuccessful in creating or deleting the different rules that you passed in your request. |
errors | object | Contains details about errors that affected any of the requested Tweets. See Status codes and error messages for more details. |