Skip to end of banner
Go to start of banner

Create Custom REST API Endpoints

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 12 Next »

This article describes how to extend the EmpowerID REST API and create a simple API endpoint that returns a string in Workflow Studio. 

To create a custom REST API Endpoint

  1. In Workflow Studio, right-click the folder where you want to create the endpoint and select New Extension or Library > Class Library.


  2. In the Solution pane to the right of the C# Editor that opens, click the Properties tab and then click the Ellipsis button for the Supports property.


  3. Select WebApi from the Supported Types dialog that opens and then click OK to close the dialog.


    You should see the value of the Supports property update to WebApi.


  4. Click the Solution tab to return to the default Solution view.

  5. In the code tree for the solution, right-click the class library node and select Add New Implementation > Add New WebApi Implementation.


  6. Name the class TestCustomAPIEndPoint and then click OK.



    Workflow Studio creates the new class and opens it in the C# Editor. Notice the class is decorated with the RBACProtectedAttribute and the RelatedApplicationAttribute.

    RBACProtectedAttribute — This attribute is used to secure access to the endpoint using the RBAC authorization framework. It should not be removed.
    RelatedApplicationAttribute — This attribute specifies the parent application for the endpoint, which is set to the EmpowerID Web application by default (GUID). You can alter the parent to specify another application by setting the value of the GUID to that application. This allows you to publish APIs for users specific to the applications they use. For example, you could publish an API for customers or partners who use a CRM application that is registered in EmpowerID. By relating the endpoint to the CRM application, your customers or partners only need to have access to the application to consume the endpoint.

  7. In the Code Tree, expand the classes node. You should see four new classes:

    • A business object class for adding methods

    • A controller for handling the HTTP requests

    • A route for routing incoming HTTP requests to a specific action method on the controller

    • A model


  8. Open the controller class and in the C# Editor, add the following code to create the stub for a new anonymous method, the GetCustomString() method. Decorate the method with ApiAllowAnonymous to allow anonymous access and use GET as the HTTP method.

    [ApiAllowAnonymous]
    [HttpGet]
    public IHttpActionResult GetCustomString(TestCustomAPIEndPointInputModel model)
    {
        var results = _implInstance.GetCustomString(model);
        // Return object as JSON
        return Json((object)results);
    }
  9. Open the TestCustomAPIEndPoint class and add the GetCustomString() method to it to return a string.

    public dynamic GetCustomString(dynamic data)
    {
         string customString = "Hello Custom API End Point!";
         return customString;
    }
  10. Open the TestCustomAPIEndPointRoutes.cs file and in the C# editor uncomment the route code and edit the default route so that it looks like the following code.

    public IEnumerable<KeyValuePair<string, MapRouteModel>> GetRouteMaps()
    {
        var routeMaps = new Dictionary<string, MapRouteModel>();
        var test = new MapRouteModel();
        test.Name = 'TestCustomAPIEndPoint';
        test.Route = 'services/v1/TestCustomAPIEndPoint/maps/{id}';
        test.Defaults = new { controller = 'TestCustomAPIEndPointController',action = 'GetCustomString', id = RouteParameter.Optional };
        routes['mapApi'] = test;
    
        return routeMaps;
    }
  11. Compile the class library.


  12. Click Close to close the Operations log. If you see any errors, check your code and then compile the class library again.


  13. Compile and publish the class library.


  14. Select No when prompted about restarting services.

  15. Reset IIS.

The custom API end point is now available for you to consume. You can test the end point in Postman by following the procedure outlined in the Getting an Access Token and Creating a Person topics. When specifying the URL, append the base URL for your environment with the route, the controller and the method; e.g., https://{FQDN_OF_Your_EmpowerID_Web_Server}/api/TestCustomAPIEndPoint/v1/TestCustomAPIEndPointController/GetCustomString.

  • No labels