0
votes

I followed this tutorial [https://blog.vgrem.com/2015/01/27/consuming-the-sharepoint-online-rest-api-from-powershell-part-2/][1]

The above link showed how to get the token and how to call the rest API in SharePoint online using powershell, but the problem is. I am getting a

403 Forbidden error when the endpoint is

$WebUri = "https://mycustomname.sharepoint.com"
$endpointUri = "$WebUri/sites/VirtualName/_api/web/lists/getbytitle('$ListTitle')"

When I changed the endpoint to the below I get 401 Unauthorized

$endpointUri = "$WebUri/sites/VirtualName/lists/getbytitle('$ListTitle')"

The permission XML I tried a few different links int he scope but nothing helped. Appdomain - localhost Redirect URl - https://mycustomname.sharepoint.com/sites/VirtualName

<AppPermissionRequests AllowAppOnlyPolicy="true">  
   <AppPermissionRequest Scope="https://mycustomname.sharepoint.com/sites/VirtualName/Lists/mylistname" 
    Right="Manage" />
</AppPermissionRequests>

Any help will be greatly appreciated.

1

1 Answers

0
votes

The app permission request scope url could only be these:

  1. http://sharepoint/content/tenant

  2. http://sharepoint/content/sitecollection

  3. http://sharepoint/content/sitecollection/web

  4. http://sharepoint/content/sitecollection/web/list enter image description here add-in-permissions-in-sharepoint

    $username = "[email protected]"
    $password = "Password"
    $cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $userName, $(convertto-securestring $Password -asplaintext -force)
    Connect-SPOService -Url https://contoso-admin.sharepoint.com -credential $cred
    Set-SPOTenant -DisableCustomAppAuthentication $false