| Muhammad Uzair

Use WebAPI in Power Portals (now Microsoft Power Pages)

The Power Pages WebAPI is a powerful tool that allows you to extend the functionality of your Power Pages portal. By using the WebAPI, you can perform CRUD operations on Dataverse tables, retrieve data from Dataverse, and integrate your Power Pages portal with other systems.

To use the WebAPI in Power Pages, you must first enable it in the Portal Management app. Once the WebAPI is enabled, you can use it in your Power Pages portal by making HTTP requests to the following endpoint:

/_api/

The WebAPI supports a variety of HTTP methods, including GET, POST, PUT, and DELETE. You can use these methods to perform CRUD operations on Dataverse tables, retrieve data from Dataverse, and more.

For example, the following GET request will retrieve all of the contacts from Dataverse:

/_api/contacts

The following POST request will create a new contact in Dataverse:

POST /_api/contacts

Content-Type: application/json

{

"name": "John Doe",

"emailAddress": "john.doe@example.com"

}

The following PUT request will update an existing contact in Dataverse:

PUT /_api/contacts(12345678-90ab-cdef-0123-456789abcdef)

Content-Type: application/json

{

"name": "Jane Doe"

}

The following DELETE request will delete a contact from Dataverse:

DELETE /_api/contacts(12345678-90ab-cdef-0123-456789abcdef)

You can use the WebAPI in Power Pages to perform a variety of tasks, such as:

  • Retrieve data from Dataverse to display on your Power Pages portal.
  • Allow users to create, update, and delete data in Dataverse from your Power Pages portal.
  • Integrate your Power Pages portal with other systems, such as CRM systems and e-commerce systems.

Example Code

The following code shows how to use the WebAPI in Power Pages to retrieve all of the contacts from Dataverse:

$(document).ready(async function () {

//Get all the contact

var requestBody = {

entityLogicalName: "contact",

query: {

filter: "statecode eq 0 and isinactive eq false",

},

};

await webapi.safeAjax({

requestBody: requestBody,

success: function (contacts) {

if (contacts.length > 0) {

for (var i = 0; i < contacts.length; i++) {

var contactName = contacts[i].name;

var el = document.createElement("option");

el.textContent = contactName;

el.value = contactName;

$('#ContactList').append(el);

}

} else {

//alert("No contact found");

}

},

error: function (error) {

alert("Error:" + error);

}

});

});

This code will retrieve all of the contacts from Dataverse and display them in a dropdown list with the id of ContactList.

Conclusion

The WebAPI is a powerful tool that allows you to extend the functionality of your Power Pages portal. By using the WebAPI, you can perform CRUD operations on Dataverse tables, retrieve data from Dataverse, and integrate your Power Pages portal with other systems.

Join us next time, as we continue our journey of learning canvas apps.Click here to learn more about Imperium's Power Apps Services. We hope this information was useful, and we look forward to sharing more insights into the Power Platform world.



About The Blog

Stay updated with what is happening in the Microsoft Business Applications world and initiatives Imperium is taking to ease digital transformation for customers.


More About Us

We provide guidance and strategic oversight to C-Suite and IT Directors for on-going implementations. Feel free to give us a call.

1 331 250 27 17
Send A Message

Ready to Start?

Get a personalized consultation for your project.

Book a Meeting