question

Upvotes
Accepted
1 2 2 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 512.0 KiB each and 1.0 MiB total.

@justin.mckenzie,

Thank you for your participation in the forum.

Are any of the replies below satisfactory in resolving your query?

If yes please click the 'Accept' text beneath the most appropriate reply. This will guide all community members who have a similar question.

Otherwise please post again offering further insight into your question.

Thanks, AHS

Please be informed that a reply has been verified as correct in answering the question, and has been marked as such.

Thanks,

AHS

Upvotes
Accepted
22k 58 14 21

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 512.0 KiB each and 1.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
22k 58 14 21

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 512.0 KiB each and 1.0 MiB total.

Upvotes
9.6k 10 7 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 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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