code": 498, "message": "Invalid token.

668
5
01-02-2022 07:58 PM
naveenbesri
Occasional Contributor

Hi All,

When i try to get arcgis portal users with below rest url in the code level. Im getting below error

function _verifyUserRole(username, token) { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = () =>{ if(xhttp.readyState == XMLHttpRequest.DONE) { var jsonResponse = JSON.parse(xhttp.responseText); } }; xhttp.open("GET", "https://domainname/portal/sharing/rest/portals/0123456789ABCDEF/users?username="+username+"&f=pjson&referer=https://domainname&token=" + token, true);
xhttp.send(); }
 

"{"error": { "code": 498, "message": "Invalid token.", "details": [] }}"

But when i try to access the same url in the browser im getting response. 

 

Could you please help me on this. 

Thanks.

0 Kudos
5 Replies
Kishore
Occasional Contributor

@naveenbesri - try to send the token in the request header like below:

xhttp.setRequestHeader("token", token);

 

Regards,
Kishore
0 Kudos
naveenbesri
Occasional Contributor

Hi Kishore,

Now error is gone but we are not getting response and getting below

naveenbeti_0-1641198453342.png

 getting cors error. 

0 Kudos
Kishore
Occasional Contributor

@naveenbesri - try with following

xhttp.setRequestHeader('Access-Control-Allow-Origin','*');

 

Hope your server has CORS enabled...

Regards,
Kishore
0 Kudos
naveenbesri
Occasional Contributor

I tried this before but no luck getting same issue. 

0 Kudos
mistersig_cc
New Contributor II

Did you ever figure this out?

0 Kudos