V3 oAuth 2 Access Token Error

464 views
Skip to first unread message

Татьяна Мирошниченко

unread,
Mar 3, 2022, 3:41:34 PM3/3/22
to Etsy API
Are there people who got success with oAuth 2 authentification flow using v3 API?

I was able to get an  Authorization Code, but have a problrm with  getting an Access Token.

I make a POST request using the below  url but constantly get HTTP 404 {"error": "Resource not found"} 

$url = "https://api.etsy.com/v3/public/oauth/token?grant_type=authorization_code&client_id={MY_ Etsy_App_ API_ Key }&redirect_uri=https:// {MY_ REDIRECT_URL }  .php&code=".$code."&code_verifier=".$code_verifier;


Is anyone able to provide an advice here?

Thanks

Nathan Crawford

unread,
Mar 7, 2022, 8:24:56 AM3/7/22
to Etsy API
This is the code I use to make that post request using curl in php:

    function post_helper($url, $data)
    {
        //open connection
        $ch = curl_init();

        //set the url, number of POST vars, POST data
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        //set encoding
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));

        //So that curl_exec returns the contents of the cURL; rather than echoing it
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

        //execute post
        $retval = curl_exec($ch);

        return json_decode($retval);
    }

        $data = "grant_type=authorization_code" .
            "&client_id=${api_key}" .
            "&redirect_uri=${redirect_url}" .
            "&code=${code}" .
            "&code_verifier=${code_verifier}";

        $response = post_helper('https://api.etsy.com/v3/public/oauth/token', $data);

if $response->error is set, then something went wrong and it will usually provide a descriptive error message. If the request is successful, you can get the access token from $response->access_token.

Татьяна Мирошниченко

unread,
Mar 15, 2022, 3:51:45 PM3/15/22
to Etsy API
Thank you, it helped!

понедельник, 7 марта 2022 г. в 14:24:56 UTC+1, nat...@milstrata.com:
Reply all
Reply to author
Forward
0 new messages