Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to pass a variable parameter when connecting through a web API? #1378

Open
thions opened this issue Sep 13, 2024 · 5 comments
Open

How to pass a variable parameter when connecting through a web API? #1378

thions opened this issue Sep 13, 2024 · 5 comments
Labels

Comments

@thions
Copy link

thions commented Sep 13, 2024

We have a device monitoring scenario where there are multiple fan devices on the main monitoring screen. Clicking on each fan will display a pop-up window showing the device profile of the current fan.

WX20240913-161941@2x

WX20240913-162222@2x

So when we click on the fan in the main interface, we bind an event and pop up a window. The data of the device file in the window is intended to be obtained through the API. However, we found that when connecting to the WEB API, we can only enter one URL and there is no place to set parameters. We would like to inquire about how to pass the parameters of the device changes as variables when binding the WEB API

@unocelli
Copy link
Member

#650

@henjoe
Copy link

henjoe commented Sep 14, 2024

By the way you can actually do this using script, it might require you do some nodejs programming but it is worth it.

And on your click event simply simply select action to "Run Script", you script something like this, and accepts your API URL as parameter.

const axios = require('axios');
//For Get Request
try {
    const response = await axios.get(url, {
      headers: headers,
      params: params
    });
    console.log('GET Response:', response.data);
    return response.data;
  } catch (error) {
    handleError(error);
  }

Your headers, parameters and URL might be a parameter on your script, or you can hard coded it directly on your script.

@thions
Copy link
Author

thions commented Sep 18, 2024

Thank you everyone, let's give it a try

@Daysons
Copy link

Daysons commented Sep 19, 2024

By the way you can actually do this using script, it might require you do some nodejs programming but it is worth it.

And on your click event simply simply select action to "Run Script", you script something like this, and accepts your API URL as parameter.

const axios = require('axios');
//For Get Request
try {
    const response = await axios.get(url, {
      headers: headers,
      params: params
    });
    console.log('GET Response:', response.data);
    return response.data;
  } catch (error) {
    handleError(error);
  }

Your headers, parameters and URL might be a parameter on your script, or you can hard coded it directly on your script.

By the way you can actually do this using script, it might require you do some nodejs programming but it is worth it.

And on your click event simply simply select action to "Run Script", you script something like this, and accepts your API URL as parameter.

const axios = require('axios');
//For Get Request
try {
    const response = await axios.get(url, {
      headers: headers,
      params: params
    });
    console.log('GET Response:', response.data);
    return response.data;
  } catch (error) {
    handleError(error);
  }

Your headers, parameters and URL might be a parameter on your script, or you can hard coded it directly on your script.

May I ask how to import Node's require module? Looking forward to your reply

@henjoe
Copy link

henjoe commented Sep 19, 2024

By the way you can actually do this using script, it might require you do some nodejs programming but it is worth it.

And on your click event simply simply select action to "Run Script", you script something like this, and accepts your API URL as parameter.

const axios = require('axios');
//For Get Request
try {
    const response = await axios.get(url, {
      headers: headers,
      params: params
    });
    console.log('GET Response:', response.data);
    return response.data;
  } catch (error) {
    handleError(error);
  }

Your headers, parameters and URL might be a parameter on your script, or you can hard coded it directly on your script.

By the way you can actually do this using script, it might require you do some nodejs programming but it is worth it.

And on your click event simply simply select action to "Run Script", you script something like this, and accepts your API URL as parameter.

const axios = require('axios');
//For Get Request
try {
    const response = await axios.get(url, {
      headers: headers,
      params: params
    });
    console.log('GET Response:', response.data);
    return response.data;
  } catch (error) {
    handleError(error);
  }

Your headers, parameters and URL might be a parameter on your script, or you can hard coded it directly on your script.

May I ask how to import Node's require module? Looking forward to your reply

i actually tried it, but it fails.
I thought we can easily import any module that is in package.json, but I am wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants