Fundamentals
Sorting
Sorting is available for most Ads API collection endpoints (that return a list of objects). Depending on the endpoint, you will find various parameters enabled for sorting. Most fields returned by these parameters (except for IDs and ENUMs) will be sortable.
API Collection | Sortable Parameters |
---|---|
Accounts | created_at , updated_at , deleted , name |
Funding Instruments | created_at , updated_at , deleted , funded_amount_local_micro , start_time , end_time |
Campaigns | created_at , updated_at , deleted , name , start_time , end_time , daily_budget_amount_local_micro , total_budget_amount_local_micro , standard_delivery |
Line Items | created_at , updated_at , deleted , bid_amount_local_micro |
Cards | created_at , updated_at , deleted , name |
Promoted Accounts | created_at , updated_at , deleted , paused |
Promoted Tweets | created_at , updated_at , deleted , paused |
App Event Tags | created_at , updated_at , deleted , post_view_attribution_window , post_engagement_attribution_window , assisted_conversion , provider_app_event_name |
Getting Started
In your API request simply append sort_by=[attribute name]-[asc/desc]
where the attribute is a valid attribute that is returned in the JSON of your GET request.
For example, you can use ?name-asc
to sort by name alphabetically or ?name-desc
to sort in reverse.
Going Deeper
Below is a sample API request to return all line items by the bid_amount_local_micro in descending order:
$ twurl -H ads-api.x.com”/5/accounts/k9w0oe/line_items?sort_by=bid_amount_local_micro-desc”
{
"request": {
"params": {
"sort_by": \[
"bid\_amount\_local_micro-desc"
\],
"account_id": "k9w0oe"
}
},
"data": \[
{
"bid_type": "MAX",
"name": "Untitled",
"placements": \[
"ALL\_ON\_TWITTER"
\],
"bid\_amount\_local_micro": 3000000,
"automatically\_select\_bid": false,
"advertiser_domain": null,
"primary\_web\_event_tag": null,
"charge_by": "ENGAGEMENT",
"product\_type": "PROMOTED\_TWEETS",
"bid_unit": "ENGAGEMENT",
"total\_budget\_amount\_local\_micro": null,
"objective": "ENGAGEMENTS",
"id": "1iw6k",
"paused": true,
"optimization": "DEFAULT",
"categories": \[
\],
"currency": "USD",
"created_at": "2014-09-09T02:11:32Z",
"updated_at": "2015-05-27T23:01:45Z",
"include\_sentiment": "POSITIVE\_ONLY",
"campaign_id": "1kv71",
"creative_source": "MANUAL",
"deleted": false
},
{
"bid_type": "MAX",
"name": "Untitled",
"placements": \[
"ALL\_ON\_TWITTER"
\],
"bid\_amount\_local_micro": 3000000,
"automatically\_select\_bid": false,
"advertiser_domain": null,
"primary\_web\_event_tag": null,
"charge_by": "FOLLOW",
"product\_type": "PROMOTED\_ACCOUNT",
"bid_unit": "FOLLOW",
"total\_budget\_amount\_local\_micro": null,
"objective": "FOLLOWERS",
"id": "1nlqp",
"paused": false,
"optimization": "DEFAULT",
"categories": \[
\],
"currency": "USD",
"created_at": "2014-10-20T18:57:18Z",
"updated_at": "2014-10-20T18:57:18Z",
"include_sentiment": null,
"campaign_id": "1pjkp",
"creative_source": "MANUAL",
"deleted": false
},
{
"bid_type": "MAX",
"name": "Untitled",
"placements": \[
"ALL\_ON\_TWITTER"
\],
"bid\_amount\_local_micro": 2500000,
"automatically\_select\_bid": false,
"advertiser_domain": null,
"primary\_web\_event_tag": null,
"charge_by": "ENGAGEMENT",
"product\_type": "PROMOTED\_TWEETS",
"bid_unit": "ENGAGEMENT",
"total\_budget\_amount\_local\_micro": null,
"objective": "ENGAGEMENTS",
"id": "1iw6l",
"paused": true,
"optimization": "DEFAULT",
"categories": \[
\],
"currency": "USD",
"created_at": "2014-09-09T02:11:54Z",
"updated_at": "2014-09-17T06:23:23Z",
"include\_sentiment": "POSITIVE\_ONLY",
"campaign_id": "1kv71",
"creative_source": "MANUAL",
"deleted": false
},
{
"bid_type": "MAX",
"name": "Untitled",
"placements": \[
"ALL\_ON\_TWITTER"
\],
"bid\_amount\_local_micro": 2500000,
"automatically\_select\_bid": false,
"advertiser_domain": null,
"primary\_web\_event_tag": null,
"charge_by": "ENGAGEMENT",
"product\_type": "PROMOTED\_TWEETS",
"bid_unit": "ENGAGEMENT",
"total\_budget\_amount\_local\_micro": null,
"objective": "ENGAGEMENTS",
"id": "1iw9q",
"paused": false,
"optimization": "DEFAULT",
"categories": \[
\],
"currency": "USD",
"created_at": "2014-09-09T03:11:46Z",
"updated_at": "2014-09-09T03:26:17Z",
"include\_sentiment": "POSITIVE\_ONLY",
"campaign_id": "1kv71",
"creative_source": "MANUAL",
"deleted": false
},
{
"bid_type": "MAX",
"name": "Untitled",
"placements": \[
"ALL\_ON\_TWITTER"
\],
"bid\_amount\_local_micro": 2500000,
"automatically\_select\_bid": false,
"advertiser_domain": null,
"primary\_web\_event_tag": null,
"charge_by": "ENGAGEMENT",
"product\_type": "PROMOTED\_TWEETS",
"bid_unit": "ENGAGEMENT",
"total\_budget\_amount\_local\_micro": null,
"objective": "ENGAGEMENTS",
"id": "1iw9r",
"paused": false,
"optimization": "DEFAULT",
"categories": \[
\],
"currency": "USD",
"created_at": "2014-09-09T03:12:02Z",
"updated_at": "2014-09-09T03:30:44Z",
"include\_sentiment": "POSITIVE\_ONLY",
"campaign_id": "1kv71",
"creative_source": "MANUAL",
"deleted": false
},
{
"bid_type": "MAX",
"name": "Untitled",
"placements": \[
"TWITTER_TIMELINE",
"TWITTER_PROFILE"
\],
"bid\_amount\_local_micro": 2000000,
"automatically\_select\_bid": false,
"advertiser_domain": null,
"primary\_web\_event_tag": null,
"charge_by": "ENGAGEMENT",
"product\_type": "PROMOTED\_TWEETS",
"bid_unit": "ENGAGEMENT",
"total\_budget\_amount\_local\_micro": null,
"objective": "ENGAGEMENTS",
"id": "1kkze",
"paused": false,
"optimization": "DEFAULT",
"categories": \[
\],
"currency": "USD",
"created_at": "2014-09-24T01:18:20Z",
"updated_at": "2015-08-30T04:41:34Z",
"include_sentiment": null,
"campaign_id": "1mj4h",
"creative_source": "MANUAL",
"deleted": false
},
{
"bid_type": "MAX",
"name": "Untitled",
"placements": \[
"TWITTER_TIMELINE",
"TWITTER_PROFILE"
\],
"bid\_amount\_local_micro": 2000000,
"automatically\_select\_bid": false,
"advertiser_domain": null,
"primary\_web\_event_tag": null,
"charge_by": "ENGAGEMENT",
"product\_type": "PROMOTED\_TWEETS",
"bid_unit": "ENGAGEMENT",
"total\_budget\_amount\_local\_micro": null,
"objective": "ENGAGEMENTS",
"id": "1kkzk",
"paused": false,
"optimization": "DEFAULT",
"categories": \[
\],
"currency": "USD",
"created_at": "2014-09-24T01:23:06Z",
"updated_at": "2015-08-30T04:41:34Z",
"include_sentiment": null,
"campaign_id": "1mj4n",
"creative_source": "MANUAL",
"deleted": false
},
{
"bid_type": "MAX",
"name": "Untitled",
"placements": \[
"ALL\_ON\_TWITTER"
\],
"bid\_amount\_local_micro": 2000000,
"automatically\_select\_bid": false,
"advertiser_domain": null,
"primary\_web\_event_tag": null,
"charge_by": "ENGAGEMENT",
"product\_type": "PROMOTED\_TWEETS",
"bid_unit": "ENGAGEMENT",
"total\_budget\_amount\_local\_micro": null,
"objective": "ENGAGEMENTS",
"id": "1kkzq",
"paused": false,
"optimization": "DEFAULT",
"categories": \[
\],
"currency": "USD",
"created_at": "2014-09-24T01:25:06Z",
"updated_at": "2014-09-24T01:34:20Z",
"include\_sentiment": "POSITIVE\_ONLY",
"campaign_id": "1mj48",
"creative_source": "MANUAL",
"deleted": false
},
{
"bid_type": "MAX",
"name": "Untitled",
"placements": \[
"ALL\_ON\_TWITTER"
\],
"bid\_amount\_local_micro": 2000000,
"automatically\_select\_bid": false,
"advertiser_domain": null,
"primary\_web\_event_tag": null,
"charge_by": "ENGAGEMENT",
"product\_type": "PROMOTED\_TWEETS",
"bid_unit": "ENGAGEMENT",
"total\_budget\_amount\_local\_micro": null,
"objective": "ENGAGEMENTS",
"id": "1kkzr",
"paused": false,
"optimization": "DEFAULT",
"categories": \[
\],
"currency": "USD",
"created_at": "2014-09-24T01:25:09Z",
"updated_at": "2014-09-24T01:34:41Z",
"include\_sentiment": "POSITIVE\_ONLY",
"campaign_id": "1mj48",
"creative_source": "MANUAL",
"deleted": false
},
{
"bid_type": "MAX",
"name": "Untitled",
"placements": \[
"ALL\_ON\_TWITTER"
\],
"bid\_amount\_local_micro": 2000000,
"automatically\_select\_bid": false,
"advertiser_domain": null,
"primary\_web\_event_tag": null,
"charge_by": "ENGAGEMENT",
"product\_type": "PROMOTED\_TWEETS",
"bid_unit": "ENGAGEMENT",
"total\_budget\_amount\_local\_micro": 6000000,
"objective": "ENGAGEMENTS",
"id": "1kl0e",
"paused": false,
"optimization": "DEFAULT",
"categories": \[
\],
"currency": "USD",
"created_at": "2014-09-24T01:42:49Z",
"updated_at": "2014-09-24T01:51:25Z",
"include\_sentiment": "POSITIVE\_ONLY",
"campaign_id": "1mj57",
"creative_source": "MANUAL",
"deleted": false
},
{
"bid_type": "MAX",
"name": "Untitled",
"placements": \[
"ALL\_ON\_TWITTER"
\],
"bid\_amount\_local_micro": 2000000,
"automatically\_select\_bid": false,
"advertiser_domain": null,
"primary\_web\_event_tag": null,
"charge_by": "ENGAGEMENT",
"product\_type": "PROMOTED\_TWEETS",
"bid_unit": "ENGAGEMENT",
"total\_budget\_amount\_local\_micro": 12000000,
"objective": "ENGAGEMENTS",
"id": "1kl0g",
"paused": false,
"optimization": "DEFAULT",
"categories": \[
\],
"currency": "USD",
"created_at": "2014-09-24T01:43:19Z",
"updated_at": "2014-09-24T01:51:40Z",
"include\_sentiment": "POSITIVE\_ONLY",
"campaign_id": "1mj57",
"creative_source": "MANUAL",
"deleted": false
},
{
"bid_type": "MAX",
"name": "Untitled",
"placements": \[
"ALL\_ON\_TWITTER"
\],
"bid\_amount\_local_micro": 2000000,
"automatically\_select\_bid": false,
"advertiser_domain": null,
"primary\_web\_event_tag": null,
"charge_by": "ENGAGEMENT",
"product\_type": "PROMOTED\_TWEETS",
"bid_unit": "ENGAGEMENT",
"total\_budget\_amount\_local\_micro": 6000000,
"objective": "ENGAGEMENTS",
"id": "1kl0l",
"paused": false,
"optimization": "DEFAULT",
"categories": \[
\],
"currency": "USD",
"created_at": "2014-09-24T01:45:09Z",
"updated_at": "2014-09-24T01:51:54Z",
"include\_sentiment": "POSITIVE\_ONLY",
"campaign_id": "1mj5d",
"creative_source": "MANUAL",
"deleted": false
}
\],
"next_cursor": null
}
On this page