09-30-2019 01:40 AM
Hello Community,
I have a custom application that is deployed under M.App website. It has the same hostname as M.App enterprise. When it loads, it logins to MAE using the standard login and stores the token in local storage.
I need to call the MAE Query API in one of the button click event from my code.But it is giving me 401 unauthorized error. I am using an ajax call to the Query API URL and pass the token as a header to it.
I have attached a screenshot of the code i am using to test the Query api. Can anyone please help me figure out what I am missing here?
Regards,
Sreedevi
Solved! Go to Solution.
10-01-2019 06:53 AM
Hi Sreedevi,
You also need to pass the Tenant in the header as well. Here's a snippet of what I use as part of the ajax call:
$.ajax({... beforeSend: function (xhr) { xhr.setRequestHeader('Authorization', 'Bearer ' + "MY BEARER TOKEN"); xhr.setRequestHeader('Tenant', "MY TENANT"); }
...});
Hope this helps
10-02-2019
06:38 AM
- last edited on
10-04-2019
08:37 AM
by
DaveOke
Thank you David,
I am still getting 401 error.
Below is the token format i pass to the header.
{"access_token":"----bearer token----","token_type":"bearer","expires_in":899,"refresh_token":"bf10db17-3fce-4957-ba19-d0304519cbd9","userId":"0a7d6124-f729-49ec-899f-4ff6ff1bbe4a","userName":"uat","userFullName":"M.App Enterprise Studio Account","userEmail":"sramanujan@imgs.ie","userLanguage":"en","isRightToLeftLanguage":"false","sessionId":"08afec29-cf15-41b0-8973-bdc5f3e637b9","initialRecharge":"false","invalidLicense":"None","client_id":"App","accountName":"IMGS - Irish Mapping and GIS Solutions","isActiveDirectory":"true","runtimeLicense":"false",".issued":"Wed, 02 Oct 2019 13:36:12 GMT",".expires":"Wed, 02 Oct 2019 13:51:12 GMT","expiration_date":1570024272213}
Regards,
Sreedevi
10-04-2019 08:39 AM
Hi Serrdevi,
Just edited your reply to remove the bearer token so it's not in public domain.
You're close - instead of passing the entire object, just pass the access_token value.
xhr.setRequestHeader('Authorization', 'Bearer ' + yourObj.access_token);
10-04-2019 08:40 AM
Thanks very much David.
Yes it is working now.
Regards,
Sreedevi
10-08-2019 04:27 AM
Hello Community,
Can I extend the expiration of MAE access_token?
Or getting a new accesss token using refresh token the only way to extend it?
Regards,
Sreedevi