cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Kishor
Level: Powered On

Call WebAPI batch request in Powerapps Component framework

Hi Team,

 

We have created multiple (CRUD operation) requests in our PCF control and we want to execute that in one WebAPI batch request. Could anyone know how to call WebAPI batch request in PCF control?

 

Can we call WebAPI batch request using HTTP in PCF control? If yes, how can we get CRM url and version in PCF control?

 

Thanks,

Kishor

3 REPLIES 3
JoCas
Level: Powered On

Re: Call WebAPI batch request in Powerapps Component framework

Hi @Kishor !


Already did something like that. I'm using HttpRequest.
Regarding the org url, you don't actually need the org url, you just set the request url to the API path of your org /api/data/v9.0 ... and the org URL will automatically be prepended to your request.

 

Cheers!

Kishor
Level: Powered On

Re: Call WebAPI batch request in Powerapps Component framework

Thank you for your help.

 

Could you please elaborate this in detail. You have any example of PCF control that we can see. 

 

Also, could you please let us know how we use WebAPI batch request using HTTP in PCF control? Is there any way to call the batch request in PCF control?

 

Thanks,

Kishor

JoshuaRobert
Level: Powered On

Re: Call WebAPI batch request in Powerapps Component framework

Hi Kishor!

Here's a sample code snippet that send fetchXml requests in batch. Notice that the request url is just the partial url of of the api.

export async function batchRequest(fetchXml: string, entity: string): Promise<string> {
    return new Promise(function (resolve, reject) {
        let xhr = new XMLHttpRequest();
        xhr.open("POST", "/api/data/v9.0/$batch", true);
        xhr.setRequestHeader("Prefer", "odata.include-annotations=OData.Community.Display.V1.FormattedValue");
        xhr.setRequestHeader("Content-Type", "multipart/mixed;boundary=batch_fetchquery");
        xhr.onload = function () {
            if (this.status >= 200 && this.status < 300) {
                resolve((xhr.response as string).substring((xhr.response as string).indexOf("{"), (xhr.response as string).lastIndexOf("}") + 1));
            } else {
                reject({
                    status: this.status,
                    statusText: xhr.statusText
                });
            }
        };
        xhr.onerror = function () {
            reject({
                status: this.status,
                statusText: xhr.statusText
            });
        };
        let body =  
            "--batch_fetchquery\n" +  
            "Content-Type: application/http\n" +  
            "Content-Transfer-Encoding: binary\n" +  
            "\n" +  
            "GET " +
            "/api/data/v9.0/"+entity+"?fetchXml=" +  
            encodeURIComponent(fetchXml) +  
            " HTTP/1.1\n" +  
            'Prefer: odata.include-annotations="*"\n' +  
            "\n" +  
            "--batch_fetchquery--";
        xhr.send(body);
    });
}

Hope this one helps.

Cheers!

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors
Users Online
Currently online: 312 members 5,452 guests
Please welcome our newest community members: