How to Use the Path to a Previous Step in the Code Instead of a Specific Number in Axios API Request?

This topic was automatically generated from Slack. You can find the original thread here.

I want to use the path to a previous step and use that in the code instead of 231225023, how do I do that?

const axios = require('axios');

// WooCommerce API URL and version
const apiURL = 'https://www.tomii.nu/wp-json/wc/v3/';
const consumerKey = 'ck_erhjore7f87d77gd7dg97gd9gd9779d9770';
const consumerSecret = 'cs_errsf46a49re7f87d77gd7dg97gd9gd9779d928';

// Endpoint for retrieving all orders
const ordersEndpoint = 'orders';

// Order number to search for
const targetOrderNumber = '231225023';

// Construct the URL for the API request
const url = `${apiURL}${ordersEndpoint}?consumer_key=${consumerKey}&consumer_secret=${consumerSecret}`;

// Make the API request to retrieve all orders
axios.get(url)
  .then(response => {
    // Check if the request was successful (status code 200)
    if (response.status === 200) {
      // Find the order with the specified order number
      const targetOrder = response.data.find(order => order.number === targetOrderNumber);

      if (targetOrder) {
        console.log(`Found order with number ${targetOrderNumber}:\n`, targetOrder);
      } else {
        console.log(`Order with number ${targetOrderNumber} not found.`);
      }
    } else {
      // Handle the error
      console.error(`Error: ${response.status} - ${response.statusText}`);
    }
  })
  .catch(error => {
    // Handle request error
    console.error(`Error: ${error.message}`);
  });

