Filtering Queries (AND)

You can also filter queries to get specific records. Multiple filters are allowed.

A filter has the following required keys:

Key

Description

match

The type of condition: all, any

conditions

The list of condition

Each condition has the following required keys:

Key

Description

column

The column the filter should be applied to

value

The value of the filter

type

The type of "equality" to use: =, !=, >, <, >=, <=

Not every filter type can be applied to every column. "String" types can only support a "=" filter, whereas "Number" types can support all filter types.

For example, to filter down to only New York Apple stores, an example request is:

POST /dataset/store/query/ HTTP/1.1
Authorization: token 01234567890123456789
X-API-Version: 20151130

{
    "tickers": [
        "nasdaq:aapl"
    ],
    "filters": [
        {
            "match": "all",
            "conditions": [
                {
                    "column": "state",
                    "type": "=",
                    "value": [
                        "NY"
                    ]
                },
                {
                    "column": "city",
                    "type": "=",
                    "value": [
                        "New York"
                    ]
                }
            ]
        }
    ]
}
curl -X POST "https://data.thinknum.com/datasets/store/query/" \
-H "Accept: application/json" \
-H "X-API-Version: 20151130" \
-H "Authorization: token 01234567890123456789" \
-d $'{
    "tickers": [
        "nasdaq:aapl"
    ],
    "filters": [
        {
            "match": "all",
            "conditions": [
                {
                    "column": "state",
                    "type": "=",
                    "value": [
                        "NY"
                    ]
                },
                {
                    "column": "city",
                    "type": "=",
                    "value": [
                        "New York"
                    ]
                }
            ]
        }
    ]
}'
response = requests.post(
    url='https://data.thinknum.com/datasets/store/query/', 
    headers={
        'Authorization': 'token 01234567890123456789', 
        'X-API-Version': '20151130', 
        'Accept': 'application/json'
    }, 
    data=json.dumps({
        "tickers": [
            "nasdaq:aapl"
        ],
        "filters": [
            {
                "match": "all",
                "conditions": [
                    {
                        "column": "state",
                        "type": "=",
                        "value": [
                            "NY"
                        ]
                    },
                    {
                        "column": "city",
                        "type": "=",
                        "value": [
                            "New York"
                        ]
                    }
                ]
            }
        ]
    })
)
results = json.loads(response.text)

A sample response follows:

{
    "state": "complete",
    "total": 7,
    "id": "191ca7678cf98b269d3dc028b9e11060f67ea30864afd2fd2a90a33312fb5253",
    "formats": [
        "application/vnd.thinknum.table+json",
        "application/vnd.thinknum.map+json"
    ]
}

To check if query is completed:

HEAD datasets/store/query/191ca7678cf98b269d3dc028b9e11060f67ea30864afd2fd2a90a33312fb5253 HTTP/1.1
Authorization: token 01234567890123456789
X-API-Version: 20151130
Accept: application/vnd.thinknum.table+json
Content-Type: application/x-www-form-urlencoded; charset=utf-8
curl -I HEAD "https://data.thinknum.com/datasets/store/query/191ca7678cf98b269d3dc028b9e11060f67ea30864afd2fd2a90a33312fb5253" \
-H "Accept: application/vnd.thinknum.table+json" \
-H "X-API-Version: 20151130" \
-H "Authorization: token 01234567890123456789"
response = requests.head(
    url='https://data.thinknum.com/datasets/store/query/191ca7678cf98b269d3dc028b9e11060f67ea30864afd2fd2a90a33312fb5253', 
    headers={
        'Authorization': 'token 01234567890123456789', 
        'X-API-Version': '20151130', 
        'Accept': 'application/vnd.thinknum.table+json'
    }
)
results = dict(response.headers)

A sample response follows:

HTTP/1.1 200 OK
Server: nginx
Date: Fri, 30 Apr 2021 15:18:35 GMT
Content-Type: application/json
Connection: keep-alive
X-Truncated: false
X-Formats: application/vnd.thinknum.table+json, application/vnd.thinknum.map+json, text/csv, application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
X-Total: 7
X-State: complete
Strict-Transport-Security: max-age=15768000

To retrieve data:

