M.App Enterprise Discussions

Discuss topics with other M.App Enterprise Product pioneers and experts to get the most out of it.
Showing results for 
Search instead for 
Do you mean 
Reply
Frequent Contributor
Posts: 123
Registered: ‎07-25-2018
Accepted Solution

Accessing MAE Query API externally

 

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

 

 

 

Technical Evangelist
Posts: 29
Registered: ‎04-04-2018

Re: Accessing MAE Query API externally

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

Frequent Contributor
Posts: 123
Registered: ‎07-25-2018

Re: Accessing MAE Query API externally

[ Edited ]

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

Technical Evangelist
Posts: 9
Registered: ‎05-28-2019

Re: Accessing MAE Query API externally

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);

Frequent Contributor
Posts: 123
Registered: ‎07-25-2018

Re: Accessing MAE Query API externally

 

 

Thanks very much David.

 

Yes it is working now.

 

Regards,

Sreedevi

Frequent Contributor
Posts: 123
Registered: ‎07-25-2018

Re: Accessing MAE Query API externally

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