Why does my requests.get() call ignore filters when querying the headlines endpoint?

dev_jan
dev_jan Newcomer

I’m trying to fetch all English news related to RCS code (LEN AND (U:C)) within a specific timeframe using the headlines endpoint.

Here’s an example of the request I send with requests.get():

https://api.refinitiv.com/data/news/v1/headlines?dateFrom=2025-08-14T22:00:00Z&dateTo=2025-08-14T22:42:57Z&query=LEN%20AND%20%28U%3AC%29

I also have a recursive function to handle pagination tokens and fetch the next page of results.

The problem:

  • When I test the same query in the API playground, I only get around 20 results, all correctly within the timeframe.
  • But when I use my Python script with requests.get(), I end up with 7,000+ results, including news outside of the timeframe and unrelated RCS codes.

So it seems like the query parameters (dateFrom, dateTo, and query filters) are not being applied correctly in my request.

Question:
Why does my requests.get() call return results outside the specified filters, and what’s the correct way to ensure the filters (date range + RCS code) are applied?

Answers

  • Jirapongse
    Jirapongse ✭✭✭✭✭

    @dev_jan

    Thank you for reaching out to us.

    I tested it with the following code and it returned 633 headlines within the range.

    import requests
    
    url = "https://api.refinitiv.com/data/news/v1/headlines?dateFrom=2025-08-14T22:00:00Z&dateTo=2025-08-14T22:42:57Z&query=LEN%20AND%20%28U%3AC%29&limit=100"
    
    token = "<token>"
    payload = {}
    headers = {
        'Authorization': 'Bearer '+token
    }
    total = 0
    response = requests.request("GET", url, headers=headers, data=payload)
    
    count = response.json()['meta']['count']
    print(count)
    if len(response.json()['data'])>0:
        print(response.json()['data'][0]['newsItem']['itemMeta']['firstCreated'])
        print("...")
        print(response.json()['data'][-1]['newsItem']['itemMeta']['firstCreated'])
       
    
    total = total + count
    cursor = response.json()['meta']['next']
    while cursor != '':
        payload = {'cursor': cursor}
        response = requests.get("https://api.refinitiv.com/data/news/v1/headlines", payload, headers=headers)
        count = response.json()['meta']['count']
        print(count)
        if len(response.json()['data'])>0:
            print(response.json()['data'][0]['newsItem']['itemMeta']['firstCreated'])
            print("...")
            print(response.json()['data'][-1]['newsItem']['itemMeta']['firstCreated'])
       
    
        total = total + count
        cursor = ''
        if 'next' in response.json()['meta']:
            cursor = response.json()['meta']['next']
    
    print("Total headlines:"+str(total))
    
    image.png