0

I'm working with MailChimp API v3.0 and I need to create a new Segment, based on the MailChimp API documentation: http://developer.mailchimp.com/documentation/mailchimp/reference/lists/segments/

It's not working in my C# API Wrapper and I´m using CURL (suggested in the documentation) for testing purposes, specifically CURL for Windows: https://curl.haxx.se/ ...here is my command:

curl --request POST --url https://usXX.api.mailchimp.com/3.0/lists/my1i5t1d/segments --header "Authorization: apikey myap1k3y-usXX" --header 'Content-Type: application/json' --data '{"name":"myDynamicSegment"}' --include

and the response message is:

HTTP/1.1 400 Bad Request
Server: nginx
Content-Type: application/problem+json; charset=utf-8
Content-Length: 203
X-Request-Id: 1d001b85-0286-4339-ab37-3cb49c6f28f8
Link: <https://us13.api.mailchimp.com/schema/3.0/ProblemDetailDocument.json>; rel="describedBy"
Date: Thu, 14 Jul 2016 22:06:08 GMT
Connection: close
Set-Cookie: _AVESTA_ENVIRONMENT=prod; path=/

{"type":"http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/","title":"JSON Parse Error","status":400,"detail":"We encountered an unspecified JSON parsing error.","instance":""}
ekad
  • 14,436
  • 26
  • 44
  • 46
nolramlinux
  • 1
  • 1
  • 3
  • I think you need quotes around the url parameter. Also try switching the quotes around your header to single quotes, it shouldnt matter but it wont hurt to try. – Unicorno Marley Jul 15 '16 at 14:45
  • I tried all the variations and is not working, I have a few days with this error and so I shared my problem. GET is working fine: curl --request GET --url https://usXX.api.mailchimp.com/3.0/lists/my1i5t1d/segments --header "Authorization: apikey myap1k3y-usXX" --include – nolramlinux Jul 15 '16 at 15:16

1 Answers1

0

Using Curl in windows cmd, the response only said:

{"type":"http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/","title":"JSON Parse Error","status":400,"detail":"We encountered an unspecified JSON parsing error.","instance":""}

But alternatively I used Git Bash( included by default when you install Git for Windows https://git-for-windows.github.io/ ) and the response was different and very useful:

{"type":"http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/","title":"Invalid Resource","status":400,"detail":"Must provide either an \"options\" field or a \"static_segment\" field","instance":""}

Based on this message I added the "static_segment" parameter in JSON and everything works great when I adjusted the command option --data:

curl --request POST --url https://usXX.api.mailchimp.com/3.0/lists/my1i5t1d/segments --header "Authorization: apikey myap1k3y-usXX" --header 'Content-Type: application/json' --data '{"name":"myDynamicSegment", "static_segment" : ["test1@domain.com", "test1@domain.com"]}' --include

Comments about the problem/solution:

Problem solved!

nolramlinux
  • 1
  • 1
  • 3