A couple of issues making HTTP requests from a workflow

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

ibrahim abou khashabh : I am trying to integrate shoebox with pipedream, I made a trigger to run the workflow in pipedream.
I get the data from shoebox api via the below code and it seems not error popup, but not sure how can I fetch the data! I have this code output = { participant: body[0] }; but it does not work, any help?
const fetch=require(‘node-fetch’);
const sboapi = ‘xxxxx?limit=1’; //Keep the “?limit=1”, only replace <YOUR-API-ENDPOINT-HERE> with your API Endpoint
const sboapikey = ‘xxxxx’
var headers = {
‘x-api-key’: sboapikey
}
const res = await fetch(sboapi, { method: ‘GET’, headers: headers});
const body = await res.json();

Dylan Sather (Pipedream) : what does the value of the body variable contain once you fetch it?

Are you seeing a specific error with the code you’re running?

ibrahim abou khashabh : No error in the code, it seems the trigger is working and the node.js code works. but how can I see the data, or fetch it from the body variable?

ibrahim abou khashabh : coz I need to pass the data to another app (hubspot) that already integrated with pipedream

Dylan Sather (Pipedream) : Try return body at the end of that code

Dylan Sather (Pipedream) : That’ll let you access the data in the next step. Check out our docs on step exports for more information on that

ibrahim abou khashabh : That’s great, thank you.
another question please:
I need to enter the data to hubspot as contact.

ibrahim abou khashabh : as I can see you have hubspot integration to get the contact, can I use it to insert the contact? or I have to run Node js code with hubspot?

Dylan Sather (Pipedream) : In this case we don’t yet have an action for creating a contact, but yes, you can run any Node.js code you’d like on Pipedream, so I’d recommend choosing the option to Run Node.js code with Hubspot and modifying that API request to create a new contact according to the Hubspot API docs.

This is a great resource on making HTTP requests with Node.js on Pipedream, so that should help you modify the code to make the right request. Check out Make HTTP Requests with Node.js specifically

ibrahim abou khashabh : I tried to do so depend on hubspot doc:

ibrahim abou khashabh : var request = require(“request”);

var options = {
method: ‘POST’,
url: ‘https://api.hubapi.com/crm/v3/objects/contacts’,
qs: {hapikey: ‘7b412fb2-2a86-49c7-8e9d-f659f5ccc703’},
headers: {accept: ‘application/json’, ‘content-type’: ‘application/json’},
body: {
properties: {
company: ‘Biglytics’,
email: ‘bcooper@biglytics.net’,
firstname: ‘Bryan’,
lastname: ‘Cooper’,
phone: ‘(877) 929-0687’,
website: ‘biglytics.net
}
},
json: true
};

request(options, function (error, response, body) {
if (error) throw new Error(error);

console.log(body);
});

ibrahim abou khashabh : I see this error:

ACTIVE_HANDLEThis step was still trying to run code when the step ended. Make sure you promisify callback functions and await all Promises. (Reason: GetAddrInfoReqWrap, Learn more: https://pipedream.com/docs/workflows/steps/code/async)

Dylan Sather (Pipedream) : The request package has actually been deprecated: request - npm

It also doesn’t support Promises, which you’ll need to run the code synchronously on Pipedream (read more here: Running asynchronous code) .

axios does support Promises and all of the examples on the docs I linked to above should work for you. The main difference between request and axios is that you’ll need to pass the data in the POST body in the data property instead of the body property