Cannot create segment using MailChimp API v3
Asked Answered
F

2

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": "[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.
Foison answered 29/9, 2015 at 16:23 Comment(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?Morelock
@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 - #41465845 | Github - github.com/drewm/mailchimp-api/issues/160Pharmacology
L
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":"[email protected]"
                                },
                                {
                                    "condition_type":"EmailAddress",
                                    "field":"merge0",
                                    "op":"is",
                                    "value":"[email protected]"
                                }
                ]
    }
Lauder answered 9/12, 2015 at 9:23 Comment(4)
Just to mention the value for the field can be either merge0 or EMAIL.Lauder
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 )Lands
You are welcome, I'm glad it saved you some time and nerves ;)Lauder
@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 - #41465845 | Github - github.com/drewm/mailchimp-api/issues/160Pharmacology
B
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.

Behalf answered 16/5, 2018 at 14:33 Comment(1)
Agreed - I've seen this happen when passing an empty value for a defined field too.Nonna

© 2022 - 2024 — McMap. All rights reserved.