0

How I can Start an UiPath Process on UiPath Robot from the Salesforce interface? I know that Salesforce can send REST API commands to other software.

1 Answers1

0

I tried to do exactly the same thing, like you in your movie on YouTube. Please, can you look on my/Your apex code bellow, and maybe help me. Thanks!!

  {
            //@future(callout=true)
            public static void startProcess(String param1,String param2)
            {
                Http http = new Http();
                HttpRequest rm = new HttpRequest();
                rm.setEndpoint('https://account.uipath.com/oauth/token');
                rm.setMethod('POST');
                rm.setHeader('Content-Type', 'application/json');
                rm.setHeader('X-UIPATH-TenantName', 'ioDefault');
                //rm.setTimeout(60000);

                JSONGenerator gen = JSON.createGenerator(true);  
                gen.writeStartObject();
                gen.writeStringField('grant_type','refresh_token');
                gen.writeStringField('client_id','8DEv1AMNXczW3y4U15LL3jYf62jK93n5');
                gen.writeStringField('refresh_token','2I7ZERqOZHFmzVzyPUE_sdf-l-dGa4086xN8fyrW-xF8-');
                gen.writeEndObject();
                rm.setBody(gen.getAsString());

                HttpResponse rs = http.send(rm);

                System.debug(rs.getBody());

                Map<String,Object> res = (Map<String,Object>)JSON.deserializeUntyped(rs.getBody());
                System.debug(String.valueOf(res.get('access_token')));

                HttpRequest rm2 = new HttpRequest();
                rm2.setMethod('POST');
              rm2.setEndpoint('https://platform.uipath.com/zuhtkqf/ioDefault/odata/Jobs/UiPath.Server.Configuration.OData.StartJobs');
                rm2.setHeader('Content-Type', 'application/json');
                rm2.setHeader('X-UIPATH-TenantName', 'ioDefault');
                rm2.setHeader('Authorization', 'Bearer '+String.valueOf(res.get('access_token')));
                //rm2.setTimeout(60000);

                JSONGenerator gen2 = JSON.createGenerator(true);  
               /// start a simple process without parameters
                gen2.writeStartObject();
                gen2.writeFieldName('startInfo');
                gen2.writeStartObject();
                gen2.writeStringField('ReleaseKey','6aa09f52-ef47-47aa-ab2e-8e487e7841e5');
                gen2.writeStringField('Strategy','All');
                gen2.writeEndObject();
                gen2.writeEndObject();

               /// start a simple process with parameters        
               /* gen2.writeStartObject();
                gen2.writeFieldName('startInfo');
                gen2.writeStartObject();
                gen2.writeStringField('ReleaseKey','YOUR release KEY for process see the YouTube movie below');
                gen2.writeStringField('Strategy','All');
                gen2.writeStringField('InputArguments','{\"param1\":\"'+param1+'\",\"param2\":\"'+param2+'\"}');
                gen2.writeEndObject();
                gen2.writeEndObject();
*/
                rm2.setBody(gen2.getAsString());

                HttpResponse rs2 = http.send(rm2);

                System.debug(rs2.getBody());
            }
        }
Kamil
  • 59
  • 7
  • Hello Kamil, first why You comment SetTimeOut because in my case I have issues without that stuff. Next the same stuff with commenting the future(callout=true) I don't remember to be just a copy-paste. This procedure is complex so I highly recommend to everything from postman first time and by sure that the UiPath REST API part is working. Last stuff try to put more System.Debug lines and after you run you can open Salesforce Development explorer and check to see only the debug only and you can see your steps very well. – Cristian Negulescu Apr 24 '20 at 05:53
  • And please revoke your refresh token as it is now potentially known of any person with an internet connection... – Quentin Apr 27 '20 at 05:35