Help With SharePoint Online REST API - HTTP Request Authentication

Hi All,
I am fairly new to RPA development and a complete novice at APIs. However, what I need to do is fairly simple and I am hoping you guys will be able to help me.

I am trying to create a robot for an internal process. I need to get list items (values in a particular column) from a SharePoint online list.

I tried the REST API URL directly in the browser and it works when I am signed into SP Online.
I am trying to do the same now with the UiPath HTTP request activity.

However, I am having trouble setting up the request builder.
I don’t know how to setup the authentication for an API.

The request URL is as below:

https://<Company>.sharepoint.com/sites/LostPackages/_api/web/lists/getbytitle('LostPackagesDB')/items?select=<ColumnName>

This URL works when I directly paste it the browser when I am signed in on SP Online.

However, when I try it with UiPath HTTP Request Activity, I get the following error:

<m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
  <m:code>-2147024891, System.UnauthorizedAccessException</m:code>
  <m:message xml:lang="en-US">Attempted to perform an unauthorized operation.</m:message>
</m:error>

Can someone please help me with setting up one of the Authentication methods and the query.
I tried the Simple HTTP authentication with my username and password but got the same error.

So now it looks like I either need to use the OAuth1 or the OAuth2 authentication method. And I how no idea on how to do either. Some guidance on how to setup the authentication for either of the 2 methods would be really appreciated.

Best Regards,
Achal Desai

@Achal_Desai

Instead of trying with REST API, why don’t you try Sharepoint Activities?

Install the above package from Manage Package and you can use different activities

Else for REST API

Check as below

“http:///_api/web/lists” - ENDPoint
endpointRequest.Method = “GET”; → Select Get
endpointRequest.Accept = “application/json;odata=verbose”;
“Authorization” = "Bearer " + accessToken);

Bearer Should be added before the access Token

Hope this may help you

Thanks

Thanks @Srini84, I will try the activity and let you know the results.
But out of curiosity and future use, how do I get the Bearer and Access Token?

@Achal_Desai

Bearer is just a string no need of getting from anywhere

Acces token can be get from the sharepoint app

Check above for getting the access token

So you need to provide as below

Header Name - “Authorization” = “Bearer” +" "+ YourAccessToken

Hope this may help you

Thanks

Thanks @Srini84, but looks like I will not be able to get the access token.
I do not have admin rights.
But thanks for the help anyway.

@Achal_Desai

If access token is not provided then you can proceed with REST API
because Sharepoint is not a public site

Even to use the activities you need the login password correctly with some rights

If this answers your questions, Close this thread by clicking on Mark As Solution

Thanks

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