GET /datasets/store/query/191ca7678cf98b269d3dc028b9e11060f67ea30864afd2fd2a90a33312fb5253
Authorization: token 01234567890123456789
X-API-Version: 20151130
Accept: application/vnd.thinknum.table+json
Content-Type: application/json
curl -X GET "https://data.thinknum.com/datasets/store/query/191ca7678cf98b269d3dc028b9e11060f67ea30864afd2fd2a90a33312fb5253?limit=10&start=1" \
-H "Accept: application/vnd.thinknum.table+json" \
-H "Content-Type: application/json" \
-H "X-API-Version: 20151130" \
-H "Authorization: token 01234567890123456789"
response = requests.get(
    url='https://data.thinknum.com/datasets/store/query/191ca7678cf98b269d3dc028b9e11060f67ea30864afd2fd2a90a33312fb5253', 
    headers={
        'Authorization': 'token 01234567890123456789', 
        'X-API-Version': '20151130', 
        'Accept': 'application/vnd.thinknum.table+json'
    }
)
results = json.loads(response.text)

A sample response follows:

{
    "group_fields": [
        {
            "display_name": "Ticker Symbol",
            "format": "ticker",
            "metric": false,
            "id": "dataset__entity__entity_ticker__ticker__ticker",
            "length": 320,
            "summary": "The full ticker symbol, defined as the financial market of the company, followed by a colon (:), and then the identifier of the company. ex. NASDAQ:AAPL",
            "type": "string",
            "options": []
        },
        ...
        {
            "display_name": "GICS Industry",
            "format": null,
            "metric": false,
            "id": "dataset__entity__entity_ticker__ticker__market_industry",
            "length": 64,
            "summary": "The gics industry within the sector a ticker belongs to",
            "type": "string",
            "options": []
        }
    ],
    "total": 7,
    "id": "191ca7678cf98b269d3dc028b9e11060f67ea30864afd2fd2a90a33312fb5253",
    "count": 7,
    "rows": [
        [
            "nasdaq:aapl",
            ...
            "Technology Hardware & Equipment"
        ],
        ...
        [
            "nasdaq:aapl",
            ...
            "Technology Hardware & Equipment"
        ]
    ],
    "fields": [
        {
            "display_name": "Ticker Symbol",
            "format": "ticker",
            "metric": false,
            "id": "dataset__entity__entity_ticker__ticker__ticker",
            "length": 320,
            "summary": "The full ticker symbol, defined as the financial market of the company, followed by a colon (:), and then the identifier of the company. ex. NASDAQ:AAPL",
            "type": "string",
            "options": []
        },
        ...
        {
            "display_name": "GICS Industry",
            "format": null,
            "metric": false,
            "id": "dataset__entity__entity_ticker__ticker__market_industry",
            "length": 64,
            "summary": "The gics industry within the sector a ticker belongs to",
            "type": "string",
            "options": []
        }
    ],
    "sort_fields": [],
    "start": 1,
    "state": "complete",
    "limit": 10,
    "last_date_updated": "2021-04-01T02:34:56Z"
}

Filtering Queries (OR)

To filter down to Apple stores in New York City OR California, an example request is:

POST /dataset/store/query/ HTTP/1.1
Authorization: token 01234567890123456789
X-API-Version: 20151130

{
    "tickers": [
        "nasdaq:aapl"
    ],
    "filters": [
        {
            "match": "any",
            "conditions": [
                {
                    "column": "state",
                    "type": "=",
                    "value": [
                        "CA"
                    ]
                },
                {
                    "column": "city",
                    "type": "=",
                    "value": [
                        "New York"
                    ]
                }
            ]
        }
    ]
}
curl -X POST "https://data.thinknum.com/datasets/store/query/" \
-H "Accept: application/json" \
-H "X-API-Version: 20151130" \
-H "Authorization: token 01234567890123456789" \
-d $'{
    "tickers": [
        "nasdaq:aapl"
    ],
    "filters": [
        {
            "match": "any",
            "conditions": [
                {
                    "column": "state",
                    "type": "=",
                    "value": [
                        "CA"
                    ]
                },
                {
                    "column": "city",
                    "type": "=",
                    "value": [
                        "New York"
                    ]
                }
            ]
        }
    ]
}'
response = requests.post(
    url='https://data.thinknum.com/datasets/store/query/', 
    headers={
        'Authorization': 'token 01234567890123456789', 
        'X-API-Version': '20151130', 
        'Accept': 'application/json'
    }, 
    data=json.dumps({
        "tickers": [
            "nasdaq:aapl"
        ],
        "filters": [
            {
                "match": "any",
                "conditions": [
                    {
                        "column": "state",
                        "type": "=",
                        "value": [
                            "NY"
                        ]
                    },
                    {
                        "column": "city",
                        "type": "=",
                        "value": [
                            "New York"
                        ]
                    }
                ]
            }
        ]
    })
)
results = json.loads(response.text)

A sample response follows:

{
    "state": "complete",
    "total": 4384,
    "id": "c792d09496b22d544e53f587c5b9c407098387ac985057c9e9d42553fb0552af",
    "formats": [
        "application/vnd.thinknum.table+json",
        "application/vnd.thinknum.map+json"
    ]
}

