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 :
Customer experience | Sales, Customer Insights,...
Answered

Where and how to use Custom API using the Execution function of Xrm.WebApi, Fetch API, and XML HTTP Request.

(0) ShareShare
ReportReport
Posted on by 5
I have the same question (0)
  • Verified answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    Hi,

    I don't fully understand your question. But to execute Custom API from Model driven form, you can attach event handler from the form property on any field change/on load. You can also execute custom api from ribbon button click.

    You can also use Rest Builder tool to generate the js code to execute custom api.

    Please mark my answer verified if this is helpful!

  • Suggested answer
    Anmol Patel Profile Picture
    5 on at

    i have use below code but get an error...

    TypeError: Converting circular structure to JSON" on JavaScript

    Code:

    // Create a variable to point to a contact record and with specific data in the needed fields

    var leadData = {

    “@odata.type”: “Microsoft.Dynamics.CRM.lead”,

    “firstname”: “Mike”,

    “lastname”: “Staurt”,

    “subject”:”Interested in Car”,

    “telephone1″:”+973426536”

    }

    async function GetResult(leadData) {

    var result = await (await fetch(‘/api/data/v9.2/new_addlead’, {

    method: ‘POST’, // *GET, POST, PUT, DELETE, etc.

    cache: ‘no-cache’, // *default, no-cache, reload, force-cache, only-if-cached

    headers: {

    ‘Content-Type’: ‘application/json’

    },

    referrerPolicy: ‘no-referrer’, // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url

    body: JSON.stringify({ “lead”:leadData}) // body data type must match “Content-Type” header

    })).json();

    console.log(result.message);

    return result.message;

    }

  • Suggested answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    Hi,

    Please download and install below solution  in your instance-

    github.com/.../releases

    This will help you auto generate code to execute custom action.

    Once Managed solution is installed -> Go to Settings->Customization-> click CRM Rest Builder button

    Then Select your custom action name and parameters then click on Create request as show below which you auto generate the code for you-

    CR2.PNG

    Please mark my answer verified if this is helpful!

    Regards,

    Bipin Kumar

    Follow my Blog: xrmdynamicscrm.wordpress.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 > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 137 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 57

#3
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans