PowerTrack API migration to X API v2 filtered stream
Use this migration guide to understand the similarities and differences between PowerTrack API and X API v2 filtered stream, and to help migrate a current PowerTrack API integration to v2 filtered stream.- Similarities
- Streaming delivery method
- Integration process
- Persistent stream connection with separate rules management endpoints
- Rule syntax
- Rule operators (with exceptions)
- Rule matching logic
- Support for Post edit history and metadata
- Differences
- Rule length
- Rule volume
- Endpoint URLs
- App and Project requirement for access
- Authentication method
- Request parameters
- Usage tracking
- Multiple streams, redundant conections, backfill and Replay recovery
- Request parameters and response format
- Response JSON data structure
Similarities
Streaming delivery method Both PowerTrack and X API v2 filtered stream use streaming data delivery, which require the client to establish an open connection to an endpoint and keeping a very long lived HTTP request, and parsing the response incrementally from the server in real time. Both PowerTrack and X API v2 filtered stream filter publicly available Posts matching rules that exist on the stream in real time, and use keep-alive signals as new line characters (\r\n) to signal the connection is still active. Both PowerTrack and X API v2 filtered stream endpoint connections deliver data in real time and should be read by the connecting client quickly. Integration process Integrating with filtered stream is similar to integrating with PowerTrack, using the general process below:- Establish a streaming connection.
- Asynchronously send separate requests to add and delete rules from the stream.
- Reconnect to the stream automatically when connection is disconnected.
Rule syntax, operators, and matching rules logic
The X API v2 filtered stream uses a subset of the same rule operators currently used for PowerTrack rules. These operators are used to create boolean based rule syntax used for filtering desired matching Posts from the live stream. Both PowerTrack and filtered stream use the same rule syntax for building rules and matching logic is the same. While the majority of the operators are available for both PowerTrack and filter stream, there are a few notable differences and net new operators listed below. For more details and example uses for each operator see current PowerTrack operators and current X API v2 filtered stream operators.
Please note that many operators (noted as ‘advanced operators’) are reserved for those users who have been approved for Academic Research access or Enterprise access.
Operators available with both PowerTrack and X API v2 Filtered stream:
Support for Post edit history and metadata
Both versions provide metadata that describes any edit history. Check out the filtered stream API References and the Edit Posts fundamentals page for more details.
Differences
Rule length Rule length is measured the same way (by character count) for both PowerTrack and filtered stream rules, however the maximum length for PowerTrack rules is 2048 characters and the maximum rule length for rules on X API v2 filtered stream varies by access level. Enterprise access - 2048 characters (please contact your designated account manager regarding your specific account) Rule volume The PowerTrack maximum rule volume per stream is defined within the enterprise account contract. X API v2 filtered stream rule volume varies by access level. Enterprise access - 25000+ rules (please contact your designated account manager regarding your specific account) Endpoint URLs- PowerTrack endpoints:
- https://gnip-stream.x.com/stream/powertrack/accounts/{account\_name}/publishers/twitter/{stream\_label}.json
- https://gnip-api.x.com/rules/powertrack/accounts/{account\_name}/publishers/twitter/{stream\_label}.json
- https://gnip-api.x.com/rules/powertrack/accounts/{account\_name}/publishers/twitter/{stream\_label}/validation.json
- X API v2 endpoint:
The PowerTrack API data format is set within console.gnip.com at the stream settings level, which can be set to either the X native enriched format or Activity streams format.
PowerTrack API only uses one optional parameter on connection, to reconnect using backfill (backfillMinutes=5). This optional parameter is also available to filtered stream, but is called backfill_minutes, and is only available via Academic Research access.
https://gnip-stream.x.com/stream/powertrack/accounts/{account\_name}/publishers/twitter/{stream\_label}.json?backfillMinutes=5
Response structure and data format
As described above, the request parameters set at the connection request for X API v2 filtered stream determine the response data returned. There are several different response possibilites using different fields and expansions which can range from the most simple default response with only the Post id and text, to an extremely detailed and expanded data payload.
The data format for PowerTrack is set within console.gnip.com at the stream settings level, which can be set to either the X Native Enriched format or Activity Streams format.
The following table references Post response examples in each different format:
If you would like to know more about how the enterprise data formats map to the X API v2 format, please visit our following guides: