Unexpected token error after adding await keyword to Node.js code

Neil Lovelace : try / catch are working for me. Thank You.
My next issue is that I can’t return / export a value from one step to the next. I have a global var called procore_token in my step (bad practice, I know). Why can I not return pro_token and have it available for use in the next step?

Something with the try / catch has caused this to stop working.

Dylan Sather (Pipedream) : I believe the value of response.data.access_token is undefined. If you try to return undefined , we won’t display any values. You’re logging response.data and note that there’s no access_token there

Neil Lovelace : Once the function returns a response and access token I am updating the value of the global variable. At the bottom of my step I am returning the value of that global var. Am I missing something? I know that I’m a novice, but, I thought I have this part right.

Dylan Sather (Pipedream) : Try to console.log(response.data.access_token)

Dylan Sather (Pipedream) : just above where you run pro_token = response.data.access_token;

Neil Lovelace : Sorry to be a pain in the butt.
See below.

image.png

Dylan Sather (Pipedream) : Yep that’s the value that you set at the start of your workflow. But then you reset the value to response.data.access_token; in this line:

pro_token = response.data.access_token;

So you need to log response.data.access_token, which is the value you’d expect pro_token to be after running that line. I modified the workflow to log that, take a look at the most recent execution:

Dylan Sather (Pipedream) : ```
From checkToken: undefined

Dylan Sather (Pipedream) : That’s the core issue. You’re setting pro_token to a variable that doesn’t exist

Dylan Sather (Pipedream) : You log the value of response.data above, so you can see the full contents of that response to confirm that there’s no access_token

Neil Lovelace : Hmm… well that’s not good.
I’ll go back and see if I can correct this. Thank you again for your help and patience.

Dylan Sather (Pipedream) : :thumbsup:

Neil Lovelace : Good Morning Slackers… that was intended to be humorous.
First question of the day: How can I retrieve a response from an API endpoint and limit that response to only the data. I just received a response that included 239 rows of information, of which, I only need the last 5 or 6 rows. Is this possible? If so, how?
Thanks!

Dylan Sather (Pipedream) : IF you’re using axios and calling it like so: const response = await axios.get(...), response.data will contain the data.

If that response is an array and you want to grab a few elements, you can use a few methods. Try checking out Array.prototype.slice() - JavaScript | MDN

Neil Lovelace : That makes perfect sense. I suppose that when I test using PostMan it is only showing the data and stripping out the headers, etc. PostMan has spoiled me.