What are triggers in marketplace app and how to add triggers?

What are triggers in marketplace app and how to add triggers?

This article covers the steps to take for adding triggers in marketplace application. 
What are triggers? Triggers in marketplace apps enables the app developers to trigger Kylas workflows based on an event that takes place in their application. And this trigger enables the end user to perform a desired action via the workflow. Below are some example user cases that can be fulfilled via the marketplace app triggers: 
  1. Send a WhatsApp message from Kylas WB messaging app via workflow when the payment is done by the payment link generated by Razorpay.
  2. Send an Email to the customer when KYC requests is generated from SETU.
This way user can connect two or more marketplace apps via Kylas workflows using app triggers and actions. 

Prerequisites: 

Product plan: Kylas elevate and above
Permissions: Tenant user who can create marketplace app as covered in https://support.kylas.io/portal/en/kb/articles/how-to-create-a-marketplace-application 

Steps: 

  1. Create or edit a marketplace app and reach up to step 5 as covered in https://support.kylas.io/portal/en/kb/articles/how-to-create-a-marketplace-application 
  2. Choose yes if you want to specify app triggers on the below screen 
  3. Choose the entity type for which you would like to add the trigger and enter the Trigger Name
  4. Define the variables that you would send on the webhook URL (generated in next step) along with this trigger.

  5. You can define as many variables as you want, the end user of your application will be able to use the values of these variables as Workflow conditions, Template variables and much more. 
  6. Click Next to move to the next step 
  7. You will see the App trigger URLs along with a sample curl request that you are supposed to pass when the trigger event occurs as shown below 

  8. You can click the 'View sample request' to view a sample curl that you can try hitting 

  9. Look at the format for the variable types you have added carefully in the sample request, and make sure to send the data in similar format to let Kylas workflows function correctly. It's mandatory to send 
  10. You may add multiple such triggers for corresponding events.
  11. Whenever the desired event occurs in your marketplace app, you need to hit the given URL with corresponding authentication and body and if Kylas user has added this trigger as their workflow trigger as explained in https://support.kylas.io/portal/en/kb/articles/how-to-let-a-marketplace-app-event-trigger-kylas-workflow then the workflow will trigger and it will perform the added actions. 
Sample curl requests with Authentication as Token:

curl --location 'https://api-qa.sling-dev.com/v1/workflows/triggers/lead/a0a30acc-f9cb-49e0-a6e8-91280ad5249b' \
--header 'Authorization: Bearer <Your bearer token>' \
--header 'Content-Type: application/json' \
--data '{
        "mpEntityId": 1234,
        "mpEntityName": "Some Text",
        "mpConnectedAccountName": "Some Text",
        "mpPanNumber": "Some Text",
        "mpKycRequestId": "Some Text",
        "mpKycRequestStatus": "Some Text",
        "mpKycResponseMessage": "Some Text",
        "mpKycInitiatedAt": "2021-09-07T05:15:35Z",
        "mpKycCompletedAt": "2021-09-07T05:15:35Z",
        "mpRequestCreatedByUserId": 1234,
        "mpRequestCreatedByUserName": "Some Text",
        "mpCustomerName": "Some Text"
    }' 


Sample curl request with API key as authentication: 

curl --location 'https://api-qa.sling-dev.com/v1/workflows/triggers/lead/a0a30acc-f9cb-49e0-a6e8-91280ad5249b' \
--header 'api-key: <Your Tenant's API key>' \
--header 'Content-Type: application/json' \
--data '{
        "mpEntityId": 1234,
        "mpEntityName": "Some Text",
        "mpConnectedAccountName": "Some Text",
        "mpPanNumber": "Some Text",
        "mpKycRequestId": "Some Text",
        "mpKycRequestStatus": "Some Text",
        "mpKycResponseMessage": "Some Text",
        "mpKycInitiatedAt": "2021-09-07T05:15:35Z",
        "mpKycCompletedAt": "2021-09-07T05:15:35Z",
        "mpRequestCreatedByUserId": 1234,
        "mpRequestCreatedByUserName": "Some Text",
        "mpCustomerName": "Some Text"
    }'
Note:: As best practice you should ask you users to which triggers out of all available ones they want to enable in the app and you should only send event to Kylas URLs for the subscribed triggers to avoid hitting rate limiting.