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

Announcements

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Get token with d365fo.tools

(3) ShareShare
ReportReport
Posted on by 156
Dear experts,
I want to use PowerShell to execute some scripts, so I installed d365fo.tools.
When I use the command Get-D365LcsApiToken to get the access token, an error always appears:The remote server returned an error: (401) Unauthorized.
I have checked the parameters several times without finding any problems, I don't know where the problem lies.
I have disabled the user's MFA authentication.
 
The commands to be executed are as follows:
Get-D365LcsApiToken -ClientId "b1ff7cb5-****-********" -Username "*****@*****.onmicrosoft.com" -Password "********" -LcsApiUri "https://lcsapi.lcs.dynamics.com" -Verbose | Set-D365LcsApiConfig -ProjectId "******" -ClientId "b1ff7cb5-****-********"
Categories:
I have the same question (0)
  • Sohaib Cheema Profile Picture
    49,636 Super User 2026 Season 1 on at
    I wonder if you added the permissions on the Azure Registered app (Dynamics LCS>Service user_impersonation , Microsoft Graph>User.Read)
    Also did you notice you are passing client id twice which is not needed.
  • Hu, Ethan Profile Picture
    156 on at
    I have added the Microsoft Graph>User.Read.
    I can't find Dynamics LCS from the API list.
    I have tried deleting the second client id parameter, but it did not work.
  • Sohaib Cheema Profile Picture
    49,636 Super User 2026 Season 1 on at
     
    click on the middle tab (Manage - API Permissions tab) and then search for Dynamics Lifecycle services
     
     
  • Hu, Ethan Profile Picture
    156 on at
    I have added the permission.
    The error is same.
  • Verified answer
    Sohaib Cheema Profile Picture
    49,636 Super User 2026 Season 1 on at
    Now your error message provides a different message, which you can read and compare with the previous one, although the reason remains the 401
    1) Did you grant the admin consent, as said in the document?
    2) Did you enable the public client as well, as documented?
    Please complete the two steps and once those are done, try with other tool like Postman, as in Microsoft example on the docs. Once you eliminate the permissions issue (401) you can use any third party tools like d365fo.tools
     
    Content-Type: application/x-www-form-urlencoded
      Host: login.microsoftonline.com
      Accept: application/json
      POST https://login.microsoftonline.com/YOUR_TENANT.COM/oauth2/v2.0/token
      BODY:
      client_id={CLIENT_ID_FROM_AZURE_CLIENT_APP}&scope=https://lcsapi.lcs.dynamics.com//.default&username={USER_EMAIL_ADDRESS}&password={PASSWORD}&grant_type=password
     
  • Suggested answer
    Sagar121 Profile Picture
    1,128 Super User 2026 Season 1 on at
    Does your account have LCS access and premission ?
  • Suggested answer
    Yng Lih Profile Picture
    1,612 Super User 2026 Season 1 on at
    Hi,
     
    You might want to narrow down the troubleshooting, by using the environment administrator id (id can be found from LCS) to try above.
     
     
    If this information was helpful, kindly mark it as 'Verified'. Thank you. :)
     
     
     
  • Hu, Ethan Profile Picture
    156 on at
    You are right, I can get token after enable public client.
     I have another question, when calling Get D365LcsDatabaseOperationStatus to get the database status, it always appears The remote server returned an error: (500) Internal Server Error.
     
    Thank you all for providing assistance.
     
    Also, in my environment in China, with the same settings, there are still errors.
    The command I used is as follows
    Get-D365LcsApiToken -ClientId "2f898d80-*******-******" -Username "******@*****.partner.onmschina.cn" -Password "********" -LcsApiUri "https://lcsapi.lcs.dynamics.cn" | Set-D365LcsApiConfig

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 721 Super User 2026 Season 1

#2
Abhilash Warrier Profile Picture

Abhilash Warrier 280 Super User 2026 Season 1

#3
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 255

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans