Select to view content in your preferred language

API works on Web Browsers but not the Mobile App

596
0
09-04-2023 09:16 AM
AdomasVensas
New Contributor

Hello,

I've recently integrated our company's REST API into a survey to retrieve calculation results based on coordinates. For the API to function, I need both an ESRI token and a company token.

This setup works seamlessly on web browsers, including mobile web browsers. However, I'm facing issues when using the Survey123 app from the PlayStore. While the ESRI API call functions as expected on the mobile app, our company's API does not.

To troubleshoot, I created a test project that returns only the API response code. In the app, this returned a value of 0. I believe this might indicate that either the API call was prematurely terminated or that JavaScript defaulted to 0 and skipped the API call.

This is the code I'm using:

function getToken(username, esriToken)
{
    const url = `theurl`;
    const data = {
        type: "esri",
        username: username,
        token: esriToken
    };

    var xhr = new XMLHttpRequest();
    xhr.open('POST', url, false);
    xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
    xhr.send(JSON.stringify(data));

    if (xhr.status !== 200)
    {
        throw new Error(xhr.responseText);
    }

    return JSON.parse(xhr.responseText).token;
}

 

Does anyone have suggestions or insights on how to address this issue?

Tags (3)
0 Kudos
0 Replies