Access Experience Workflow result from external api call

Feel like a fool for asking this as the answer should be obvious but unfortunately it evades me…

I’ve got the following 2 experience workflows:

One workflow GETS a list of devices based on an advanced query and then replies with the id and serialNumber of each device that the query found.

A second workflow POSTS a serialNumber, runs a test and updates the device’s tags with two values.

The challenge is that I would like to access the results of each of these workflows in a C# application for internal use and would prefer to NOT have a user attached to the API calls.

The Bearer Token functionality works to gain access to the Losant API but am not finding success in triggering custom workflows from outside of Losant without an email / password.

Have tried making calls with Postman and from the C# Application. I can make this work if choosing All public users / custom authentication but was hoping to select Any authenticated user and attaching a token to the call for access.

In summary… Is there a way to trigger a custom experience workflow and send the reply as a result in an API call from outside of Losant without an email / password and preferably with some sort of token authentication?

Thanks

Hey @Greg_Bopp,

Welcome to the Losant forums! Please don’t feel bad for asking questions, that’s what we’re here for!

Since you are creating a custom API with Experiences and would like to have that endpoint only available to Any authenticated user, and also utilize a token system, you will need to obtain a token. If you would like other users to be able to get a token, you can create an Authentication Endpoint.

We have made this addition incredibly easy with an Authentication Endpoint Template in our Template Library.

If you just need one token, you can create a sort of “dummy” Experience user to get this token and be able to use it for a long period of time (for as long as you set the TTL). You would create this user, then build a workflow with a Virtual Button, an Authenticate Node, and a Generate Token Node. This option would be a good one if you also have Experience users, separate from your C# application, that will be using these custom Experience endpoints.

Another option you have is to implement these workflows as Application Workflows, then use an Application API Token to make requests to the Flow endpoint for the specific workflow(s). You are able to scope this token, too, to just allow it to press virtual buttons in workflows and nothing else.

Please let me know if this helps or if you would like any more clarification on what I’ve explained.

Thank you,
Heath

Thank you for the fast response…

Still a bit confused though. I am comfortable making the workflows as application workflows as opposed to experience workflows if that allows for an application api token to be used for authentication.

I copied a GET endpoint workflow over to an application workflow and it still will not authenticate with an application api token with Any Authenticated User selected in the endpoint.

NOT understanding what the virtual button situation is. I would like to send a GET to a URL and get the results of the workflow. I’m fine with implementing a virtual button if required but how does the button and endpoint relate?

Thanks

@Greg_Bopp,

I copied a GET endpoint workflow over to an application workflow and it still will not authenticate with an application api token with Any Authenticated User selected in the endpoint.

This is expected behavior since an Application API Token cannot authenticate the use of an Experience endpoint. The Token you would use to execute an Experience workflow via an Experience Endpoint would be an Experience User Token. Which you would need to obtain through generating a token for an authenticated Experience User.

NOT understanding what the virtual button situation is. I would like to send a GET to a URL and get the results of the workflow. I’m fine with implementing a virtual button if required but how does the button and endpoint relate?

Workflows need an entry point. To trigger a workflow via an HTTP request, you have two options in this case:

  1. A Webhook
  2. A Virtual Button

A webhook would allow you to trigger a workflow, but does not have the same verification that utilizing the Losant API does.

Moving your Experience API workflows to Application Workflows allows you to use Token-based authorization (Application API Tokens) to make requests to specific Application resources.

Specifically, in your case, you could create an Application API Token and use the “Custom” Scoping option, and only select “Press Virtual Button”. This means that any API requests to your Application with this token would only be able to be the pressing of Virtual Buttons in workflows.

Here’s an example:

I’ve created an Application API Token:

And created this simple Application Workflow:

And using postman, I made a request to https://api.losant.com/applications/608c4f056609710007e7023e/flows/608c4f0cd0d6a90007fd666c/virtualButton with an Authorization header with the value of Bearer <my-application-api-token>:

This request requires you to put the Node Key in the request body, which you can find in the Virtual Button Configuration:

I know this is a lot of information, so please let me know if you need more clarification.

Thank you,
Heath

Very good information, thank you!

Was able to successfully trigger the virtual button and update a devices’ tags after going through the workflow.

Is there any way to send a response other than "success": true?

Thanks!

@Greg_Bopp,

Is there any way to send a response other than "success": true ?

Because this is a response from the Losant API, the response is unable to be changed. Is there something you’d like to see there other than just a success message?

The best way to get a custom response would be to use the Webhooks that I had mentioned or using Experience API Endpoints (which was the option you had asked about in your first question).

Thank you,
Heath

Is there something you’d like to see there other than just a success message?

I would like for the application to inform the user which devices have been updated successfully but can go about it a different way. Thanks so much for the continued help!

1 Like