skip to Main Content

I am using Laravel 8 and the Http Client library. Here is my code:

    public function mintNewApplicationAccessToken()
    {
        $response = Http::withHeaders([
            'Accept' => 'application/json',
            'Content-Type' => 'application/x-www-form-urlencoded',
            'Authorization' => 'Basic ' . base64_encode(config('ebay.ebay_client_id_sandbox') . ":" . config('ebay.ebay_client_secret_sandbox')),
        ])->post(config('ebay.ebay_token_request_endpoint_url_sandbox'), [
            'grant_type' => 'client_credentials',
            'scope' => urlencode(config('ebay.ebay_client_credentials_scopes_sandbox')),
        ]);

        dd($response->json());
    }

I have double checked my client_id and client secret, I am using the Ebay sandbox at the moment, have checked the sandbox url is correct, I can’t figure out what is wrong with my request? I get a 400 error back saying unsupported_grant_type and the error description says grant type in request is not supported by the authorization server. I have checked my scopes and everything seems in order?

2

Answers


  1. Chosen as BEST ANSWER

    I finally figured it out. As per the documentation on the Laravel website, I changed the code from:

        public function mintNewApplicationAccessToken()
        {
            $response = Http::withHeaders([
                'Accept' => 'application/json',
                'Content-Type' => 'application/x-www-form-urlencoded',
                'Authorization' => 'Basic ' . base64_encode(config('ebay.ebay_client_id_sandbox') . ":" . config('ebay.ebay_client_secret_sandbox')),
            ])->post(config('ebay.ebay_token_request_endpoint_url_sandbox'), [
                'grant_type' => 'client_credentials',
                'scope' => urlencode(config('ebay.ebay_client_credentials_scopes_sandbox')),
            ]);
    
            dd($response->json());
        }
    

    To:

            $auth = base64_encode(config('ebay.ebay_client_id_sandbox') . ':' . config('ebay.ebay_client_secret_sandbox'));
    
            $response = Http::asForm()->withOptions([
                'debug' => true,
            ])->withHeaders([
                'Authorization' => 'Basic ' . $auth,
            ])->post(config('ebay.ebay_token_request_endpoint_url_sandbox'), [
                'grant_type' => 'client_credentials',
            'scope' => config('ebay.ebay_client_credentials_scopes_sandbox'),
            ]);
    
            dd($response->json());
    

    So. I added asForm to the code rather than the Content-Type line, and removed the url encode from the scopes.

    What surprised me most was when I removed the url encode method from the scopes it started working? Very strange.


  2. i have also same this problem and solution is that your account is not veriyfied or still waiting for aproval kindly contact support.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search