Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot create segment using MailChimp API v3

I'm using the "playground" to test creating a segment but I keep getting validations errros

my request:

{
    "name": "MyTest",
    "options": {
        "match": "any",
        "conditions": [
            {
                "field": "EMAIL",
                "op": "is",
                "value": "[email protected]"
            },
            {
                "field": "EMAIL",
                "op": "is",
                "value": "[email protected]"
            }
        ]
    }
}

response is:

type: http://kb.mailchimp.com/api/error-docs/400-invalid-resource
title: Invalid Resource
status: 400
detail: The resource submitted could not be validated. For field-specific details, see the 'errors' array.
instance:
errors:
    0:
        field: options.conditions.item:0
        message: Data did not match any of the schemas described in anyOf.
    1:
        field: options.conditions.item:1
        message: Data did not match any of the schemas described in anyOf.
like image 225
Hans Hansen Avatar asked Sep 29 '15 16:09

Hans Hansen


2 Answers

Actually the format of the JSON should be as following:

{
    "name":"email based",
    "options":{
                "match": "any",
                "conditions":[
                                {
                                    "condition_type":"EmailAddress",
                                    "field":"merge0",
                                    "op":"is",
                                    "value":"[email protected]"
                                },
                                {
                                    "condition_type":"EmailAddress",
                                    "field":"merge0",
                                    "op":"is",
                                    "value":"[email protected]"
                                }
                ]
    }
like image 101
codebusta Avatar answered Sep 20 '22 19:09

codebusta


For others also having this issue, it also occurs when you do not provide a key / value for all defined merge fields. It can also happen if you use different case when passing in merge fields. So if you have the following merge fields defined, whether they're set as required or not :

Age Gender

Make sure you always pass in key/value pairs for both Age and Gender, using that exact same case. If you only pass in "Age=25" or "age=25", without passing in "Gender=", the above described error will occur, because it is not a well designed API.

like image 37
Y.K. Avatar answered Sep 19 '22 19:09

Y.K.