Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. In the Code Tree, right-click the project and select Add New Controller.


  2. Name the controller HelloAPI and click OK.

    Workflow Studio creates the controller class and opens it in the C# Editor. Notice the class is decorated with the RBACProtectedAttributeand 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.

    Additionally, notice that Workflow Studio generated the following classes in addition to the controller:
    ✔ A route for routing incoming HTTP requests to a specific action method on the controller
    ✔ A model to represent data

  3. Save and close the project.

    Next, we will open the API project in Visual Studio and add logic to the controller and route.

...

  1. In the Source Control tree of Workflow Studio, locate the API project and double-click it.

    You should see the project open as a solution in Visual Studio.

  2. Open the HelloAPIclass and add a new method to the class that returns a string named GetHelloString().

    Code Block
    public dynamic GetHelloString(dynamic data)
    {
         string helloString = "Hello API!";
         return helloString;
    }

  3. Open the HelloAPIController class and add the following code to create the stub for a new anonymous method named GetHelloAPIString(). Decorate the method with ApiAllowAnonymous to allow anonymous access and use GET as the HTTP method.

    Code Block
    languagec#
    [ApiAllowAnonymous]
    [HttpGet]
    public IHttpActionResult GetHelloAPIString(HelloAPIInputModel model)
    {
        var results = _implInstance.GetHelloString(model);
        // Return object as JSON
        return Json((object)results);
    }

  4. Open the HelloAPIRoutes.cs file.

    Notice the default GetRouteMaps() method defines a dictionary of routeMaps. You can use this default method or replace the commented out code with your routes.

    Code Block
    languagec#
    public IEnumerable<KeyValuePair<string, MapRouteModel>> GetRouteMaps()
    {
      var routeMaps = new Dictionary<string, MapRouteModel>();
      /*
        Your routes go here!
        Below is an example - 
    
        var map = new MapRouteModel();
        map.Name = 'mapApi';
        map.Route = 'services/v1/itshop/maps/{id}';
        map.Defaults = new { controller = 'Maps',action = 'GetMapsByMapsGUID', id = RouteParameter.Optional };
        routes['mapApi'] = map;
      */
        return routeMaps;
    }  

  5. Remove the commented out lines and edit the default route so that it looks like the following example.

    Code Block
    languagec#
    public IEnumerable<KeyValuePair<string, MapRouteModel>> GetRouteMaps()
    {
        var routeMaps = new Dictionary<string, MapRouteModel>();
        var map = new MapRouteModel();
        map.Name = 'HelloAPI';
        map.Route = 'services/v1/HelloAPI/maps/{id}';
        map.Defaults = new { controller = 'HelloAPIController',action = 'GetHelloAPIString', id = RouteParameter.Optional };
        routes['mapApi'] = map;
    
        return routeMaps;
    } 

  6. Build the solution.

    Building the solution in Visual Studio, publishing publishes the API in EmpowerID. You should see something similar to the below output message.

    Image RemovedImage Added

  7. 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., similar to that shown in the below example:

https://{FQDN_OF_Your_EmpowerID_Web_Server}/api/HelloAPI/v1/HelloAPIController/GetCustomString.

Insert excerpt
IL:External Stylesheet
IL:External Stylesheet
nopaneltrue

...

Next Steps

Add OAuth Scopes to API Endpoints