question

Upvotes
Accepted
1 0 1 3

Status code 401 - unauthorized / token expired

I am trying to access the /search/beta1 in the Elektron Data Platform for a small proof of concept I am building. I've generated the app key and am including it in the Authorization header in the request. However, when I go to fetch from my front-end, I am being returned an error object that looks like so:

{
  code: "401",
  id: "e02f9ec2-2986-49d5-ab62-9d066539c9ce",
  message: "token expired",
  status: "Unauthorized"
}


I am just trying to fetch the same results that is included in the api playground, so my fetching looks like this:


export async function fetchRef() {
    const url = 'https://api.refinitiv.com/search/beta1/';
    const key = '9e2708*********b85abce1f4';
    const response = await fetch(url, {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            Authorization: "Bearer " + key,
        },
        body: JSON.stringify({
            View: "People",
            Query: "cto microsoft"
        })
    });
    const json = await response.json();
    console.log(json);
}


Is there something I am doing wrong? I cannot seem to find any documentation that would tell me otherwise. I inspected the request that is sent from the api playground, and I noticed the "key" is a much longer one that I was provided in the generator. Am I using the wrong key, and where would I get this new key?

Thank you in advance for your help!

elektron-sdkrdp-apirefinitiv-data-platformsearchjavascript
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Upvotes
Accepted
13k 32 12 18

Hi @justin.mckenzie, You seem to be using the Refresh Token instead of Access Token in your request. Please see the EDP tutorials and download the working code samples in Python or Postman.

PS: This is a public forum, so do not post credentials in the posts. I have removed the key from your question.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Hi Gurpreet thanks for your reply. Am I able to do this with a simple frontend (receive authorization tokens and then use them in subsequent requests) or will I need to use a Node or Python back end to be able to do so?

Upvotes
13k 32 12 18

EDP supports Authorization Code and Implicit grant, which can be used in the browser based applications.

API Playground is implemented using Implicit grant.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Upvotes
9.5k 10 5 7

Hello @justin.mckenzie

For more details about tokens, requests and responses, please see Authorization - All about tokens tutorial

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Click below to post an Idea Post Idea