使用curl将用户订阅到MailChimp列表总是返回“我们遇到了未指定的JSON解析错误”

时间:2017-01-17 23:35:52

标签: curl mailchimp-api-v3.0

我有一个创建批处理文件的应用程序,然后调用

我需要将订阅者添加到MailChimp列表

curl.exe -v --request POST --url "https://us11.api.mailchimp.com/3.0/lists/list_id/members" --user "anystring:api_key" --header "content-type: application/json" --data "{"email_address":"urist.mcvankab+3@freddiesjokes.com", "status":"subscribed"}" --include

我已根据建议更新了请求但仍然出错。是的,看起来双引号是这里的问题。

{"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":""}

Note: Unnecessary use of -X or --request, POST is already inferred.
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 92.123.199.167...
* Connected to us11.api.mailchimp.com (92.123.199.167) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: C:\DevPB\Epos\ca-bundle.crt
  CApath: none
* TLSv1.2 (OUT), TLS header, Certificate Status (22):
} [5 bytes data]
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
} [512 bytes data]
* TLSv1.2 (IN), TLS handshake, Server hello (2):
{ [104 bytes data]
* TLSv1.2 (IN), TLS handshake, Certificate (11):
{ [2662 bytes data]
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
{ [333 bytes data]
* TLSv1.2 (IN), TLS handshake, Server finished (14):
{ [4 bytes data]
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
} [70 bytes data]
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
} [1 bytes data]
* TLSv1.2 (OUT), TLS handshake, Finished (20):
} [16 bytes data]
* TLSv1.2 (IN), TLS change cipher, Client hello (1):
{ [1 bytes data]
* TLSv1.2 (IN), TLS handshake, Finished (20):
{ [16 bytes data]
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN, server accepted to use http/1.1
* Server certificate:
*  subject: C=US; ST=Georgia; L=Atlanta; O=The Rocket Science Group, LLC; OU=IT; CN=*.api.mailchimp.com
*  start date: May  3 00:00:00 2016 GMT
*  expire date: May  3 23:59:59 2017 GMT
*  subjectAltName: host "us11.api.mailchimp.com" matched cert's "*.api.mailchimp.com"
*  issuer: C=US; O=GeoTrust Inc.; CN=GeoTrust SSL CA - G3
*  SSL certificate verify ok.
* Server auth using Basic with user 'anystring'
} [5 bytes data]
> POST /3.0/lists/XXXXXXXX/members HTTP/1.1
> Host: us11.api.mailchimp.com
> Authorization: Basic XXXXXXXXXXXXXXXXXXXXX
> User-Agent: curl/7.50.1
> Accept: */*
> content-type: application/json
> Content-Length: 69
>
} [69 bytes data]
* upload completely sent off: 69 out of 69 bytes
{ [5 bytes data]
< HTTP/1.1 400 Bad Request
< Server: openresty
< Content-Type: application/problem+json; charset=utf-8
< Content-Length: 203
< X-Request-Id: 145d8a92-f4c5-4a83-8e1f-f72cf7850c45
< Link: <https://us11.api.mailchimp.com/schema/3.0/ProblemDetailDocument.json>; rel="describedBy"
< Date: Wed, 18 Jan 2017 13:42:59 GMT
< Connection: close
< Set-Cookie: _AVESTA_ENVIRONMENT=prod; path=/
<
{ [203 bytes data]
100   272  100   203  100    69    419    142 --:--:-- --:--:-- --:--:--   419
* Closing connection 0
} [5 bytes data]
* TLSv1.2 (OUT), TLS alert, Client hello (1):
} [2 bytes data]

C:\DevPB\Epos>

1 个答案:

答案 0 :(得分:1)

可能由于Windows终端不支持单引号而发生。用双引号替换您的数据。例如

--data "{\"email_address\"...}"

同时尝试使用-v切换到调试输出来运行命令。如果输出不起作用,请用输出更新您的问题。