0

尝试使用 Gibbon(Ruby 的 MailChimp 包装器)创建标签/段时遇到问题。

我已经成功地将 Gibbon 用于大型生产站点 2 年,但需要从合并字段转移到标记订阅者。

我可以通过 Gibbon 成功地将标签添加到订阅者,但是有超过 85,000 个用户需要转换,我真的不想提出 85,000 个单独的请求。有 200 多个可能的标签,所以我想找到每个可能标签的所有用户,然后将电子邮件地址发布到分段端点......所以 200 个请求,而不是 85,000 个。

问题是,如果列表中已经存在标签(即我创建的测试标签),那么我会得到400 error, Tag already exists,如果标签不存在,我会得到404 Resource Not Found. 无论我是否提供电子邮件地址,这都是一样的static_segment

我希望以下内容在 MailChimp 中创建一个标签:

request = Gibbon::Request.lists(<list_id>)
request.tags.create(body: { name: "testing3", static_segment: [] })

但是,我收到以下错误(如果我使用tagssegments在请求中,这是相同的):

I, [2019-06-06T10:33:59.711436 #88340]  INFO -- request: POST https://us15.api.mailchimp.com/3.0/lists/<list_id>/tags
D, [2019-06-06T10:33:59.711556 #88340] DEBUG -- request: User-Agent: "Faraday v0.15.4"
Authorization: "Basic <key>"
Content-Type: "application/json"
D, [2019-06-06T10:33:59.711605 #88340] DEBUG -- request: {"type":"http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/","title":"Resource Not Found","status":404,"detail":"Invalid path","instance":"<instance_id>"}
I, [2019-06-06T10:33:59.711779 #88340]  INFO -- response: Status 404
D, [2019-06-06T10:33:59.711839 #88340] DEBUG -- response: server: "openresty"
content-type: "application/problem+json; charset=utf-8"
x-request-id: "<instance_id>"
link: "<https://us15.api.mailchimp.com/schema/3.0/ProblemDetailDocument.json>; rel=\"describedBy\""
vary: "Accept-Encoding"
date: "Thu, 06 Jun 2019 09:33:59 GMT"
content-length: "204"
connection: "close"
set-cookie: "_AVESTA_ENVIRONMENT=prod; path=/, _mcid=1.b9640bf1122e4a9b277bb19e3d72caf6; expires=Fri, 05-Jun-2020 09:33:59 GMT; Max-Age=31536000; path=/; domain=.mailchimp.com"

D, [2019-06-06T10:33:59.711878 #88340] DEBUG -- response: {"type":"http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/","title":"Resource Not Found","status":404,"detail":"Invalid path","instance":"<instance_id>"}
Gibbon::MailChimpError: the server responded with status 404 @title="Resource Not Found", @detail="Invalid path", @body={:type=>"http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/", :title=>"Resource Not Found", :status=>404, :detail=>"Invalid path", :instance=>"<instance_id>"}, @raw_body="{\"type\":\"http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/\",\"title\":\"Resource Not Found\",\"status\":404,\"detail\":\"Invalid path\",\"instance\":\"<instance_id>\"}", @status_code=404
from /Users/Paul/.rvm/gems/<gemset>/gems/gibbon-3.2.0/lib/gibbon/api_request.rb:134:in `handle_error'
Caused by Faraday::ResourceNotFound: the server responded with status 404
from /Users/Paul/.rvm/gems/<gemset>/gems/faraday-0.15.4/lib/faraday/response/raise_error.rb:8:in `on_complete'

我正在使用最新版本的Gibbon 3.2.0.

当我在里面Gibbon::APIRequest.post查看正在生成的路径时,我看到以下内容:

 (byebug) base_api_url
 "https://us15.api.mailchimp.com/3.0/"

 # For request.segments
 (byebug) api_url
 "https://us15.api.mailchimp.com/3.0/lists/<list_id>/segments"

 # For request.tags
 (byebug) api_url
 "https://us15.api.mailchimp.com/3.0/lists/<list_id>/tags"

任何帮助将不胜感激,因为我真的不确定我做错了什么。

先感谢您。保罗。:)

4

2 回答 2

2

因此,对于其他可能对此感到困扰的人,Gibbon 文档根本不谈论 Segments,而是做参考标签,我认为这是我的一些困惑所在。

request.tags应该是request.segments

另一个问题是请求不能被重用,所以因为我在循环内执行操作,通过分配request1 = Gibbon::Request.lists(<list_id>)并尝试将其用于第二次迭代,Gibbon 将请求转发到错误的路径并返回 404 错误。

每个请求都需要是它自己的 Gibbon Request 实例Gibbon::Request。因此,以下将起作用:

request = Gibbon::Request
#loop start
request.lists(<list_id>).segments.create(body: { name: "testing", static_segment: [] })
# loop end

希望对其他人有所帮助。

于 2019-06-06T10:22:27.027 回答
1
Gibbon::Request.lists(LIST_ID).segments.create(body: { name: "NAME", static_segment: [] })
于 2019-06-06T10:08:04.580 回答