Best answer

Formatting a request in Code mode for a custom Action

  • 25 February 2022
  • 2 replies
  • 89 views

Userlevel 1

I’m a novice so hoping someone smarter than me can lend a helping hand here.

I’m testing out a custom app for Outreach.io. I’m hoping to build a simple action to POST a prospect.

I have successfully authenticated with my app and performed a test GET so all good there.

When trying to POST the prospect I think I need to reformat my request using code mode.

When I open code mode the default is populated very differently to what what is in the example POST on the Outreach API documentation.

 

"data": {
"type": "prospect",
"attributes": {
"firstName": "John"
}

V

const options = {
url: 'https://api.outreach.io/api/v2/prospects',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': `Bearer ${bundle.authData.access_token}`
},
params: {

},
body: {

'firstName': bundle.inputData.firstName
}
}

return z.request(options)
.then((response) => {
response.throwForStatus();
const results = response.json;

// You can do any parsing you need for results here before returning them

return results;
});

Do I need to fit my data into the body of the default Zapier code or what’s the direction here?

icon

Best answer by Cathalmoran 1 March 2022, 11:03

View original

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

2 replies

Userlevel 1

Solved - I needed to format it into the body like this :

 

body: {
"data":{
"type":"prospect",
"attributes":{
'firstName': bundle.inputData.firstName,
'lastName': bundle.inputData.lastName,
'company': bundle.inputData.company,
'emails': [bundle.inputData.emails]

}
}
}

 

Userlevel 7
Badge +11

Great work here, @Cathalmoran:tada:

Thanks so much for following up here to share the solution you found. It’s much appreciated! :relaxed: