sendgrid-nodejs: Unable to create contacts with custom fields set

Issue Summary

Unable to create contacts with custom fields set using New Marketing Campaigns PUT /marketing/contacts API

Steps to Reproduce

  1. Having custom fields created, send following payload to PUT /marketing/contacts
{
  contacts: [
   {
    email: 'user.myuser@gmail.com',
    custom_fields: {
      purchaseTime: -1,
      activations: 0,
      partner: 'none',
      userCreationTime: 1544997675,
      lastSigningTime: 1544997675,
      emailVerified: 1,
      disabled: 0,
      displayName: 'Rv',
      photoURL: 'https://lh6.googleusercontent.com/-,
      uid: 'uid'
    }
  }
  ]
}

Observe invalid custom field ids supplied - partner,emailVerified,photoURL,uid,purchaseTime,activations,userCreationTime,lastSigningTime,disabled,displayName

Technical details:

  • sendgrid-nodejs Version: 6.4.0
  • Node.js Version v12.1.0

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 39

Most upvoted comments

Seems like the current API is expecting the field_id and not the name.

If you inspect the network traffic inside SendGrid when loading the https://mc.sendgrid.com/custom-fields page you can see the response for /field_definitions that returns the field_ids as well as the names.

SendGrid either needs to display this id value on the front end or update the API to accept the name in the request.

@soramister I didn’t try myself yet, because due to missing Segments and some feature I consider switching to Mailerlite instead. Anyways, according to support, you should be able to get your created custom fields using GET https://api.sendgrid.com/v3/marketing/field_definitions call.

Then you will need to take the IDs for the custom fields you are interested in adding/updating values for, and use those in your call to add/update a contact with: PUT https://api.sendgrid.com/v3/marketing/contacts

Here is example payload support gave me. keys for custom_fields field are those special ids.

{

"contacts": [
    {
        "email": "gigifinn1232@aol.com",
        "address_line_1": "123 main st",
        "custom_fields":
            {
                "e6_T": "5555555555",
                "e5_T": "Acme Group"
            }
    }]
}

The Marketing API and custom_fields have been a real nightmare. The docs tell you to send in a custom_field ID when you’re PUTing a new contact into a marketing list. Then, when you do, it sends back a “invalid custom_field ID” message. Nowhere in the docs have I found it say you seen to send in those weird “e1_T” style custom_field ids. Anyone else?

But…when you send in a PUT request and use the “e1_T” style custom_field ID instead of the ID that is returned when you do a GET request on the custom_fields endpoint, it works perfectly to add a new contact.

I just don’t get it.

I came across this issue today. When adding a contact that includes custom fields, the api would return a job_id but the contact would never be added.

For me, the problem was that I was sending boolean values to a ‘text’ custom field. Sending those booleans as strings instead resolved my problem.

It’s fragile and often not intuitive, the Sendgrid doc says “You should save the returned id value if you ever want to update or delete custom fields.”, in my case the returned id values were those weird “e1_T” style, and using those works fine… just a pain, why they didn’t just setup to take the field name is beyond me.

I can’t even get a contact created using SendGrid’s “try it out” section of thier API without a custom field. All I get is this:

{ “errors”: [ { “field”: “”, “message”: “invalid JSON” } ] }

Yeah, the try it out doesn’t work at all really. Try it through postman. You’ll likely run into the same issues as the rest of us though.

It may take a while to see the contact created on sendgrid, has the contact been created? Your object looks good though.

It’s really odd, the contact will only get created if I don’t include custom fields. At a bit of a loss where to go from here