Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ignezio's avatar

Guzzel returning 404 error

hello, I am trying to use the guzzle package to post to challonge API using the following code but Laravel is returning the following error any help is greatly appreciated.

Client error: `POST https://username:***@api.challonge.com/v1/` resulted in a `404 Not Found

controller

    public function index()
    {
        $client = new \GuzzleHttp\Client();
        $url = "https://user:[email protected]/v1/";
        $params = array(
            "tournament[name]" => "My Tourney",
            "tournament[tournament_type]" => "single elimination",
            "tournament[url]" => "my_toruney",
            "tournament[description]" => "Challonge is <strong>AWESOME</strong>"
            );
        $request = $client->post($url,  ['tournaments'=>$params]);
        $response = $request->send();
    }

web.php

Route::resource('test', 'TeamController');
0 likes
6 replies
ignezio's avatar

@Cronix ive appended test to the end of the url but it seems to have not changed

ignezio's avatar

Thanks @Cronix, unfortunately when updating the URL and the controller to accommodate for the following error I am presented with a 406 error. When referencing the API this error means. I was wondering if you could take a look at my controller below

406 - Requested format is not supported - request JSON or XML only

controller

        $client = new \GuzzleHttp\Client();
        $url = "https://UserName:[email protected]/v1/tournaments.{json|xml}";
        $params = array(
            "tournament[name]" => "My Tourney",
            "tournament[tournament_type]" => "single elimination",
            "tournament[url]" => "my_toruney",
            "tournament[description]" => "Challonge is <strong>AWESOME</strong>"
            );
        $data = json_encode($params);
        $request = $client->post($url,array(
                      'content-type' => 'application/json'));
        $request->setBody($data); #set body!
        $response = $request->send();
Cronix's avatar
Cronix
Best Answer
Level 67

Yes, look at the url I wrote in my first post.

$url = "https://UserName:[email protected]/v1/tournaments.json";

When the docs show {json|xml} here

POST https://api.challonge.com/v1/tournaments.{json|xml} 

it means it should be .json OR .xml, not the whole thing literally

ignezio's avatar

@Cronix hey man sorry to keep asking you but could you look at this final error for me.

`422 Unprocessable Entity` response: {"errors":["Tournament parameters are required"]}
``

I know that it means the format is incorrect but whenever I return it to the view it seems to be in the same format as in the API docs.

    $params = array(
        "tournament[name]" => "My Tourney",
        "tournament[tournament_type]" => "single elimination",
        "tournament[url]" => "my_toruney",
        "description" => "Challonge is <strong>AWESOME</strong>"
        );
        $request = $client->post($url,array(
                  'content-type' => 'application/json',
                  'tournament' => json_encode($params)
          ),array());
  $response = $request->send();


Please or to participate in this conversation.