Tray Embedded / Core Topics / Retrieving Webhook URLs

Retrieving Webhook URLs

Overview

For cases when it is necessary to directly send messages to a specific Workflow in an End User's Solution Instance (e.g. when using Amazon SQS), it is possible to retrieve the webhook URL for the Workflow Instances which underlie their Solution Instance.

When talking about a Workflow in an End User's Solution Instance, it is important to understand that there are effectively two Workflows:

  1. The original Source Workflow which you built in the UI (in Dashboard > Create New Workflow). It can be found in the url when using the workflow editor https://app.tray.io/workflow/<sourceWorkflowId>/edit/
    In the API example results below this is identified by sourceWorkflowId
  2. The End User-specific copy of the Workflow (the Workflow Instance) which exists within their Solution Instance (in the UI you can see this by going to Users > Click 'Instances' for End User > Click 'See Workflows' for Instance > Click 'Debug Workflow' for the relevant Workflow)
    In the API example results below this is identified by id
You can also choose to make the webhook URL available to the End User in the COnfig Wizard

Before using the GraphQL mutations below you should identify the sourceWorkflowId of the workflow you want to pinpoint for a specific user. This is so that, in your external application, you can filter out the other workflows in the solution which you are not concerned with.

The ultimate aim here is to get the triggerUrl for the relevant End User-specific Workflow Instance.

Retrieving webhook URL when creating a Solution Instance

When using Create Solution Instance you can expose the webhook urls for a Solution Instance by including workflows as data to be returned:

mutation {
createSolutionInstance(input: {
solutionId: "2bexxx-xxxx-xxxx-xxxx-xxxxxxf3491",
instanceName: "some instance name",
authValues: [{ externalId: "external_sqs_authentication", authId: "aaa67786-xxx-xxx-xxx-97dedd1519b3" }],
configValues: [{ externalId: "external_user-email" , value: "\\"me@example.com\\"" }]
}) {
solutionInstance {
id
name
enabled
created
workflows {
edges {
node {
id
triggerUrl
sourceWorkflowId
}
}
}
}
}
}

This will produce a result such as:

{
"data": {
"createSolutionInstance": {
"solutionInstance": {
"id": "625xxx-xxx-xxx-xxx-xxx111f",
"name": "Gene Slack star instance 2",
"enabled": false,
"created": "2019-02-25T11:02:21.884Z",
"workflows": {
"edges": [
{
"node": {
"id": "98099de2-xxx-xxx-xxx-xxxxxb8ff7",
"triggerUrl": "https://6a4xxx-xxx-xxx-xxx-xxx-xxxe8eaa2.trayapp.io",
"sourceWorkflowId": "378xxx-xxx-xxx-xxx-xxx-xxx4fd6"
},
"node": {
"id": "83774e4-xxx-xxx-xxx-xxxxxvur88f",
"triggerUrl": "https://9s3xxx-xxx-xxx-xxx-xxx-xxxe5iuu2.trayapp.io",
"sourceWorkflowId": "593xxx-xxx-xxx-xxx-xxx-xxx9du4"
}
}
]
}
}
}
}
}

Retrieving webhook URL after Instance creation

After a Solution Instance has been created it is also possible to return the webhook url with a list instances query (remember you must use the End User's token for this query):

query {
viewer {
solutionInstances {
edges {
node {
id
name
enabled
created
workflows{
edges {
node {
id
triggerUrl
sourceWorkflowId
}
}
}
}
}
}
}
}