Skip to main content
Best answer

Formatting a request in Code mode for a custom Action

  • February 25, 2022
  • 2 replies
  • 119 views

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?

Best answer by CathalmoranBest answer by Cathalmoran

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]

      }
    }
  }

 

View original
Did this topic help you find an answer to your question?
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

  • Author
  • Beginner
  • 1 reply
  • Answer
  • March 1, 2022

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]

      }
    }
  }

 


SamB
Community Manager
Forum|alt.badge.img+11
  • Community Manager
  • 7547 replies
  • March 1, 2022

Great work here, @Cathalmoran:tada:

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