How to use the API to run a scenario?

Hi,

Firstly, what a fantastic tool!
I would like to be able to run scenarios from Make rather than from the browser interface.
I’ve seen the API page but could you provide a simple example of what is required?
I am a no-code user!

Many thanks
Pazza

There are 2 step.

  1. Get your bearer token (api/auth/login) and authorize in the swagger page/api client.

  2. Find and call api/scenario/run/{scenario id}.

  1. Get your token code by executing this call, enter your details by clicking try it out.

  1. Click the padlock icon, enter your token code, and enter the scenario ID that you want to run.

Hi Pazza,

We will send you more detailed explanation on your mailbox.

Thank you!

Hi Zekeriya,
Could you send them to me too?

Thanks

We are preparing a better documentation for the APIs. Will share you when it is ready.

Hi

Can you let me/us know where the account id can be found so we can authorise the API calls?

Thanks
Martin

Hi @pritcham,

I tried but I was not able to do it by myself as well :slight_smile: I need to learn this from the team :slight_smile:

However, as a workaround you can get your token directly from browser after login:

Then you need to give it as an authentication bearer {Token} in the header. I suppose you know this part?

For to authenticate your APIs, you can use

POST /api/Auth/login

{
  "email": "string",
  "password": "string"
}

Dear U-Xer Support Team,

My name is Ivan Khainatsky, and I am experiencing difficulties with correctly executing a scenario using the U-Xer API. Despite following the available documentation, my attempts to specify the correct agent for scenario execution have been unsuccessful.

Issue Description:

  • Problem: The scenario consistently runs on the default agent, even though I have specified the correct agent ID in my requests.
  • Expected Behavior: The scenario should execute using the agent with ID 8be345a8-a0a5-44f9-a32c-9f30bc851e6c, which corresponds to the agent named “Khainatsky” in my U-Xer account.
  • Steps Taken:
    1. Used the GET method to request scenario execution with the specified agent ID.
    2. Attempted to retrieve a list of agents using various endpoints and methods (GET and POST).
    3. Confirmed that the agent ID is correctly set in my configuration file.

Specific Errors Encountered:

  • When trying to retrieve the list of agents using GET request: HTTP 405 Method Not Allowed.
  • When trying to retrieve the list of agents using POST request: HTTP 405 Method Not Allowed.

Request for Assistance:

  1. Correct Endpoint and Method: Could you please confirm the correct API endpoint and method to retrieve the list of agents?
  2. Proper Agent Specification: Is there a different approach or additional parameter required to ensure that the scenario runs on the specified agent “Khainatsky” instead of the default agent?
  3. Documentation Clarification: Any additional documentation or guidance on properly setting up and executing scenarios with a specified agent would be greatly appreciated.

Below is a sample of my current code setup for executing the scenario:

python

import requests
import config

def run_scenario(scenario_id, agent_id, token):
    headers = {"Authorization": f"Bearer {token}"}
    run_url = f"https://gateway.u-xer.com/api/Scenario/{scenario_id}/run?agentId={agent_id}"
    run_response = requests.get(run_url, headers=headers)
    print(f"Status code: {run_response.status_code}")
    print(f"Response text: {run_response.text}")
    if run_response.status_code == 200:
        print("Scenario successfully started")
    else:
        print(f"Error starting scenario: {run_response.status_code} {run_response.text}")

if __name__ == "__main__":
    token = config.token
    scenario_id = config.scenario_id
    agent_id = config.agent_id
    run_scenario(scenario_id, agent_id, token)

I appreciate your time and assistance in resolving this matter.

Thank you, Ivan Khainatsky

Hi Ivan,

Please take a look at the video. I can’t provide 100% solution at the moment but this is a starting point.

additionaly you can use below api to get list of agents. (leave body empty)
POST /api/Agent/search

https://video.u-xer.com/s/XL1wemgk?

Watch Video

Hi Zekeriya,

Thank you for your previous response and the helpful video. I followed your suggestion to use the POST /api/Agent/search endpoint to get the list of agents. This worked perfectly, and I was able to retrieve the correct agent IDs.

Here are the details:

  • Agent Name: Kha*******
  • Agent ID: 8be345a8-a0a5-****