To check if query is completed:

HEAD datasets/store/query/c792d09496b22d544e53f587c5b9c407098387ac985057c9e9d42553fb0552af HTTP/1.1
Authorization: token 01234567890123456789
X-API-Version: 20151130
Accept: application/vnd.thinknum.table+json
Content-Type: application/x-www-form-urlencoded; charset=utf-8
curl -I HEAD "https://data.thinknum.com/datasets/store/query/c792d09496b22d544e53f587c5b9c407098387ac985057c9e9d42553fb0552af" \
-H "Accept: application/vnd.thinknum.table+json" \
-H "X-API-Version: 20151130" \
-H "Authorization: token 01234567890123456789"
response = requests.head(
    url='https://data.thinknum.com/datasets/store/query/191ca7678cf98b269d3dc028b9e11060f67ea30864afd2fd2a90a33312fb5253', 
    headers={
        'Authorization': 'token 01234567890123456789', 
        'X-API-Version': '20151130', 
        'Accept': 'application/vnd.thinknum.table+json'
    }
)
results = dict(response.headers)

A sample response follows:

HTTP/1.1 200 OK
Server: nginx
Date: Fri, 30 Apr 2021 15:31:13 GMT
Content-Type: application/json
Connection: keep-alive
X-Truncated: false
X-Formats: application/vnd.thinknum.table+json, application/vnd.thinknum.map+json, text/csv, application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
X-Total: 4384
X-State: complete
Strict-Transport-Security: max-age=15768000

To retrieve data:

GET /datasets/store/query/c792d09496b22d544e53f587c5b9c407098387ac985057c9e9d42553fb0552af
Authorization: token 01234567890123456789
X-API-Version: 20151130
Accept: application/vnd.thinknum.table+json
Content-Type: application/json
curl -X GET "https://data.thinknum.com/datasets/store/query/c792d09496b22d544e53f587c5b9c407098387ac985057c9e9d42553fb0552af?limit=10&start=1" \
-H "Accept: application/vnd.thinknum.table+json" \
-H "Content-Type: application/json" \
-H "X-API-Version: 20151130" \
-H "Authorization: token 01234567890123456789"
response = requests.get(
    url='https://data.thinknum.com/datasets/store/query/191ca7678cf98b269d3dc028b9e11060f67ea30864afd2fd2a90a33312fb5253', 
    headers={
        'Authorization': 'token 01234567890123456789', 
        'X-API-Version': '20151130', 
        'Accept': 'application/vnd.thinknum.table+json'
    }
)
results = json.loads(response.text)

A sample response follows:

{
    "group_fields": [
        {
            "display_name": "Ticker Symbol",
            "format": "ticker",
            "metric": false,
            "id": "dataset__entity__entity_ticker__ticker__ticker",
            "length": 320,
            "summary": "The full ticker symbol, defined as the financial market of the company, followed by a colon (:), and then the identifier of the company. ex. NASDAQ:AAPL",
            "type": "string",
            "options": []
        },
        ...
        {
            "display_name": "GICS Industry",
            "format": null,
            "metric": false,
            "id": "dataset__entity__entity_ticker__ticker__market_industry",
            "length": 64,
            "summary": "The gics industry within the sector a ticker belongs to",
            "type": "string",
            "options": []
        }
    ],
    "total": 4384,
    "id": "60d68cb37d2af4e7b3c4b7aaae0b89ad45f992487997bb173b4b60191fc4d673",
    "count": 10,
    "rows": [
        [
            "nasdaq:aapl",
            ...
            "Technology Hardware & Equipment"
        ],
        ...
        [
            "nasdaq:aapl",
            ...
            "Technology Hardware & Equipment"
        ]
    ],
    "fields": [
        {
            "display_name": "Ticker Symbol",
            "format": "ticker",
            "metric": false,
            "id": "dataset__entity__entity_ticker__ticker__ticker",
            "length": 320,
            "summary": "The full ticker symbol, defined as the financial market of the company, followed by a colon (:), and then the identifier of the company. ex. NASDAQ:AAPL",
            "type": "string",
            "options": []
        },
        ...
        {
            "display_name": "GICS Industry",
            "format": null,
            "metric": false,
            "id": "dataset__entity__entity_ticker__ticker__market_industry",
            "length": 64,
            "summary": "The gics industry within the sector a ticker belongs to",
            "type": "string",
            "options": []
        }
    ],
    "sort_fields": [],
    "start": 1,
    "state": "complete",
    "limit": 10,
    "last_date_updated": "2021-04-01T02:34:56Z"
}