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, ...
Unanswered

calling D365FO custom web service with REST API in the Logic app and specify call context (i.e. Multiple companies)

(1) ShareShare
ReportReport
Posted on by 50

Hi All, 

I am trying to call Custom D365FO REST web service using client-id and ClientSecret in Logic App (i.e. HTTP Post). The web service executed the operation in the Default user context. I know that in the Soap version it is possible to switch the context/Company using      AX.CallContext callContext = new AX.CallContext() { Company = "XXXX" }. Which in turn generates 

<s:Header><h:CallContext xmlns:h="">schemas.microsoft.com/.../datacontracts" xmlns:i="">www.w3.org/.../h:Company><h:Language i:nil="true"/><h:MessageId i:nil="true"/><h:PartitionKey i:nil="true"/></h:CallContext></s:Header>

I would like to achieve the same in REST endpoint of this webservice. 

I tried the following: 

1. Added the call context in Body of the request 

   "CallContext": {
        "Company": "XXXX"
    },
2. Added CallContext in the header 
Nothing seems to work. Can someone advise how to switch the context?
Note: I don't want to add Company in data contract and then code does the company switching  
I have the same question (0)
  • WillWU Profile Picture
    22,361 on at

    Hi Poojith,

    Have you tried this:

    BODY

    {

       "legalEntityId":"<string>"

    }

    Why do you have to use Rest API?

    What do you want to achieve?

    Many regards.

  • Poojith Jain Profile Picture
    50 on at

    Hi Will,

    Thanks for the reply. I am trying to call D365FO custom web service from LogicApp. I need to switch the company based on a parameter. Currently the call context (company) is always the default context of Azure AD Application.

    I tried your solution and it didn't work.

  • WillWU Profile Picture
    22,361 on at

    Hi Partner,

    Why do you want to call the Web APIs directly when Logic Apps provides a Dynamics 365 connector out of the box?

    You can create a API connection and select the organization and the entity.

    7026.Capture.PNG

    5734.Capture2.PNG

  • Poojith Jain Profile Picture
    50 on at

    Hi Will,

    There is a difference between D365 and D365FO. A custom webservice in FO is needed for business logic.

  • WillWU Profile Picture
    22,361 on at

    Hi Partner,

    D365FO can do the same.

    Please refer to the blog:

    community.dynamics.com/.../dynamics-365-for-operations-logic-app-how-to-get-one-record-if-you-do-not-know-the-unique-key

    You can type your company name in the filter query.

    Hope this helps.

  • Poojith Jain Profile Picture
    50 on at

    Hi Will,

    With all the respect, please read the questions before responding :)

    I am calling custom FO webservice using HTTP request

  • Lionel Yanzeu Profile Picture
    10 on at

    Hi,

    Have you found a way to do it with REST API ?

    I'm looking for a solution as we have for SOAP service with callContext

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

    There is no CallContext for REST endpoints. You need to add a parameter to your contract and use it to switch companies inside your service operation. It won't happen automatically.

  • Lionel Yanzeu Profile Picture
    10 on at

    Thanks for your answer.

  • ThomasVogtPoulsen Profile Picture
    30 on at

    I know it is probably a long short, but did you get the Logic App to call the D365FO custom service. I have tried without any luck getting "Cannot connect to remote server" error. The same call from Postman works fine.

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 646 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