Executing a webMethods.io Integration workflow through a custom API endpoint

Overview

This webMethods.io Integration workflow example is triggered through an API request from an external service.

Using the data we receive from the external service, we send an API request to our Discourse community platform to delete a user who is no longer active, and this way we keep our database clean.

Note: Currently, there is no webMethods.io connector for Discourse. For workflows which work together with Discourse, we are using their great API . This means that the below example will work with any application (not just Discourse) that has an API you can access.

Steps

  1. Login to your webMethods.io Integration tenant or sign up for a free trial if you’re new.

  2. Create a new project or choose an existing one.

  3. In the workflows tab, add a new Workflow.

  4. Hover over the Start step and click the gear icon to start the workflow with the Webhook trigger. Specify the webhook payload that will be used by the API request at the runtime.

    As we want to pass an email address, add an email key in the Body field:

    Note: To avoid errors when you test Webhook, ensure you add a value to the email key in the Body field.

  5. You might need to verify the email address format. You can achieve this using conditions. Add the Switch action, one HTTP Request action and one Send email action to the canvas using the drag and drop feature, and let’s set the conditions.

  6. First connect the HTTP Request to the Switch action. Click on the arrow settings and set the case 1 (when a valid email address is received) condition:

    Select Case: Case 1
    Filter 1
    Input: {{$request.body.email}}
    Condition: (Regex) Match pattern
    Expected: (?:[a-z0-9!#$%&'+/=?^_{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_{|}~-]+)|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\[\x01-\x09\x0b\x0c\x0e-\x7f])")@(?:(?:a-z0-9?.)+a-z0-9?|[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-][a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\[\x01-\x09\x0b\x0c\x0e-\x7f])+)])

    Click Done.

  7. Connect now the Send email action to the Switch action. Click on the arrow settings and set the default case (when an invalid email address is received) condition:

    Select Case: Default

    Click Done.

    You might want to be notified if the workflow is not successful because of invalid input data. Open the Send email action settings and set it to receive an email with the invalid data:

    Click Done and connect the Send email action with the Stop step.

    Of course, you can use different ways for notifications or you can even skip this step and connect the default switch case to the Stop step directly as there is no point in continuing with an invalid email address.

  8. Let’s go back to case 1 when we have received valid input data.

    Open the HTTP request settings and use the following settings to receive the user id, which will be used later in the delete HTTP request:

    HTTP method: GET
    URL: https://{defaultHost}/admin/users/list/all.json?email={{$request.body.email}}
    Headers:
    Key: Api-Username
    Value: username
    Key: Api-Key
    Value: key

  9. Search for Return Data on Sync Webhook action and add it to the canvas. Open the settings and set the Response data in json format like this:

    Read more about how the Return Data on Sync webhook works.

  10. Add the HTTP Request service to the canvas by the drag and drop feature. This automatically connects with the previous step. Use the following settings to delete the user:

    HTTP method: DELETE
    URL: https://{defaultHost}/admin/users/{{$a0.responseObject.0.id}}.json
    Headers:
    Key: Api-Username
    Value: username
    Key: Api-Key
    Value: key

  11. Add the Send email action again and type a message that you want to receive after the workflow ends successfully. Using the different API responses, you can send different messages according to the output – user deleted successfully, user doesn’t exist in the database, user can’t be deleted, etc.

  12. Connect your last actions with the Stop step and save the workflow.

  13. You can also test it using the play button in the right upper corner and review the result.

Now let’s build an API using the REST API feature and execute the workflow

  1. To start creating an API, navigate to the project for which you want to create an API and click on APIs tab. Here you see a list of all existing REST APIs.

  2. Click Create API. You will be redirected to the Create API configuration window. Choose the first option Create from scratch:

  3. Fill out all required fields:

    Once you have entered all the details, click Save.

  4. The next step is to add the desired resources and methods to the created API. Open the newly created API and navigate to the Resources and Methods tabs on the left. Click the Add Resources button and choose:

    Path - Specify the resource path you want to expose for this API.
    HTTP Method - Select an HTTP method to use for the specified resource.

    Click Save.

  5. On the next screen, you can provide a short description and select the workflow you want to execute via this API.

    Note: Only workflows containing Webhook and a tested Return Data on Sync Webhook action will be listed in the drop-down field.

  6. Navigate to the API Details tab of your API and copy the API endpoint:

  7. Now that you have set your API endpoint URL and method type, you can make an API request. You need to use a Basic Auth (your webMethods.io Integration username and password) for making the call and also do not forget to pass the input data as Body parameters.

    For more information on the webMethods.io Integration REST API feature, please refer to the documentation.

2 Likes