Integrating Pipedream Workflow into node js

109 views Asked by At

I'm an absolute beginner coder and trying to learn some of the basics with smaller projects.

Lately I've been trying to load the content of a Microsoft to list on my web site.

I've managed to pull the content with the help of pipedream and Microsoft graph but I'm failing to integrate the pipedream workflow into my JavaScript file.

This is the node.js code I wrote so far

This the pipedream workflow:

Every time I get this console error:

SyntaxError:
Unexpected token '<', "<p><b>Succ"... is not valid JSON

I guess the response I receive from the API isn't a JSON file?

How could I resolve that?

1

There are 1 answers

0
Serge E Wong On

leemann

That's cool that you are using Pipedream

I'm confident to know what's the issue here.

See, the error your are experiencing is very much likely because your workflow isn't configured to return a custom HTTP response.

The default response of a workflow ressembles this text:

Success!

To customize this response, check out our docs here

This certainly isn't data in JSON format.

In order for your workflow to return JSON, you need to do two things in this workflow.

  1. Setup your trigger to allow returning a custom HTTP response. When you add your workflow trigger, select the option for custom responses:

enter image description here

  1. Adjust your code in your workflow step to return the custom HTTP response. This is accomplish by using Pipedream's $.respond directive

In your case, you'd need to set the axios response to a variable, such as in:

... const body = await axios($, { ...

And return the body with the response using $.respond:

await $.respond({
  status: 200,
  headers: {
    "Content-Type": "application/json"
  },
  body,
});

For more information, take a look at the documentation, Using custom code with $.respond().

Good luck on your Pipedream endeavours!