Sunday, March 24, 2024

Develop a custom API to Delete a contact using XrmToolBox | Dynamics 365

Create Custom API to Delete Contact in Dynamics 365 with XrmToolBox

Introduction:

This blog explores building custom APIs within Power Apps by leveraging plugins. Custom APIs empower developers to expose specific functionalities of Dynamics 365, enabling seamless integration with external systems and services.

Scenario: We will create a Custom API of Entity Binding type with a plugin tailored to delete contact records in Dynamics 365. Following this, we'll set up and associate this Custom API with the registered plugin, and illustrate how to invoke the API using either the XrmToolBox custom API tester or Power Automate Flow.

Refer to this video for a detailed implementation guide for Developing, Configuring and Invoking Custom API


Custom API Binding Types

In Power Apps, custom APIs offer a flexible way to extend the capabilities of your data platform by defining custom messages that can be invoked from various sources. These messages can interact with data or perform custom logic. A key aspect of custom APIs is the concept of binding types, which determine how the API interacts with entities in your Dataverse environment.

Here's a breakdown of the three available binding types and we will focus on the implementation for the Global type:

  1. Global:

    • Description: This type is most versatile as it doesn't have a specific association with any entity. It's suitable for operations that don't directly work with entity records.
    • Use Cases:
      • Performing calculations or manipulations on data that doesn't reside in a particular entity.
      • Triggering workflows or custom actions that aren't tied to an entity.
      • Integrating with external services or systems that don't map directly to Dataverse entities.
  2. Entity:

    • Description: This type binds the custom API to a specific entity (table) in Dataverse. It's designed for operations that accept a single record of that entity as input or return information about a single record.
    • Use Cases:
      • Performing operations on a single entity record, such as creating, updating, or deleting a record.
      • Validating data against entity-specific rules before processing it further.
      • Retrieving details about a specific entity record.
  3. EntityCollection:

    • Description: This type also binds to a specific entity, but it's used for operations that involve collections of records from that entity. It can accept a collection of entity records as input or return a collection of records as output.
    • Use Cases:
      • Performing bulk operations on multiple entity records, such as creating, updating, or deleting multiple records at once.
    • Querying and retrieving a collection of entity records based on specific criteria.

Prerequisites
Before starting on the development of the custom API using a plugin, ensure you possess the necessary tools, licenses, and knowledge outlined below.
  1. Power Apps License
  2. XrmToolBox with Custom API Manager and Custom API Tester  installed
  3. Power Automate License (Optional to Invoke)
  4. Plugin/C# Development Knowledge
  5. Visual Studio (with .Net Framework 4.6.2 for plugin development)
  6. Plugin Registration Tool

Below is a snapshot from the XrmToolBox Custom API Manager, showcasing an Entity type custom API designed for deleting a contact, featuring input and output response properties.

Creating a Custom API in Custom API Manager




Note: The unique name must commence with the Publisher prefix, such as "new_fieldname." If provided without the prefix, the Custom API cannot be saved and will result in the following error


Plugin Code-


Link to download the plugin code for Deleting Contact is - here

Output Snapshot 
Input - { "RecordId": "868b1cff-08ea-ee11-a203-0022482e5de4"}



No comments:

Post a Comment

Followers

Power Dynamix YouTube Videos