我正在尝试使用Challonge API向锦标赛中添加一些参与者,请参见https://api.challonge.com/v1/documents/participants/bulk_add。
我最初的尝试是使用Google Apps脚本:
query_url = "https://api.challonge.com/v1/tournaments/" + tourn_id + "/participants/bulk_add.json";
payload = {"api_key" : api_key, "name" : players};
options = {"method" : "POST", "muteHttpExceptions" : true, "contentType": "application/json", "payload" : JSON.stringify(payload)};
response = UrlFetchApp.fetch(query_url, options);
Logger.log("");
Logger.log(response);
这记录了响应“ []”,并且没有参与者被添加到锦标赛中。没有HTTP错误或任何其他类型的错误。我认为这可能与Google Apps脚本代码有关,所以我也尝试了curl的请求:
curl -X POST -H "Content-Type: application/json" --data '{"name":["testname", "testname2"]}' "https://<username>:<api_key>@api.challonge.com/v1/tournaments/<tournament id>/participants/bulk_add.json"
结果是一样的:没有HTTP错误,但是没有将参与者添加到锦标赛中。
有人可以看到这些请求有什么问题吗?请注意,来自Challonge API的其他请求没有问题,例如我可以通过https://api.challonge.com/v1/documents/participants/create添加一个参与者。
答案 0 :(得分:0)
我遇到了类似的问题。这是我用来让它工作的示例主体:
// This is the URL /tournaments/your_tournament_id/participants/bulk_add.json
{
"api_key" : "your API key goes here",
"participants" : [{"name" : "hello w0rld", "misc" : "optional field"},
{"name" : "hello w0rld2", "misc" : "optional field"}]
}