This topic was automatically generated from Slack. You can find the original thread here.
Mitch McAlister : hey there. I’m a bit of a noob at this. I’m trying to do something very basic and easy, but I’m hitting a wall. When I run an HTTP get, I can see the response in the console log, but I’m having trouble returning it for use in subsequent steps. Here’s my code:
var axios = require('axios');
var config = await {
method: 'get',
url: 'https://boards-api.greenhouse.io/v1/boards/juvo/jobs',
headers: { }
};
// log response data
await axios(config)
.then((response) => {
console.log((response.data));
console.log((response.status));
console.log(response.statusText);
console.log(response.headers);
console.log(response.config);
})
.catch(function (error) {
console.log(error);
})
//return data to export for future steps
!!! what do I put here to ensure that the response from the GET will return for future steps???
Dylan Sather (Pipedream) : If you add a new step to your workflow, you’ll see the HTTP / Webhook Request action on the right. I’d recommend using that, since it allows you to pass any method / URL / headers / etc. to it, and will return the response body for use in future steps. Take a look at an example here. Just click on the optional fields (e.g. + headers) below the params I’ve entered to add any other headers / data you’d like.
If you want code-level control, you can re-write what you have to something like this. You’ll see the returned data in the variable steps.nodejs.$return_value, where you can access the body, status, and other data returned from axios .
Dylan Sather (Pipedream) : The only real difference in the two methods is:
• You don’t have to write code in the first, but do in the second
• The first method returns just the response body, but the second returns the whole axios object - the body, status, etc.
Mitch McAlister : - I’ve got everything pulling from greenhouse properly, and I setup a POST to our CMS (Webflow), but I don’t know how to perform the post even for multiple records (from the greenhouse response). I’m currently only able to create 1 single record.
the way I have my parameters setup, they are calling the step path, which has an item specific path. do you have any tips for how to loop the request for each item in the response object?
Dylan Sather (Pipedream) : in case it wasn’t obvious, you can click into the code for any step (even pre-existing actions) and modify it. So I’d recommend modifying this step to accept the records from the Greenhouse response and loop over them in a similar manner
Mitch McAlister : ok. I gave it a go… but I’m running into some issues.
Step 1 steps.trigger
Step 2 steps.getjobs
Step3 - steps.webflow_create_collection_item_1
const axios = require("axios");
//store each response and return them in this array
const responses = []
for (const num of steps.getjobs.$return_value) {
const resp = await require("@pipedreamhq/platform").axios(this, {
method: "POST",
url: 'https://api.webflow.com/collections/${params.collection_id}/items',
headers: {
Authorization: `Bearer ${auths.webflow.oauth_access_token}`,
"Content-Type": "application/json",
"Accept": "application/json",
"accept-version": "1.0.0"
},
data: {
num, // Will send the current value of num in the loop
fields: {
name: params.name,
location: params.offices,
url: params.url,
_archived: params._archived,
_draft: params._draft,
},
},
});
responses.push(resp.data)
}
when I try to run this, I get the following error
TypeErrorsteps.getjobs.$return_value is not iterable
at Object.module.exports (/steps/webflow_create_collection_item_1.js:7:33)
Dylan Sather (Pipedream) : steps.getjobs.$return_value is an object (just a set of key-value pairs), and you can’t iterate over objects on their own. Did you want to iterate over steps.getjobs.$[return_value.jobs](http://return_value.jobs) instead?
Dylan Sather (Pipedream) : great. Since each job is itself an object, you can reference its properties like I do in the console.log above. So you can send those in the data block of the axios request in the appropriate fields