Analytics Rest API - Returning Empty JSON even with status 200

I’ve been trying to use Algolia’s rest-api with python request but even though im getting a status 200, my json always returns None ie: {‘countries’: None}. Here is the documentation Analytics REST API Reference | Algolia . The python api exists but for the analytics section you need to use the rest-api, here is the python api: algoliasearch-client-python/ at master · algolia/algoliasearch-client-python · GitHub

I tried looking at the headers in the python api to see if it would help.

Here is an example curl requests from the documentation:

 curl -X GET \
     -H "X-Algolia-API-Key: ${API_KEY}" \
     -H "X-Algolia-Application-Id: ${APPLICATION_ID}" \
    "${index name}" 

Here is my code using requests:

import requests
from datetime import date
import json

class AutoAlgolia():
    def __init__(self, api_key, application_id, index_name):
        self.api_key = api_key
        self.application_id = application_id
        self.index_name = index_name
    def _headers(self):
        header = {
                'X-Algolia-API-Key': self.api_key,
                'X-Algolia-Application-Id': self.application_id ,
                "Content-Type": "application/json"
        return header

    def getsearches(self):
        header = self._headers()
        today =
        session = requests.Session()
        url = "" + self.index_name + "&startDate=" + today + "&endDate=" +"2022-09-03" 
        req = session.get(url, headers=header)
        data = req.json()
if __name__ == "__main__":
    algolia = AutoAlgolia(api_key="key
", application_id="id", index_name="si_SOLUTIONS")

    a = algolia.getsearches()
    print(a) `

I also checked using req.headers what could be wrong but i do not fully understand it:

{'Date': 'Thu, 01 Dec 2022 16:17:00 GMT', 'Content-Type': 'application/json', 'Content-Length': '17', 'Connection': 'keep-alive', 'Access-Control-Allow-Origin': '', 'Vary': 'Origin', 'X-Ratelimit-Limit': '100', 'X-Ratelimit-Remaining': '99', 'X-Ratelimit-Reset': '1669911480', 'Via': '1.1 google', 'CF-Cache-Status': 'DYNAMIC', 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains; preload', 'Server': 'cloudflare', 'CF-RAY': '772d216aaf1001db-ZRH'} ```

Could it be the access-control-allow-origin which is empty?

Thank you, I greatly appreciate any help

Using different headers, reading the python api doc to see if there could be any similarities to the rest api, tried urllib3 (same result), tried other webhooks from the rest api.

@ariele.sgheiza your code works for me and one of my test indexes. I noticed in the URL parameters you are filtering by today’s date but ending on a date in the past. I tested this and if you do this, the system won’t return results which may be what you are running into.

For example:

> {'searches': None}

> {'searches': [{'search': '...', 'count': 2, 'withFilterCount': 0}, ...]}

I also noticed your post above mentioned a response that included countries: [], but this endpoint doesn’t seem to do that so I may be missing something.

Get Top Countries endpoint (documentation)

Let me know, happy to help further, thanks!

Sorry, I agree the start and end date were wrong. I deleted my other post, but I guess this got double posted. The issue was very silly, our servers are in germany and therefore the base link for the webhook is slightly different as it includes .de inside it.