6

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": "p001@mymaildomain.xxx"
            },
            {
                "field": "EMAIL",
                "op": "is",
                "value": "p002@mymaildomain.xxx"
            }
        ]
    }
}

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.
ekad
  • 14,436
  • 26
  • 44
  • 46
Hans Hansen
  • 61
  • 1
  • 2
  • That looks right to me; I tried that exact query just now on my own account and it worked -- maybe the issue was resolved? – TooMuchPete Oct 01 '15 at 15:35
  • @Hans: Can you please tell me how you test segment creation on mailchimp playgroung; I am also facing same problem but i have different merge field (i.e. Type). Can you please help me to find out my problem. Please have a look on my question on SO - http://stackoverflow.com/questions/41465345/issue-when-requsting-create-segments-api-v3-through-php-wrapper | Github - https://github.com/drewm/mailchimp-api/issues/160 – Ishan Jain Jan 10 '17 at 10:58

2 Answers2

8

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":"p001@mymaildomain.xxx"
                                },
                                {
                                    "condition_type":"EmailAddress",
                                    "field":"merge0",
                                    "op":"is",
                                    "value":"p002@mymaildomain.xxx"
                                }
                ]
    }
codebusta
  • 1,922
  • 1
  • 14
  • 15
  • 1
    Just to mention the value for the field can be either merge0 or EMAIL. – codebusta Dec 09 '15 at 09:27
  • Thank you so much I have been testing for a day using trial and error. Note. I was using EMAIL that did not work so I used merge0 and worked like a charm thanks ) – xiarnousx Jan 22 '16 at 11:03
  • You are welcome, I'm glad it saved you some time and nerves ;) – codebusta Jan 22 '16 at 11:44
  • @CodeBusta: Sorry, I know this is not right way to contact someone on SO; But i need help for Create Segments using mailchimp API. I also facing same problem but i have different merge field (i.e. Type). Can you please help me to find out my problem. Please have a look on my question on SO - http://stackoverflow.com/questions/41465345/issue-when-requsting-create-segments-api-v3-through-php-wrapper | Github - https://github.com/drewm/mailchimp-api/issues/160 – Ishan Jain Jan 10 '17 at 10:59
2

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.

Y.K.
  • 290
  • 2
  • 9