Why am I unable to use data from a previous step in a code step?

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

I have issues using data from a previous step in a code step.

I have a first step get_tokens_from_xano which returns an object.

Then I’m trying to use this like:

  async run({ steps, $ }) {
    const url = "https://********.com/auth/token";
    const headers = {
      "********-instance": this.instanceName,
    };
    const prev = steps.get_tokens_from_xano;
    console.log(prev);

But this fails with error Cannot read properties of undefined (reading 'get_tokens_from_xano') at this specific like where I set const prev.

I’ve tried with return and $.export but both result in the same error.

Any help would be greatly appreciated!

can you show me how to use the $return_value from a step export from a previous step in my workflow titled get_tokens_from_xano?

Specifically I want to send an HTTP request with this returned value from that step as the body for the request.

Sure! To use the $return_value from the get_tokens_from_xano step and send an HTTP request with it as the body, you can use the following code in a new code step: import { axios } from "@pipedream/platform"; export default defineComponent({ async run({ steps, $ }) { const url = "https://your-api-url.com/endpoint"; const body = steps.get_tokens_from_xano.$return_value; const response = await axios(this, { method: "POST", url: url, data: body, }); return response; }, }); Replace https://your-api-url.com/endpoint with the actual URL you want to send the request to. This code sends a POST request with the $return_value from the get_tokens_from_xano step as the request body.

Thanks . In this case I was not using the $return_value since the previous step was exporting values with $.**export**("tokens", tokens); , not returning them.

Even then however, this is returning undefined

Just tested again returning a value from get_tokens_from_xano instead of exporting it, and the following throws on get_tokens_from_xano being undefined:

    const prev = steps.get_tokens_from_xano.$return_value.tokens;
    console.log(prev);

Cannot read properties of undefined (reading 'get_tokens_from_xano')

FWIW those code actions are actions saved to My actions (components). Not sure if this can make any difference in the behavior of the workflow?

Ah, so are you aware that steps aren’t available in published actions?

gosh no, I wasn’t aware

Any input data into a published action needs to a prop

Gotcha, thanks a bunch

There’s a section called “Why can’t I use steps in my published Node.js code steps?” that explains this

Sure thing

one quick question if I may. Any way to set variables global to a workflow, that can be modified in any step?

Is this something we can do with exports ($.export)? Or would I need to use the data store or temp file for that.

Thanks

Correct, for mutable data that’s common between steps, then I would recommend using a Data Store

Or you can use MySQL, Postgres, MongoDB, DynamoDB, etc

You can connect to any of those services from Pipedream

Awesome thanks!