Custom Javascript workflow has issues accessing the OneUptime API #632

Closed
opened 2026-04-05 16:21:32 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @Overflow0xFFFF on 11/26/2024

Describe the bug
When using Axios to query OneUptime's Alerts API with headers set as instructed, Axios receives a 401 Unauthorized error.

To Reproduce
Steps to reproduce the behavior:

  1. Create a new workflow.
  2. Add a secret apiKey variable to the workflow that holds the contents of a OneUptime API Key.
  3. Add a projectId variable to the workflow that holds the contents of a OneUptime project ID.
  4. Add a manual trigger.
  5. Connect a "Run Custom Javascript" tile with the following code, add the aforementioned variables as arguments, and run the workflow:
const API_KEY = String(args['apiKey']);
const PROJECT_ID = String(args['projectId']);
const ONEUPTIME_URL = 'example.com'

const data = {};
const config = {
  headers: {
    "Accept": "application/json",
    "ApiKey": API_KEY,
    "Content-Type": "application/json;charset=UTF-8",
    "ProjectID": PROJECT_ID,
    "User-Agent": "Axios"
  }
}
console.log("Request Data: " + JSON.stringify(data));
let alerts = await axios
  .get(`https://${ONEUPTIME_URL}/api/alert/get-list`, data, config)
  .then((response) => {
    console.log('Response Status: ' + response.status);
    console.log('Response Headers: ' + response.headers);
    console.log('Response Data: ' + JSON.stringify(response.data));
    return response.data;
  })
  .catch((err) => {
    console.log('Axios error: ' + err);
    console.log('Response Status: ' + err.response.status);
    console.log('Response Headers: ' + err.response.headers);
    console.log('Response Data: ' + JSON.stringify(err.response.data));
  });
console.log("Alerts: " + alerts);
return alerts;

Expected behavior
A list of alerts present in the system is returned from the Run Custom Javascript tile.

Screenshots
n/a

Desktop (please complete the following information):

  • OS: Ubuntu 22.04 LTS
  • Browser: Firefox
  • Version: 132.0.2

Smartphone (please complete the following information):

  • Device: n/a
  • OS: n/a
  • Browser: n/a
  • Version: n/a

Deployment Type
Self-hosted

Additional context
The error message returned from the workflow on my end is:

{
  "error": "A user should be logged in to read record of Alert."
}

The same API key and Project ID were used to test the same endpoint using Insomnia, and there were no issues.
The same API key and Project ID were also used directly in the workflow instead of passed by arguments, and this did not change the response.

*Originally created by @Overflow0xFFFF on 11/26/2024* **Describe the bug** When using Axios to query OneUptime's Alerts API with headers set as instructed, Axios receives a 401 Unauthorized error. **To Reproduce** Steps to reproduce the behavior: 1. Create a new workflow. 2. Add a secret `apiKey` variable to the workflow that holds the contents of a OneUptime API Key. 3. Add a `projectId` variable to the workflow that holds the contents of a OneUptime project ID. 4. Add a manual trigger. 5. Connect a "Run Custom Javascript" tile with the following code, add the aforementioned variables as arguments, and run the workflow: ```javascript const API_KEY = String(args['apiKey']); const PROJECT_ID = String(args['projectId']); const ONEUPTIME_URL = 'example.com' const data = {}; const config = { headers: { "Accept": "application/json", "ApiKey": API_KEY, "Content-Type": "application/json;charset=UTF-8", "ProjectID": PROJECT_ID, "User-Agent": "Axios" } } console.log("Request Data: " + JSON.stringify(data)); let alerts = await axios .get(`https://${ONEUPTIME_URL}/api/alert/get-list`, data, config) .then((response) => { console.log('Response Status: ' + response.status); console.log('Response Headers: ' + response.headers); console.log('Response Data: ' + JSON.stringify(response.data)); return response.data; }) .catch((err) => { console.log('Axios error: ' + err); console.log('Response Status: ' + err.response.status); console.log('Response Headers: ' + err.response.headers); console.log('Response Data: ' + JSON.stringify(err.response.data)); }); console.log("Alerts: " + alerts); return alerts; ``` **Expected behavior** A list of alerts present in the system is returned from the Run Custom Javascript tile. **Screenshots** n/a **Desktop (please complete the following information):** - OS: Ubuntu 22.04 LTS - Browser: Firefox - Version: 132.0.2 **Smartphone (please complete the following information):** - Device: n/a - OS: n/a - Browser: n/a - Version: n/a **Deployment Type** Self-hosted **Additional context** The error message returned from the workflow on my end is: ``` { "error": "A user should be logged in to read record of Alert." } ``` The same API key and Project ID were used to test the same endpoint using Insomnia, and there were no issues. The same API key and Project ID were also used directly in the workflow instead of passed by arguments, and this did not change the response.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/oneuptime#632