How to get the Orchestrator token via OAuth for a NodeJs - Axios application?

Hey guys,

i am trying to implement a post method on our webpage to start the roboter.
i cant get the token and then go further.

I tried it with postman → No problems. Got the token and i can start the roboter via postman.

But in Nodejs via axios i just get status 200 and in the data object a html page as a return.

I tried using grant_type as “client_credentials” and many other.

What am i doing wrong?

const { default: axios } = require('axios');

axios
  .post(
    'http://cloud.uipath.com/quantjljabnl/Quantum/identity/connect/token',
    {
      grant_type: 'refresh_token',
      client_id: '998dc874-7f0f-463e-a4a1-XXXXXXXXXXXX',
      client_secret: '5!sI^M!KXXXXXXXX',
      scope:
        'OR.Administration OR.Analytics OR.Assets OR.Audit OR.BackgroundTasks OR.Execution OR.Folders OR.Hypervisor OR.Jobs OR.License OR.Machines OR.ML OR.Monitoring OR.Queues OR.Robots OR.Settings OR.Tasks OR.TestDataQueues OR.TestSetExecutions OR.TestSets OR.Users OR.Webhooks',
    },
    {
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
        'Content-Security-Policy': '*',
        'Access-Control-Allow-Origin': '*',
      },
    }
  )
  .then((data) => {
    console.log('Data: ', data);
  })
  .catch((err) => {
    console.error('Error: ', err);
  });

That is what i get back

data: '<!DOCTYPE html>\n' +
    '<html lang="en">\n' +
    '<head>\n' +
    '    <meta charset="utf-8" />\n' +
    '    <meta http-equiv="X-UA-Compatible" content="IE=edge" />\n' +
    '    <meta name="viewport" content="width=device-width, initial-scale=1" />\n' +
    '    <meta name="description" content="" />\n' +
    '    <meta name="author" content="" />\n' +
    '    <meta name="referrer" content="no-referrer" />\n' +
    '\n' +
    '    <base href="/quantjljabnl/Quantum/orchestrator_/" />\n' +
    '\n' +
    '    <title>UiPath Orchestrator </title>\n' +
    '    <link rel="shortcut icon" href="favicon.ico" />\n' +
    '    <script type="text/javascript" src="js/redirect.js" nomodule></script>\n' +
    '\n' +
    '\n' +
    '        <script type="text/javascript" src="https://orch-cdn.uipath.com/client/dist/assets/js/preload.js"></script>\n' +
    '\n' +
    '        <link rel="stylesheet" href="/portal_/apollo/packages/apollo-fonts/1/font.css?spaceName=orchestrator" />\n' +
    '        <script type="module" src="/portal_/apollo/packages/portal-shell/2/portal-shell.esm.js?spaceName=orchestrator"></script>\n' +
    '\n' +
    '</head>\n' +
    '<body class="light apollo-design" data-cdn-url="https://orch-cdn.uipath.com/client" data-build-version="2022.5.0-s95.1752">\n' +
    '    <portal-sheet>\n' +
    '        <ui-app>\n' +
    '            <div class="loader-container">\n' +
    '                <svg class="loader-animation"\n' +
    '                        width="400"\n' +
    '                        height="400"\n' +
    '                        viewBox="0 0 400 400"\n' +
    '                        xmlns="http://www.w3.org/2000/svg">\n' +
    '                    <path class="animated-path"\n' +
    '                            d="M32,48H352V368"\n' +
    '                            fill="none"></path>\n' +
    '                    <path class="animated-path"\n' +
    '                            d="M368,352H48V32"\n' +
    '                            fill="none"></path>\n' +
    '                </svg>\n' +
    '            </div>\n' +
    '\n' +
    '            <span class="material-icons-outlined" style="position:absolute; font-size: .1px; color: transparent">people</span>\n' +
    '        </ui-app>\n' +
    '    </portal-sheet>\n' +
    '    <script type="text/javascript" src="dist/assets/cdn.js?version=2022.5.0-s95.1752"></script>\n' +
    '</body>\n' +
    '</html>\n'
}
1 Like

The Auth and Token URL for Cloud I believe should be

