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 :
Finance | Project Operations, Human Resources, ...
Answered

D365 OData 401 on SaveChanges()

(0) ShareShare
ReportReport
Posted on by 300

I am able to retrieve both out of the box and standard data entities from my dev instance if D365FO

I now want to submit Sales journals and have setup the following code but I get a 401 returned.

context.AddToOpenSalesPriceJournalLines(new OpenSalesPriceJournalLine()
{

//populate journal entry

});

var response = context.SaveChanges();

Any idea what could be causing the 401?

I can successfully retrieve a collection of journals, just not submit them

I have the same question (0)
  • Martin Dráb Profile Picture
    237,880 Most Valuable Professional on at

    I would start by reviewing details of the Exception object and events logs.

  • Sergei Minozhenko Profile Picture
    23,093 on at

    Hi richerich79,

    As 401 means Unauthorized and you said that you can read data with the same credentials, I can suspect that you don't have enough rights to insert data. Which account is linked to application in D365? Does it have enough access rights to the entity?

    But it's good to explore the exception for useful information.

  • richierich79 Profile Picture
    300 on at

    Thanks for your replies, authentication and permission issues always give me a headache :-(

    @Martin Unfortunately the exception object give me no more information than a 401 Authentication Failed, and I have not been able to find anything useful in the event viewer.

    pastedimage1581331254267v1.png

    The only thing I can find in the event viewer is a security audit (I don't know if it's even relevant)
    pastedimage1581331602853v2.png

    @Sergei I agree that seems the most likely issue. I have one user setup in dynamics as a system admin.
    pastedimage1581331747696v3.png

    The azure application has the following roles
    pastedimage1581331797066v4.png

    In visual studio I have created security privileges for my custom data entities, and I have added in SalesOpenSalesPriceJournalLineEntity to the group of entities

    pastedimage1581332100030v5.png

    I'm a bit stuck for where to go from here :-(

  • Martin Dráb Profile Picture
    237,880 Most Valuable Professional on at

    If you use the client secret for authentication, did you register your app in F&O (System Administration > Setup > Azure Active Directory Applications)?

  • richierich79 Profile Picture
    300 on at

    Hi Martin

    Yes I have, and the client Id in FO matches the client id of the app in Azure

    I would of thought if this wasn't setup then I would be able to access FO externally at all. Currently I can retrieve data, but can't create new journals

    pastedimage1581335934483v1.png

    The inner exception is of type System.InvalidOperationException. Could it be that the 401 is a red herring and Im sending the journals in an incorrect mannor?

  • LDuncan Profile Picture
    on at

    It is possible the 401 is not actually representative of the issue.  The best way to get the inner exception is with a Fiddler trace.  This article contains a link to Fiddler, I don't expect it is a token issue if you can read data successfully so the rest of the article may not be helpful. 

    https://docs.microsoft.com/en-us/dynamics365/fin-ops-core/dev-itpro/data-entities/troubleshoot-service-authentication

    Also the Event Log I think is a good spot to check and you noted checking there but I would look into the AX-OData* logs as opposed to the Windows Security Events.  You can find all of the AX logs in the Windows Event Viewer under Applications and Services Logs > Microsoft > Dynamics

  • richierich79 Profile Picture
    300 on at

    Thanks for all of your comments guys. Unfortunately I'm still getting the same error.

    Fiddler doesn't give much more than the exception object.

    I doubt it's authentication because I can retrieve records.

    My instincts tell me it's permissions of the user\application, or it's down to the data entity permissions. Unfortunately I've not been able to find anything

    Any ideas would be greatly welcome.

  • Verified answer
    richierich79 Profile Picture
    300 on at

    So I was being an idiot.

    The calls that were working were using a different config file. It was my own config that was causing the issue.

    The backslash issue...

    This works

    ActiveDirectoryResource = "https://#######.cloudax.dynamics.com";

    This doesn't!

    ActiveDirectoryResource = "https://#######.cloudax.dynamics.com/";

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 611 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 529 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 285 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans