GET /2/tweets/search/stream/rules

GET /2/tweets/search/stream/rules

Return either a single rule, or a list of rules that have been added to the stream.

If you would like to initiate the stream to receive all Tweets that match these rules in real-time, you will need to use the GET /tweets/search/stream endpoint.

Endpoint URL

https://api.x.com/2/tweets/search/stream/rules

Authentication and rate limits

Authentication methods
supported by this endpoint

OAuth 2.0 App-only

Rate limit

App rate limit (Application-only): 450 requests per 15-minute window shared among all users of your app

Query parameters

NameTypeDescription
ids
 Optional 
stringComma-separated list of rule IDs. If omitted, all rules are returned.


Example code with offical SDKs

TypeScript
Java
      (async () => {
  try {
    const getStreamRules = await twitterClient.tweets.getRules();
    console.dir(getStreamRules, {
      depth: null,
    });
  } catch (error) {
    console.log(error);
  }
})();

    
      //Set the (optional) params values

//List<String> | A comma-separated list of Rule IDs.
List<String> ids = Arrays.asList();

//Integer | The maximum number of results
Integer maxResults = 1000;

//String | This value is populated by passing the 'next_token' returned in a request to paginate through results.
String paginationToken = "paginationToken_example";

try {
    GetRulesResponse result = apiInstance.tweets().getRules(ids, maxResults, paginationToken);
    System.out.println(result);
} catch (ApiException e) {
    System.err.println("Exception when calling TweetsApi#getRules");
    System.err.println("Status code: " + e.getCode());
    System.err.println("Reason: " + e.getResponseBody());
    System.err.println("Response headers: " + e.getResponseHeaders());
    e.printStackTrace();
}

    

Example responses

Response
      {
  "data": [
    {
      "id": "1165037377523306497",
      "value": "dog has:images",
      "tag": "dog pictures"
    },
    {
      "id": "1165037377523306498",
      "value": "cat has:images -grumpy"
    }
  ],
  "meta": {
    "sent": "2019-08-29T01:12:10.729Z"
  }
}
    

Response fields

NameTypeDescription
idstringUnique identifier of this rule. This is returned as a string in order to avoid complications with languages and tools that cannot handle large integers.
valuestringThe rule text as submitted when creating the rule.
tagstringThe tag label as defined when creating the rule.
meta.sentnumberThe time when the request body was returned.
errorsobjectContains details about errors that affected any of the requested Tweets. See Status codes and error messages for more details.