https://cloud.uipath.com/identity_/connect/authorize
https://cloud.uipath.com/identity_/connect/token

A working example for refresh_token is this one:

For client_credentials, the below will work:

First of all, thank you for the reply.
But as i mentioned in my first post → I am able to get the token via postman but not with node.js.
What redirecturl should it be, if i want to use nodejs on my local pc ?
Could someone give me a working snippets in node.js please ?

Thank you for the reply.
I tried these links and i get the same html as a data object back with status 200.
Could you please give me a working snippets in nodejs ?

The generated code from Postman:

var axios = require('axios');
var qs = require('qs');
var data = qs.stringify({
  'grant_type': 'client_credentials',
  'client_id': 'YOUR_CLIENT_ID',
  'scope': 'OR.License OR.Robots OR.Jobs OR.Settings OR.Assets OR.Robots OR.Folders OR.Execution OR.Monitoring OR.Administration OR.Queues',
  'client_secret': 'YOUR_CLIENT_SECRET' 
});
var config = {
  method: 'post',
  url: 'https://cloud.uipath.com/identity_/connect/token',
  headers: { 
    'Content-Type': 'application/x-www-form-urlencoded'
  },
  data : data
};

axios(config)
.then(function (response) {
  console.log(JSON.stringify(response.data));
})
.catch(function (error) {
  console.log(error);
});

i am getting back Bad request → invalid scope??
i copy pasted the scope from the button “Copy scope” in external application.

Also what should i type into Redirect URL?

Should it be application scope or user scope?
i selected application scope

If it is a Confidential application with Application Scopes, you can leave the redirect URL empty.

Example:

i have the same settings as you. Why am i getting “invalid scope” ?
This is my scope :

scope:
‘OR.Administration OR.Administration.Read OR.Administration.Write OR.Analytics OR.Analytics.Read OR.Analytics.Write OR.Assets OR.Assets.Read OR.Assets.Write OR.Audit OR.Audit.Read OR.Audit.Write OR.BackgroundTasks OR.BackgroundTasks.Read OR.BackgroundTasks.Write OR.Execution OR.Execution.Read OR.Execution.Write OR.Folders OR.Folders.Read OR.Folders.Write OR.Hypervisor OR.Hypervisor.Read OR.Hypervisor.Write OR.Jobs OR.Jobs.Read OR.Jobs.Write OR.License OR.License.Read OR.License.Write OR.Machines OR.Machines.Read OR.Machines.Write OR.ML OR.ML.Read OR.ML.Write OR.Monitoring.Read OR.Queues OR.Queues.Read OR.Queues.Write OR.Robots OR.Robots.Read OR.Robots.Write OR.Settings OR.Settings.Read OR.Settings.Write OR.Tasks OR.Tasks.Read OR.Tasks.Write OR.TestDataQueues OR.TestDataQueues.Read OR.TestDataQueues.Write OR.TestSetExecutions OR.TestSetExecutions.Read OR.TestSetExecutions.Write OR.TestSets OR.TestSets.Read OR.TestSets.Write OR.TestSetSchedules OR.TestSetSchedules.Read OR.TestSetSchedules.Write OR.Users OR.Users.Read OR.Users.Write OR.Webhooks OR.Webhooks.Read OR.Webhooks.Write’,

You have too many scopes, and because of that, it will fail as the scope is invalid.

For example, you have OR.Administration OR.Administration.Read OR.Administration.Write. This is not a good approach as the OR.Administration includes the OR.Administration.Read and OR.Administration.Write permissions.

Look at my example from above and do the same.

Let us know if this helped.

Oh, well. I didn’t know this.
Thank you very much. I selected as the scope “OR.Administration” and i got the access token :slight_smile:

So now that i am able to get the token as a response like your code … How am i able to start a Robot ? i hope i am not asking to much :frowning: .
I read several documentation but unfortunately they are not up to date or confusing.

Thanks for the update. Mark as a solution the correct post in this thread that helped to solve your requirement.

For the other requirement, first look in the Forum thread posts to see if somebody else faced the same requirement, if not, raise a new thread post.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.