我想使用 httparty 对内部通信 API 进行 POST 调用,以便按照特定条件搜索对话。 我首先在邮递员中进行了测试,它工作正常(见以下链接上的屏幕截图( 邮递员内部的 API 调用 但是,当我想使用 httparty gem 在 ruby 中进行此 API 调用时,它不起作用。 我使用了以下代码:
headers: {
"Content-Type": "application/json",
Authorization: "Bearer {{value of the token}}",
Accept: "application/json",
},
query: {
"field": "updated_at",
"operator": ">",
"value": 1592248820
}
}
results = HTTParty.post('https://api.intercom.io/conversations/search', options)
它返回以下错误:
{"type":"error.list","request_id":"0001t1gne3j7pscoq2n0","errors":[{"code":"invalid_query","message":"Query body must contain a query hash"}]}
这真的很奇怪,因为我使用完全相同的语法测试了对内部通信 API 的另一个 POST 调用的语法,并且它工作正常。见下文:
headers: {
"Content-Type": "application/json",
Authorization: "Bearer {{value of the token}}",
Accept: "application/json",
},
query: {
"email": "wash@serenity.io",
"name": "Hoban Washburn",
"role": "user"
}
}
results = HTTParty.post('https://api.intercom.io/contacts', options)
我的第一个想法是查询必须在调用的正文中,所以我建议尝试...
headers: {
"Content-Type": "application/json",
Authorization: "Bearer {{value of the token}}",
Accept: "application/json",
},
body: {
query: {
"field": "updated_at",
"operator": ">",
"value": 1592248820
}
}
}
这也与您的邮递员电话更匹配。