To integrate the text data from the previous step steps.code.$return_value.groups
into your Python code within a Pipedream workflow, you’ll need to adjust your approach since the provided Python code cannot be directly used in Pipedream’s Python code steps. However, I can guide you on how to adapt this logic using Pipedream’s Node.js environment, which is the primary environment for Pipedream workflows. Given the constraints, here’s how you can adapt your logic to work within a Pipedream Node.js code step, including fetching the kolli-ids
from a previous step and making requests to the WooCommerce API: ```
import { axios } from “@pipedream/platform” export default defineComponent({ props: { woocommerce: { type: “app”, app: “woocommerce”, }, }, async run({ steps, $ }) { const base_url = https://${this.woocommerce.$auth.url}/wp-json/wc/v3/
const kolli_ids = steps.code.$return_value.groups // Adjusted to fetch from previous step for (const kolli_id_data of kolli_ids) { const kolli_id = kolli_id_data[“kolli-id”] const response = await axios($, { url: ${base_url}orders?search=${kolli_id}
, auth: { username: ${this.woocommerce.$auth.key}
, password: ${this.woocommerce.$auth.secret}
, }, }) const orders = response.data if (orders.length > 0) { const order = orders[0] // Assuming the kolli-id is unique and only appears in one order const message = Din order ${order.number} blev tidigare inlämnad till PostNord
// Sending a customer message to the order await axios($, { method: “post”, url: ${base_url}orders/${order.id}/customer-notes
, auth: { username: ${this.woocommerce.$auth.key}
, password: ${this.woocommerce.$auth.secret}
, }, data: { note: message, }, }) console.log(Message sent for order: ${order.number}
) } else { console.log(No order found for kolli-id: ${kolli_id}
) } } }, })