title: Azure Data Factory 401 error when calling GET request on SharePoint online API
body: <p>I am trying to move files between Azure Data Factory and SharePoint Online.</p>
  <p>I have some test data files in a SharePoint location and I have a pipeline in Data factory containing a Web Activity and a Copy data activity. The copy activity then links to a Data Lake as its sink.</p>
  <p>My <strong>desired outcome</strong> is for the Copy Data activity to be granted access to the SharePoint Online API and then proceed to move the retrieved data into the data lake. As is stands it has the bearer token but cant access the data through the SharePoint Online API.</p>
  <p>I have followed the Microsoft guide <a href="https://docs.microsoft.com/en-us/azure/data-factory/connector-sharepoint-online-list" rel="nofollow noreferrer">here</a>, including the prerequisites.</p>
  <p>I am getting the following error in Data Factory:
  <code>Error code 2200</code>
  <code>&quot;Failure happened on 'Sink' side. ErrorCode=UserErrorInvalidCredentialToReadHttpFile,'Type=Microsoft.DataTransfer.Common.Shared.HybridDeliveryException,Message=The credential to read http file is invalid.,Source=Microsoft.DataTransfer.ClientLibrary,''Type=System.Net.WebException,Message=The remote server returned an error: (401) Unauthorized.,Source=System,</code></p>
  <p>The error is present on the Copy data activity (Which uses a HTTP linked service), <strong>not the web activity</strong>. Therefore I am successfully getting a bearer token which is passed to the Copy data activity, only to be denied.</p>
  <p>Troubleshooting:</p>
  <ul>
  <li><p>I have assigned Owner role access to the data factory for the data
  lake.</p>
  </li>
  <li><p>I have registered the service principal App as per the prerequisites
  in the Microsoft guide above, successfully using the Application ID,
  Key and Tenant Id to access the bearer token</p>
  </li>
  <li><p>I have granted SharePoint online <strong>full</strong> access to the registered
  service app, successfully, as I can see it listed in the trusted apps in SharePoint. I did so not
  only here:
  <code>https://my_company.sharepoint.com/_layouts/15/appinv.aspx</code> but here
  <code>https://my_company.sharepoint.com/sites/folder/_layouts/15/appinv.aspx</code></p>
  </li>
  <li><p>I have granted full API permissions to SharePoint and Microsoft Graph
  in the registered Service app.</p>
  </li>
  <li><p>I have replicated the process in Postman. Only to have the same
  results - I retrieve a bearer token and then get 401 error when
  trying calling a GET request for the files, using the bearer token.
  The error in Postman is: <code>{&quot;error_description&quot;:&quot;Exception of type 'Microsoft.IdentityModel.Tokens.AudienceUriValidationFailedException' was thrown.&quot;}</code></p>
  </li>
  </ul>
  <p>I 've read that an alternative OData linked service in Data Factory is not possible using using basic authentication here. So I have tried <a href="https://social.msdn.microsoft.com/Forums/en-US/85ab91ef-0336-4832-b750-2ed007b030a9/access-sharepoint-list-data-using-adf?forum=AzureDataFactory" rel="nofollow noreferrer">this article</a> using AAD service principal with cert, but had further problems trying to generate a certificate. Perhaps this is my best bet.</p>
  <p>Most relevant posts I've used:</p>
  <p><a href="https://stackoverflow.com/questions/39512605/how-to-move-sharepoint-list-or-excel-file-to-azure-sql-dw">How to move sharepoint list or excel file to azure sql dw?</a></p>
  <p><a href="https://docs.microsoft.com/en-us/answers/questions/109275/copy-file-from-sharepoint-not-working.html" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/answers/questions/109275/copy-file-from-sharepoint-not-working.html</a></p>
  <p><a href="http://www.ktskumar.com/2017/01/access-sharepoint-online-using-postman/" rel="nofollow noreferrer">http://www.ktskumar.com/2017/01/access-sharepoint-online-using-postman/</a></p>
  <p><a href="https://stackoverflow.com/questions/54868998/azure-data-factory-and-sharepoint">Azure Data Factory and SharePoint</a></p>