Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Omit empty merge field choices array to pass API validation #36

Merged
merged 1 commit into from Dec 2, 2019

Conversation

nmec
Copy link
Contributor

@nmec nmec commented Aug 15, 2019

Currently it is not possible to create new merge fields that are not options as the Mailchimp API does not accept null as an empty array, however it is possible to omit the field and pass validation.

Consider the struct:

gochimp3.MergeField{
  Tag: "My example field",
  Type: "text",
}

Will be encoded by json.Marshal as:

{
  "tag": "",
  "name": "My example field",
  "type": "text",
  "required": false,
  "default_value": "",
  "public": false,
  "display_order": 0,
  "options": {
    "default_Country": 0,
    "phone_format": "",
    "date_format": "",
    "choices": null,
    "size": 0
  },
  "help_text": ""
}

However Mailchimp will reject this request with an error, as choices is null rather than an empty array: []:

Invalid Resource : The resource submitted could not be validated. For field-specific details, see the 'errors' array. : [{options.choices Schema describes array, NULL found instead}]

There is an open issue on Go discussing the options for encoding as an empty array instead of null - golang/go#27589 - but in the meantime it is possible to omit the empty choices field and Mailchimp will create the merge field as expected.

@nmec
Copy link
Contributor Author

nmec commented Dec 2, 2019

Anything we need to do to get this merged @zeekay @davidtai ?

@zeekay zeekay merged commit 026e350 into hanzoai:master Dec 2, 2019
@zeekay
Copy link
Member

zeekay commented Dec 2, 2019

Looks good! Merged in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants