PHP code example of rhysnhall / etsy-php-sdk

1. Go to this page and download the library: Download rhysnhall/etsy-php-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rhysnhall / etsy-php-sdk example snippets


composer 

use Etsy\Etsy;

$etsy = new Etsy(
  $client_id,
  $access_token
);

// Do the Etsy things.

$client = new Etsy\OAuth\Client($client_id);

$url = $client->getAuthorizationUrl(
  $redirect_uri,
  $scopes,
  $code_challenge,
  $nonce
);

$scopes = ["listings_d", "listings_r", "listings_w", "profile_r"];

$scopes = \Etsy\Utils\PermissionScopes::ALL_SCOPES;

[$verifier, $code_challenge] = $client->generateChallengeCode();

$nonce = $client->createNonce();

[$access_token, $refresh_token] = $client->requestAccessToken(
  $redirect_uri,
  $code,
  $verifier
);

[$access_token, $refresh_token] = $client->refreshAccessToken($refresh_token);

[$access_token, $refresh_token] = $client->exchangeLegacyToken($legacy_token);

use Etsy\Etsy;
use Etsy\Resources\User;

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

// Get the authenticated user.
$user = User::me();

// Get the users shop.
$shop = $user->shop();

// Get a Listing Resource
$listing = \Etsy\Resources\Listing::get($shopId);

$listingTitle = $listing->title;

$shop = $listing->shop;

$json = $listing->toJson();

$array = $listing->toArray();

$reviews = Review::all();

$firstReview = $reviews->data[0];

$firstReview = $reviews->first();

$count = $reviews->count();

$reviews->append(['shop_id' => $shopId]);

// Get 100 results using pagination.
foreach($reviews->paginate(200) as $review) {
  ...
}

$jsonArray = $reviews->toJson();

$response = Etsy::$client->get(
  "/application/listings/active",
  [
    "limit" => 25
  ]
);

$listings = Etsy::getResource(
  $response,
  'Listing'
);