rhysnhall / etsy-php-sdk

PHP SDK for Etsy API v3.
MIT License
47 stars 36 forks source link

OpenApi Requests that only require API Key #17

Closed cdburgess closed 2 years ago

cdburgess commented 2 years ago

There appears to be some redundancy in the instantiation of Etsy. For example, when creating an instance of Etsy ($Etsy = new Etsy($client_id, $api_key)) for a GET request that only requires the $api_key (ie. https://developers.etsy.com/documentation/reference#operation/getListing), I am required to send the $api_key twice

$Etsy = new Etsy($apiKey, $apiKey);

It appears the $client_id and $api_key are interchangeable. Is this how it should be?

rhysnhall commented 2 years ago

The first key is the API key associated with your app. This is required for all requests and gets set in the x-api-key header. The second key is an oauth2 token. Any request that requires a scope also requires this token as an authorization header. There are a handful of requests where no scope is required, but for convenience, the Etsy class requires one.

This is redundant in a way, yes. The SDK was based on the Etsy API v2 and only updated for v3. Etsy have since updated a handful of the routes and added a lot of new ones that are not present here. I have a complete overhaul in the works that addresses many of the redundancies, for example, having to go through the User or Shop classes to get public data like this example.

An interim solution is to step around the Etsy class:

$client = new Client($api_key); // The key associated with your App.
$response = $client->get("/application/listings/{$listing_id}");
$listing = Etsy::getResource($response, 'Listing'); // Static method does not require the Etsy class to be setup
cdburgess commented 2 years ago

Awesome! I look forward to the updates.