However, I am still facing an issue with correctly executing a scenario using this specific agent. Despite specifying the correct agent ID in my request, the scenario seems to default to the “Default Agent,” which is inactive in my account.

Current Issue:

  • When attempting to run the scenario using the specified agent ID, I receive a 405 Method Not Allowed response.
  • Below is the code snippet I am using for this request:

python

Копіювати код

import requests
import config

def run_scenario(scenario_id, agent_id, token):
    headers = {"Authorization": f"Bearer {token}"}
    run_url = f"https://gateway.u-xer.com/api/Scenario/{scenario_id}/run"
    payload = {"agentId": agent_id}
    print(f"Running scenario with agent: {agent_id}")
    print(f"Request to URL: {run_url} with payload: {payload}")
    run_response = requests.post(run_url, headers=headers, json=payload)
    print(f"Status code: {run_response.status_code}")
    print(f"Response text: {run_response.text}")
    if run_response.status_code == 200:
        print("Scenario successfully started")
    else:
        print(f"Error starting scenario: {run_response.status_code} {run_response.text}")

def main():
    token = config.token
    if not token:
        print("Token not found")
        return
    
    print(f"Using agent with ID: {config.agent_id}")
    run_scenario(config.scenario_id, config.agent_id, token)

if __name__ == "__main__":
    main()

Request for Assistance:

  1. Correct Method: Could you confirm if POST is the correct method to use for executing scenarios with a specified agent?
  2. Endpoint Confirmation: Is there a different endpoint or additional parameters required to ensure the scenario runs with the specified agent “Kha*******” instead of defaulting to “Default Agent”?
  3. 405 Error Resolution: Any guidance on resolving the 405 Method Not Allowed error when attempting to run the scenario would be greatly appreciated.

Thank you for your assistance and support.

Best regards,
Ivan Khainatsky

Hi Zekeriya,

I deeply apologize for the earlier confusion and for taking up your time with questions that turned out to be unnecessary. It was my mistake for not correctly following the available guidance.

I found the information you provided about using the correct API endpoints for running scenarios with specific agents. Specifically, I used the endpoint GET /api/Scenario/{id}/run/agent/{agentid} as you described.

By following this information, I was able to successfully start the scenario with the correct agent. Thank you very much for your help and the detailed instructions you provided.

Best regards,
Ivan Khainatsky

I am happy to spend my time for your success.
Great to hear that it works now :slight_smile:

Just a quick tip that you can use gateway page for to test any apis, and then try to implement it directly for your app.

It also gives you the exact curl command which then can help you convert it to your python script.

Thanks!

Hi,
I’ve not received any documentation yet.

I would like to use “Make” to call the automation. No idea what curl is or how to use it, I was expecting a webhook so it could fire.

Could you please send the documentation? Thanks!

Hi @Pazza,

Please check this out:

Thanks for the info. I am nearly there! thanks to the video and instructions.

I can run the scenario from within Swagger by clicking Execute.

How though do you run it from Make?

I guess you have to do something with the URL and an HTTP call using this. (ID changed when posting)

URL
https://gateway.u-xer.com/api/Scenario/XXX-XXXXXX-XXXXX/run

METHOD
Get

No idea here, can anyone provide a screenshot of how? thanks!
I seem to get a 401 error after running this so the server must recognize the call but it is not authenticated. My guess is you have to combine auth and scenario run together.

Thanks in advance

You have to insert “Bearer xxxx” (token) to the header data https://www.make.com/en/help/tools/http#create-an-api-key-connection-for-the-make-an-api-key-auth-request-module

Authorization: Bearer xxxxx

Thanks bukit!

I just cannot fathom how to get this to work.

Any chance of a video of the steps from beginning to end.

I simply want to fire a scenario from Make.

Unfortunately, if I cannot fathom this, then U-xer is not for me.

SOLVED!

Authorization was required in the last box

2 Likes

Congrats :facepunch: Make is poorly documented unfortunately.

I’d suggest try the API call using uxer swagger first, then postman/hoppscotch(save the request for future use), if both work, then use it on automation platform like make/zapier/n8n.

2 Likes