Da11aS
Da11aS

Reputation: 465

cURL PUT Request Not Working with PHP

I am working with the Challonge.com API found here: https://api.challonge.com/v1

I am trying to get the match UPDATE feature to work - https://api.challonge.com/v1/documents/matches/update

I have had success updating my tournament with the same code, but for some reason the following code is not updating the variables. Instead the response I get is the same as before the script is ran. Any Ideas?

       // Update Match on Challonge
        $params = array(
            "api_key" => "my api key goes here",
            "winner_id" => "50287554",
            "scores_csv" => "2-5,1-3"               
        );
        $url = "https://api.challonge.com/v1/tournaments/efps_59/matches/78842711.json"; 
        $data_json = json_encode($params);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Content-Length: ' . strlen($data_json)));
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
        curl_setopt($ch, CURLOPT_POSTFIELDS,$data_json);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $response  = curl_exec($ch);
        curl_close($ch);
        echo $response;

Upvotes: 0

Views: 599

Answers (1)

Kep
Kep

Reputation: 5857

Your documentation states that the parameters for winner_id and scores_csvhave to be an array of match:

   // Update Match on Challonge
    $params = array(
        "api_key" => "my api key goes here",
        "match" => array(
            "winner_id" => "50287554",
            "scores_csv" => "2-5,1-3"
        )
    );

Upvotes: 2

Related Questions