To use the output from a previous step in your Pipedream workflow, you can reference the step’s exported data using the steps object. Here’s how you can modify your code to use the order number from a previous step: import { axios } from "@pipedream/platform"; export default defineComponent({ async run({ steps, $ }) { // WooCommerce API URL and version const apiURL = 'https://www.tomii.nu/wp-json/wc/v3/'; const consumerKey = 'ck_erhjore7f87d77gd7dg97gd9gd9779d9770'; const consumerSecret = 'cs_errsf46a49re7f87d77gd7dg97gd9gd9779d928'; // Endpoint for retrieving all orders const ordersEndpoint = 'orders'; // Replace '231225023' with the order number from the previous step // For example, if the previous step is named 'trigger', and the order number is exported as 'order_number' const targetOrderNumber = steps.trigger.event.order_number; // Construct the URL for the API request const url = `${apiURL}${ordersEndpoint}?consumer_key=${consumerKey}&consumer_secret=${consumerSecret}`; // Make the API request to retrieve all orders const response = await axios($, { method: "GET", url: url, }); // Check if the request was successful (status code 200) if (response.status === 200) { // Find the order with the specified order number const targetOrder = response.data.find(order => order.number === targetOrderNumber); if (targetOrder) { console.log(`Found order with number ${targetOrderNumber}:\n`, targetOrder); return targetOrder; } else { console.log(`Order with number ${targetOrderNumber} not found.`); return `Order with number ${targetOrderNumber} not found.`; } } else { // Handle the error throw new Error(`Error: ${response.status} - ${response.statusText}`); } }, }); Please replace steps.trigger.event.order_number with the actual path to the order number from your previous step. The steps object is a map of the names of previous steps to their exports. If your previous step is named differently or the

I want to use the path to a previous step and use that in the code instead of 231225023 (steps.node_1.$return_value), how do I do that?

Im adding “steps.node_1.$return_value” like this

// Order number to search for
const targetOrderNumber = steps.node_1.$return_value;

and it throws an error.
CODE ERROR
STEPS IS NOT DEFINED

DETAILS

ReferenceError: steps is not defined
    at Object.<anonymous> (/tmp/__pdg__/dist/code/1783092a450c5c3b697f93b67773e2f9dfcacfe2a658331e067c052dc70539ca/code.js:12:27)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)
const axios = require('axios');

// WooCommerce API URL and version
const apiURL = 'https://www.tomii.nu/wp-json/wc/v3/';
const consumerKey = 'ck_erhjore7f87d77gd7dg97gd9gd9779d9770';
const consumerSecret = 'cs_errsf46a49re7f87d77gd7dg97gd9gd9779d928';

// Endpoint for retrieving all orders
const ordersEndpoint = 'orders';

// Order number to search for
const targetOrderNumber = '231225023';

// Construct the URL for the API request
const url = `${apiURL}${ordersEndpoint}?consumer_key=${consumerKey}&consumer_secret=${consumerSecret}`;

// Make the API request to retrieve all orders
axios.get(url)
  .then(response => {
    // Check if the request was successful (status code 200)
    if (response.status === 200) {
      // Find the order with the specified order number
      const targetOrder = response.data.find(order => order.number === targetOrderNumber);

      if (targetOrder) {
        console.log(`Found order with number ${targetOrderNumber}:\n`, targetOrder);
      } else {
        console.log(`Order with number ${targetOrderNumber} not found.`);
      }
    } else {
      // Handle the error
      console.error(`Error: ${response.status} - ${response.statusText}`);
    }
  })
  .catch(error => {
    // Handle request error
    console.error(`Error: ${error.message}`);
  });

It looks like you’re trying to use the steps object in a Node.js code step, but you’re encountering a “STEPS IS NOT DEFINED” error. This is likely because you’re using the require syntax to import axios, which is not supported in Pipedream’s Node.js environment. Instead, you should use the import syntax provided by Pipedream and make sure to use the axios function from the @pipedream/platform package. Here’s how you can modify your code to work within a Pipedream Node.js code step, including accessing the $return_value from a previous step: ``` import { axios } from “@pipedream/platform”; export default defineComponent({ async run({ steps, $ }) { // WooCommerce API URL and version const apiURL = https://www.tomii.nu/wp-json/wc/v3/; const consumerKey = ‘ck_erhjore7f87d77gd7dg97gd9gd9779d9770’; const consumerSecret = ‘cs_errsf46a49re7f87d77gd7dg97gd9gd9779d928’; // Endpoint for retrieving all orders const ordersEndpoint = ‘orders’; // Order number to search for // Replace ‘node_1’ with the actual name of the step you’re referencing const targetOrderNumber = steps.node_1.$return_value; // Construct the URL for the API request const url = ${apiURL}${ordersEndpoint}; // Make the API request to retrieve all orders try { const response = await axios($, { url: url, auth: { username: consumerKey, password: consumerSecret, }, }); // Check if the request was successful (status code 200) if (response.status === 200) { // Find the order with the specified order number const targetOrder = response.data.find(order => order.number === targetOrderNumber); if (targetOrder) { console.log(Found order with number ${targetOrderNumber}:\n, targetOrder); return targetOrder; } else { console.log(Order with number ${targetOrderNumber} not found.); } } else { // Handle the error console.error(`Error: ${response.status} -

const axios = require('axios');

// WooCommerce API URL and version
const apiURL = 'https://kemii.nu/wp-json/wc/v3/';
const consumerKey = 'ck_71f115aa0fe5e67a42e446d55637223586cbe770';
const consumerSecret = 'cs_e6a49a1d6b56a126db506042d8a68ce6d062eb28';

// Endpoint for retrieving all orders
const ordersEndpoint = 'orders';

// Order number to search for
const targetOrderNumber = '231225023';

// Construct the URL for the API request
const url = `${apiURL}${ordersEndpoint}?consumer_key=${consumerKey}&consumer_secret=${consumerSecret}`;

// Make the API request to retrieve all orders
axios.get(url)
  .then(response => {
    // Check if the request was successful (status code 200)
    if (response.status === 200) {
      // Find the order with the specified order number
      const targetOrder = response.data.find(order => order.number === targetOrderNumber);

      if (targetOrder) {
        console.log(`Found order with number ${targetOrderNumber}:\n`, targetOrder);
      } else {
        console.log(`Order with number ${targetOrderNumber} not found.`);
      }
    } else {
      // Handle the error
      console.error(`Error: ${response.status} - ${response.statusText}`);
    }
  })
  .catch(error => {
    // Handle request error
    console.error(`Error: ${error.message}`);
  });
 import { axios } from "@pipedream/platform";  export default defineComponent({   props: {     woocommerce: {       type: "app",       app: "woocommerce",     },   },   async run({ steps, $ }) {     // Endpoint for retrieving all orders     const ordersEndpoint = 'orders';      // Order number to search for     const targetOrderNumber = '231225023';      // Make the API request to retrieve all orders     const response = await axios($, {       url: `https://${this.woocommerce.$auth.url}/wp-json/wc/v3/${ordersEndpoint}`,       auth: {         username: `${this.woocommerce.$auth.key}`,         password: `${this.woocommerce.$auth.secret}`,       },     });      // Check if the request was successful (status code 200)     if (response.status === 200) {       // Find the order with the specified order number       const targetOrder = response.data.find(order => order.number === targetOrderNumber);        if (targetOrder) {         console.log(`Found order with number ${targetOrderNumber}:\n`, targetOrder);       } else {         console.log(`Order with number ${targetOrderNumber} not found.`);       }     } else {       // Handle the error       throw new Error(`Error: ${response.status} - ${response.statusText}`);     }   }, }); 
```  Please replace the placeholder `https://kemii.nu/wp-json/wc/v3/` with your actual WooCommerce store URL and ensure that your WooCommerce app is connected with the correct credentials in Pipedream. The `axios` call has been adapted to use the Pipedream platform's `axios` module, and the authentication is handled using the connected WooCommerce app's credentials.
const axios = require('axios');

// WooCommerce API URL and version
const apiURL = 'https://tomii.nu/wp-json/wc/v3/';
const consumerKey = 'ck_71f1ighiuhu7878kjhkl6876868770';
const consumerSecret = 'cs_e6a49a1d6b876868687jhghjh68ce6d062eb28';

// Endpoint for retrieving all orders
const ordersEndpoint = 'orders';

// Order number to search for
const targetOrderNumber = '231225023';

// Construct the URL for the API request
const url = `${apiURL}${ordersEndpoint}?consumer_key=${consumerKey}&consumer_secret=${consumerSecret}`;

// Make the API request to retrieve all orders
axios.get(url)
  .then(response => {
    // Check if the request was successful (status code 200)
    if (response.status === 200) {
      // Find the order with the specified order number
      const targetOrder = response.data.find(order => order.number === targetOrderNumber);

      if (targetOrder) {
        console.log(`Found order with number ${targetOrderNumber}:\n`, targetOrder);
      } else {
        console.log(`Order with number ${targetOrderNumber} not found.`);
      }
    } else {
      // Handle the error
      console.error(`Error: ${response.status} - ${response.statusText}`);
    }
  })
  .catch(error => {
    // Handle request error
    console.error(`Error: ${error.message}`);
  });
 import { axios } from "@pipedream/platform";  export default defineComponent({   props: {     woocommerce: {       type: "app",       app: "woocommerce",     },   },   async run({ steps, $ }) {     const targetOrderNumber = '231225023';     const ordersEndpoint = 'orders';      const response = await axios($, {       url: `https://${this.woocommerce.$auth.url}/wp-json/wc/v3/${ordersEndpoint}`,       auth: {         username: `${this.woocommerce.$auth.key}`,         password: `${this.woocommerce.$auth.secret}`,       },     });      if (response.status === 200) {       const targetOrder = response.data.find(order => order.number === targetOrderNumber);        if (targetOrder) {         console.log(`Found order with number ${targetOrderNumber}:\n`, targetOrder);       } else {         console.log(`Order with number ${targetOrderNumber} not found.`);       }     } else {       throw new Error(`Error: ${response.status} - ${response.statusText}`);     }   }, }); 
``` Please replace the placeholder `https://tomii.nu/wp-json/wc/v3/` with the actual URL of your WooCommerce store, and ensure that your WooCommerce app is connected with the correct API key and secret in Pipedream.