简体   繁体   中英

How to pass bulk participants to Challonge REST API?

I am trying to add a number of participants to a tournament using the Challonge API, see https://api.challonge.com/v1/documents/participants/bulk_add .

My original attempt was using Google apps script:

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); 

This logged a response "[]" and no participants were added to the tournament. There was no HTTP error or any other type of error. I thought that this might be an issue with the Google apps script code, so I also tried a request with 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"

The result is the same: no HTTP error, but the participants aren't added to the tournament.

Can anyone see anything wrong with these requests? Note that there is no problem with other requests from the Challonge API, eg I can add a single participant via https://api.challonge.com/v1/documents/participants/create .

I was running into a similar issue. Here is an example body that I used to get it working:

// 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"}]
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM