web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

System.ServiceModel.FaultException Mensaje = The remote server returned 401 unauthorized error

(2) ShareShare
ReportReport
Posted on by 21
A few days ago, a CodeActivity that was running on different clients to create custom SharePoint folders and locations stopped working, throwing this error. We opened a support ticket, but they haven't provided a solution.
In some cases, setting the workflow to real-time works, but, for example, if it's run by an application user, there's no way to get it working.
Normally, we had the WF running in the background to create the records and then create the folders.
 
 
The code imitates the requests that CRM makes if we do it from the documents section, whether we create a location or a folder.
Categories:
I have the same question (0)
  • Suggested answer
    Holly Huffman Profile Picture
    6,530 Super User 2025 Season 2 on at
    Hi there! Good morning, evening, or afternoon - depending on where you are :) Hope you are well today! 
     
    The error message "System.ServiceModel.FaultException: The remote server returned 401 unauthorized error" typically indicates an authentication issue when attempting to access SharePoint resources. Here's how you can troubleshoot and resolve this problem:

    1. Verify Authentication Credentials
    • Ensure that the credentials used by the application user or workflow have the necessary permissions to access SharePoint.
    • If you're using an application user, confirm that it has the correct API permissions in Azure Active Directory (e.g., Sites.ReadWrite.All).
    2. Check SharePoint Permissions
    • Verify that the application user or service account has been granted access to the SharePoint site, document library, or folder.
    • Ensure that the user or account is added to the appropriate SharePoint group with sufficient permissions.
    3. Update CodeActivity
    • Review the code that imitates CRM requests to SharePoint. Ensure that it includes proper authentication headers and tokens.
    • If you're using OAuth, confirm that the access token is valid and not expired.
    4. Real-Time Workflow Considerations
    • Real-time workflows may work because they execute in the context of the user who triggers them. Background workflows, however, may use the application user or service account, which could lack permissions.
    • If possible, configure the workflow to run in the context of a user with sufficient permissions.
    5. Enable Logging
    • Enable detailed logging in your CodeActivity to capture the exact request and response from SharePoint. This can help identify the root cause of the 401 error.
    6. Test API Calls
    • Use tools like Postman or Fiddler to test the API calls manually. This can help verify whether the issue is with the code or the SharePoint configuration.
  • Vicente Garcia Llopis Profile Picture
    21 on at
    It's something about creating folders. I just logged in with the Azure user, and with Postman, I can create contacts, but not folders. As for SharePoint, it throws a 401 error.
    In Azure, you have SharePoint permissions at the application level. Should I give it more permissions?
     
  • Vicente Garcia Llopis Profile Picture
    21 on at
    Thanks for your response
    I attach photos of both requests, with the same token, generated with the oauth2 token
     
     
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 83 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

#3
#ManoVerse Profile Picture

#ManoVerse 40

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans