Best answer

Friendly field labels / names - what format API response should I provide?

  • 24 February 2022
  • 4 replies
  • 361 views

Userlevel 1

Hi folks,

I am working on a Zapier integration for an online form builder. Each unique form for our users has lots of long, auto-generated field names.

We have a trigger called “New form entries”, which polls our server for form entries, and comes back like this:

[
{
"id": "6209aee326baa600224d822c",
"email_907058157108782": "test@test.com",
"phone_589083232390193": "12345",
},
{
"id": "61fd629f19408200225e1893",
"email_907058157108782": "test@test2.com",
"phone_589083232390193": "54321",
},
]

However, this results in end users seeing these really long, gross field names in the Zapier interface:

 

My question: how do I get Zapier to display friendly labels to the user, whilst using the unique field IDs behind the scenes?

I’m thinking of returning something like the following, but I need to know how to actually use “friendlyFieldName” and “value” in Zapier!-

[
{
"id": "62179ec5ab9daa0022df7d1d",
"text_576692390099896": {
"friendlyFieldName": "What is your favourite colour?",
"value": "Blue"
},
"email_282478176629848": {
"friendlyFieldName": "What is your email address?",
"value": "test@test.com"
}
},
{
"id": "6217903dab9daa0022df7a2e",
"text_576692390099896": {
"friendlyFieldName": "Text field on page 1",
"value": "My name"
},
"email_282478176629848": {
"friendlyFieldName": "Email address",
"value": "foo@bar.com"
}
}
]

Thank you :)

icon

Best answer by harveygrowform 1 March 2022, 18:51

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.

4 replies

Userlevel 1

Update: I solved this by using field labels as unique identifiers (eg. “What is your name?”), as I don’t believe it’s possible to have IDs/friendly names for fields like this in Zapier. 

Userlevel 7
Badge +9

I think this is probably the best approach. Field names in output fields really just need to help the user set up field mapping in the Zap Editor.

The other way to go is to use an output fields definition. But because your fields are user defined (custom/dynamic), that would involve adding a function to query an endpoint to get the field level meta data to dynamically return the user friendly labels. You already have those in your response payload, so that wouldn’t make sense for your use case.

For those unable to change the actual payload of the response from the API (probably the most common case here), you can use scripting to grab the response, flatten/transform the array of responses, and return that new array to the Zap.

 

Something like

 

const formatFieldNames = (form) => {

   const cleanedOutput = {id: form.id}

   for (prop in form){

       if (prop != 'id' && form[prop].friendlyFieldName){

          cleanedOutput[form[prop].friendlyFieldName] = form[prop].value;

       }

   }

   return cleanedOutput;

}

return input.map(form => formatFieldNames(form));

 

Where “form” is the response from your API

Would yield 

[

  {

    id: '62179ec5ab9daa0022df7d1d',

    'What is your favourite colour?': 'Blue',

    'What is your email address?': 'test@test.com'

  },

  {

    id: '6217903dab9daa0022df7a2e',

    'Text field on page 1': 'My name',

    'Email address': 'foo@bar.com'

  }

]

Userlevel 7
Badge +9

Thanks for coming back to update the thread on what worked for you, @harveygrowform! We love to see it. 🙂

@harveygrowform Hey, yes you are able to do that but for that You need to create special function in Zapier CLI to fetch dynamic labels, your solution is good to the moment until someone change title then mapped key in zaps change and they wont get the data. If you need any more help @ me.