This topic was automatically generated from Slack. You can find the original thread here.
if I connect to an app in a Node.js code step can I control the app within that step? For example, I need to connect to Browse_AI and then also select the Robot ID from that app for my step. Is there a way to connect the Robot ID from the Browse AI connection?
Based on the information provided in the Pipedream documentation, when you connect to an app like Browse AI in a Node.js code step, you can indeed control the app within that step by using the credentials provided through the props of the component. To select a specific Robot ID from Browse AI, you would typically use the axios request to interact with the Browse AI API, specifying the Robot ID in your API request. Here’s an example of how you might structure your Pipedream component to connect to Browse AI and select a Robot ID: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { browse_ai: { type: "app", app: "browse_ai", }, }, async run({ steps, $ }) { // Replace 'your_robot_id' with the actual Robot ID you want to select const robotId = 'your_robot_id'; return await axios($, { url: `https://api.browse.ai/v2/robots/${robotId}`, headers: { Authorization: `Bearer ${this.browse_ai.$auth.api_key}`, }, }); }, }); In this code, you would replace 'your_robot_id' with the actual Robot ID you wish to interact with. The axios request is configured to make a call to the Browse AI API endpoint for a specific robot, using the Robot ID in the URL path. If you need to dynamically select a Robot ID based on some criteria or input, you could modify the component to include an additional prop for the Robot ID or use an options method to fetch and present a list of Robot IDs to the user in the Pipedream UI.
To fetch and present a list of Robot IDs to the user in the Pipedream UI using options, you would define an options method within the props of your Pipedream component. This method would make an API call to retrieve the Robot IDs, then format them in a way that the Pipedream UI can present as selectable options. Here’s an example of how you might write this in a Pipedream component: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { robot: { type: "string", label: "Robot", description: "Select a robot by its ID", async options({}) { const response = await axios(this, { url: "https://api.your-robot-service.com/robots", headers: { Authorization: `Bearer YOUR_API_KEY`, // Add any other required headers here }, }); // Assuming the API returns an array of robots with an id property return response.map(robot => ({ label: `Robot ${robot.id}`, // Human-readable string value: robot.id, // The ID value that will be used in the component })); }, }, }, async run({steps, $}) { // You can now use `this.robot` to access the selected Robot ID in your component }, }); In this example, replace https://api.your-robot-service.com/robots with the actual URL of the API that returns the list of robots, and YOUR_API_KEY with the actual API key required for authentication. The options method makes a GET request to the API, retrieves the list of robots, and maps over the array to return an array of objects with label and value properties, which Pipedream uses to present options to the user in the UI. Please ensure that you have the correct permissions and authentication to access the API that provides the Robot IDs. If the API requires different parameters or methods, adjust the axios call accordingly.
Yes, you can pass the auth key from the app connection with Browse AI in Pipedream. When you use the Browse AI app in a Pipedream component, the this.browse_ai.$auth object contains the properties for each key or token the user enters, including the api_key. Here’s an example of how you can use the api_key in a Pipedream component to authenticate API requests to Browse AI: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { browse_ai: { type: "app", app: "browse_ai", }, }, async run({ steps, $ }) { return await axios($, { url: `https://api.browse.ai/v2/robots`, headers: { Authorization: `Bearer ${this.browse_ai.$auth.api_key}`, }, }); }, }); In this code, the Authorization header is set with the api_key from the connected Browse AI app. This will authenticate your requests to the Browse AI API.
the response from Browse_AI with my list of robots is below. How would I format my code to allow a Pipdream User to see the list of robots and select the correct one for this step?
To allow a Pipedream user to see the list of robots from Browse AI and select the correct one for a step, you would use an options method within a prop to dynamically generate the options. Here’s an example of how you could structure the Pipedream component code to achieve this: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { browse_ai: { type: "app", app: "browse_ai", }, robot: { type: "string", label: "Robot", description: "Select the robot you'd like to use for this step", async options({ steps, $ }) { const response = await axios($, { url: `https://api.browse.ai/v2/robots`, headers: { Authorization: `Bearer ${this.browse_ai.$auth.api_key}`, }, }); // Assuming the response contains an array of robots under a `data` property return response.data.map((robot) => ({ label: robot.name, // Replace 'name' with the actual property that holds the robot's name value: robot.id, // Replace 'id' with the actual property that holds the robot's unique identifier })); }, }, }, async run({ steps, $ }) { // The selected robot's ID is now available in `this.robot` // You can use this ID to perform further actions with the selected robot }, }); In this code, the robot prop includes an options method that makes an API request to Browse AI to fetch the list of robots. It then maps over the response to return an array of options where each option has a label (the human-readable name of the robot) and a value (the unique identifier of the robot). The Pipedream user will see a dropdown list of robot names in the UI and will be able to select the correct one for the step.
Based on the response from Browse AI, you want to allow a Pipedream user to select a robot from a list of robots returned by the API. To achieve this, you can create a Pipedream component with a prop that uses the async options method to dynamically generate the options for the robot selection. Here’s an example of how you could structure the code: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { browseAI: { type: "app", app: "browse_ai", }, robot: { type: "string", label: "Robot", async options({ steps, $ }) { const response = await axios($, { url: "https://api.browse.ai/robots", headers: { "Authorization": `Bearer ${this.browseAI.$auth.oauth_access_token}`, }, }); return response.robots.items.map((robot) => { return { label: robot.name, value: robot.id }; }); }, }, }, async run({ steps, $ }) { // You can use the selected robot ID in your API requests or other logic here console.log(`Selected robot ID: ${this.robot}`); }, }); In this example, browseAI is a placeholder for the actual app name used in Pipedream. You would need to replace it with the correct app name and ensure that the app is configured correctly in Pipedream with the necessary authentication. The robot prop uses the async options method to fetch the list of robots from the Browse AI API and maps the response to the format required by Pipedream, with label and value properties for each option. The user can then select a robot from the dropdown in the Pipedream UI when configuring this step, and the selected robot’s ID will be available in the this.robot property within the run method.