SAP Knowledge Base Article - Public

2943554 - Source file update via Roambi API fails with error (401) Not Authorised

Symptom

Updating source files with Roambi API starts failing

The error in tomcat logs is similar to:

System.Net.WebException: (401) Not Authorised

Environment

Roambi Cloud

Reproducing the Issue

Example:

When using this code:

static string accountID(string tokenvar)
        {
            // Setup the variables necessary to make the Request
            HttpWebResponse response = null;
            try
            {
                // Create the data to send
                string _cred = "Bearer " + tokenvar;
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://api.roambi.com/1/user/resources");
                request.Headers.Add("Authorization", _cred);
                request.Method = "GET";
                response = (HttpWebResponse)request.GetResponse();
                using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                {
                    // Get the Response Stream
                    string json = reader.ReadLine();
                    Console.WriteLine(json);
                    int first = json.LastIndexOf("uid") + "uid".Length + 3;
                    int last = json.LastIndexOf("title") - 3;
                    string str2 = json.Substring(first, last - first);
                    return str2;
                }
            }

- Error response on get https://api.roambi.com/1/user/resources");

- Manual upload via browser works, but error appears before getting to the upload

Cause

The problem is in the method token inthe Example above.

When running:

first = json.IndexOf("access_token") + "access_token".Length + 3;

last = json.LastIndexOf("expires_in") - 3;
str2 = json.Substring(first, last - first);

Looking at the output of earlier runs it can be seen that json is set to something like:

{"access_token":"XXX","token_type":"bearer","refresh_token":"YYY","expires_in":86400}

This will cause the "string between access_token and expires_in".

By logging this:

Console.WriteLine("Access token");

Console.WriteLine(str2);

It is visible that this is something like:

XXX","token_type":"bearer","refresh_token":"YYY

which is not correct, as only the access is needed

Resolution

In this case the string between access_token and token_type is needed.

Example:

Changing

last = json.LastIndexOf("expires_in") - 3;

to

last = json.LastIndexOf("token_type") - 3;

Makes it possible to get the user id with the Example script above.

However, this fix is not the correct way to go.

The returned result is in JSON. JSON does not guarantee the order of elements.

SOLUTION:

The JSON needs to be parsed correctly.

Obtain the access_token element instead of handling the result as string.

For further details please have a look at the Roambi API documentation at https://help.sap.com/doc/688d649621184199903ae22642ee9710/9.1/en-US/SAP%20BusinessObjects%20Roambi%20Cloud%20-%20API%20Documentation.pdf

Keywords

KBA , BI-ROM-CLD-SRC , Roambi Cloud Service , Problem

Product

SAP BusinessObjects Roambi, cloud edition 71