Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Answered

Python API to call REST endpoints for Finops / Ax7

Posted on by 10


I am looking to execute REST-based CRUD operations on the Finance and Operations module

I am unable to find all the tables exposed by ODATA

Where can I obtain the spec (swagger/OpenAPI) for the REST endpoints for Finops ?

It seems based on this question that there is none 

   

I am looking for something similar to the example shown here for CRM

   

I tried the example shown in this video 

https://www.youtube.com/watch?v=wZQ64yaDK84
]

  • SandeepJ Profile Picture
    SandeepJ 10 on at
    RE: Python API to call REST endpoints for Finops / Ax7

    thanks, update worked

    Now I just to parse the metadata (xml) returned by "<d365_url/data/$metadata>"

    will the odata python packages be able to parse that ?

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,235 Most Valuable Professional on at
    RE: Python API to call REST endpoints for Finops / Ax7

    You can use OData to query data, create, update and delete entity records. Note that not all entities support all operations. For example, some tables contain data created by journal posting and modifying the data isn't allowed, therefore the entities are built as read-only.

    You may want to look at some code, although it's in C#, not Python. For example, SimpleCRUDExamples shows an update, confirming that it's indeed possible.

  • SandeepJ Profile Picture
    SandeepJ 10 on at
    RE: Python API to call REST endpoints for Finops / Ax7

    thanks, I saw that list of python libraries already

    it seems only ODataPy is V4 compliant which is what Dynamics expects.  The other two (pyodata and Pyslet) are V2

    Btw, are updates allowed with OData ? I am seeing conflicting information in the doc.  My app is getting 404 when I try update (i.e. Patch requests)

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,235 Most Valuable Professional on at
    RE: Python API to call REST endpoints for Finops / Ax7

    You'll need to think about a few things. For example, what kind of information you'll want to get and when. The information may be just list of entities and field names, but maybe you'll also want to know other things like data types. You need to know which information you want to get before you can designb a solution to get it.

    The question "when" is also crucial. A common approach is fetching metadata at design time. You download OData metadata, generate classes and then use these classes in the application. Adding or modifying entities in F&O would require rebuilding the application, which may be a problem.

    Another approach is allowing some refresh in the application, when you'll download all the metadata again (and maybe populate lookup tables or something).

    The last approach is getting metadata every time when you need it, e.g. when a user wants to get a list of fields of an entity. You should use aggressive caching in such a case to limit the actual number of requests.

    By the way, you should explore existing Python libraries for OData. They may offer some features that you need. The list at odata.org mentions three ones for Python.

  • SandeepJ Profile Picture
    SandeepJ 10 on at
    RE: Python API to call REST endpoints for Finops / Ax7

    > Could you explain your business requirement, please? Maybe there are other approaches that you could use

    We are developing a CRUD application in python to interact with Dynamics as well as other databases

    user will send commands containing entity and field names.

    ideally we would like auto-detect all the entities and allow updates and deletes on them without hard-coding anything

    Hence we need some introspection ability to obtain the schema and use it

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,235 Most Valuable Professional on at
    RE: Python API to call REST endpoints for Finops / Ax7

    1. Could you explain your business requirement, please? Maybe there are other approaches that you could use. I don't think that $metadata allows any filters, therefore you would need to download the whole thing and then extract what you need. But as I said, maybe your requirement can be addressed in a different way.

    2. There are some relations in entity difinitions, but not many. It's expected that the system asking for data knows what data it needs. If you're saying that you don't know yet what you need anf you don't understand the data model, you can look into F&O table definitions for relations between tables. Then you can find entities for these tables.

    3. You should always use the latest one. Older versions don't contain the latest improvements.

  • SandeepJ Profile Picture
    SandeepJ 10 on at
    RE: Python API to call REST endpoints for Finops / Ax7

    thanks Martin.    Couple of follow-up questions, if you dont mind.   I have read the docs for past few days and found them overwhelming for my simple use-case

    1. Is there a way to obtain the metadata for a single entity like Customer ?  The metadata endpoint gives me a huge dump.  Looks like it was not possible in 2016 as per stackoverflow.com/.../fetching-metadata-for-a-specific-collection-or-entity-with-odata-web-services-i

    2.  How to figure out the foreign key relationships between entities (e.g. Customer and CustGroup) ?

    3.  Multiple versions : I see there are Customer, CustomerV2 and CustomerV3 ?  Are they all interoperable or should I use only latest version ?

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,235 Most Valuable Professional on at
    RE: Python API to call REST endpoints for Finops / Ax7

    You can get the list of available entities by simply making the request to the OData service. The URL is [your F&O instance]/data. You can open it in a browser, or make a GET request from any tool.

    The complete metadata can be obtained by [your F&O instance]/data/$metadata. Note that it's a lot of data. This is the information that code generator tools use to generate classes and method to manipulate with OData services in an object-oriented manner.

    You can always find these URLs (and some other details) in F&O documentation: Open Data Protocol (OData).

  • SandeepJ Profile Picture
    SandeepJ 10 on at
    RE: Python API to call REST endpoints for Finops / Ax7

    How can I get the list of all Data entities and their attributes ?

    For example, I was getting error because "Currency" field was missing when inserting "Customer" record.   But actually, it turned out the field name was "SalesCurrencyCode".   Took some time to figure that out

  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,235 Most Valuable Professional on at
    RE: Python API to call REST endpoints for Finops / Ax7

    OData is the right approach. But F&O doesn't expose tables. Data entities are used instead - they provide simpler schema, so systems consuming F&O data don't need to deal with a huge amount normalized tables and don't need to all the implementation details of F&O.

    OData is a standard - you can read more about it at data.org.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans