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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / How to call custom api...
Power Apps
Answered

How to call custom api from PCF component

(1) ShareShare
ReportReport
Posted on by 27
Hello All,
 
I have dynamics’ custom api developed and registered, it returns simple string data. I have PCF which need to call this custom api. But there is no execute method under context.webAPI, so I was wondering what are otherways to call dynamics’ custom api?
 
Thanks
Makarand
I have the same question (0)
  • Suggested answer
    Diana Birkelbach Profile Picture
    3,072 Most Valuable Professional on at
    Hi Makarand,

    The execute method is there, and it works, but it's not documented... so you can use it, if you know that is unsupported and accept the risk. 
    Do you need it in MDA? I have the feeling that the risk there is not that big, since the form scripting webAPI supports the execute method, so it's basically there.

    If you try to call it supported, it depends....
    One supported way would be to trigger an event from your PCF and let the form-scripting call the execute method.
    In CustomPages you can trigger an event from your PCF and there call the CustomAPI using PowerFx.

    In both cases it depends what you need to do with the result. It could be an input/bound parameter which you set in form-scripting/PowerFx.

    Of  course, there is also the old way of making a change on a record, which triggers the CustomAPI and writes the result back to your record is there too.. (not nice, but works).

    You could also write your own HTTPRequest too. There are some issues you need to take care of in that case (which is the url for webAPI requests inside the maker portal, take care of offline mode , ...).
     
     
  • Makarand Keer Profile Picture
    27 on at
    Thanks @Diana for helpful tips. 
     
    I would try calling execute and see how it works. 
     
    You also mentioned about triggering custom events (dispatchEvent) from PCF and handling it in Dyanamics form (which in my case is Case form). 
     
    I had different requirements where I wanted to use customEvents triggered from Case form and wanted to catch it PCF, however so far I could not make it work.
     
    Do you have a example which I can follow and get it working in my case?
     
    Here is how I am doing it (I have also posted it as separate question here )
     
    In dyamics case form’s custom js
    window.dispatchEvent(
    new CustomEvent("SKRibbonLoadingEvent", {
    bubbles: true,
    detail: JSON.stringify(caseData),
    })
    );
     
    and here is I tried to catch it in PCF (index.ts), but here handleCustomEvent never gets called
     
    public init(
    context: ComponentFramework.Context<IInputs>,
    notifyOutputChanged: () => void,
    state: ComponentFramework.Dictionary
    ): void {
    this.state = state;
    this.context = context;
    this.userSettings = context.userSettings;
    this.notifyOutputChanged = notifyOutputChanged;
     
    // Add the event listener when the component mounts
    window.addEventListener(
    "SKRibbonLoadingEvent",
    this.handleCustomEvent
    );
    }
     
     
     
  • Diana Birkelbach Profile Picture
    3,072 Most Valuable Professional on at
    Hi Makarand,
     
    Regarding triggering events: I was talking about triggering them from inside the PCF, which we can . We have a PCF api for that, but only for CanvasApps and CustomPages. I have a blog on this : https://dianabirkelbach.wordpress.com/2023/12/21/pcf-custom-events-sneak-peak/
     
    We can trigger events also in model-driven apps, by using output objects, and using the "addOnOutputChanged" event in form api: https://dianabirkelbach.wordpress.com/2023/05/19/let-your-subgrid-dataset-pcf-communicate-with-the-form/
     
    But your question is the other way around: trigger events from inside a form and catch it in the PCF. The only supported way I know is to use properties bound to your PCF. The updateView will be called when any of your properties gets changed, so you can react that way to events. So instead triggering an event, you make a change to that dedicated bound property,
     
    The code you've posted won't work also because the PCF and the scripts window are different. Probably the PCF is on the top window, and the scripts in an IFrame. You could try to post messages to window.top, but you'll have some issues with the solution checker, since that's not supported.

    Hope this helps!

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 765 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 272

Last 30 days Overall leaderboard