PHP code example of hmalicha / etsy-php

1. Go to this page and download the library: Download hmalicha/etsy-php 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/ */

    

hmalicha / etsy-php example snippets


  # it will request /categories/tag1/subtag1/subsubtag1
  $api->getSubSubCategory(array(
          'params' => array(
                         'tag' => 'tag1',
                         'subtag' => 'subtag1',
                         'subsubtag' => 'subsubtag1'
           )));

  # it will request /shipping/templates sending the "data" array as the post data
  $api->createShippingTemplate(array(
    						'data' => array(
   							    "title" => "First API Template",
   							    "origin_country_id" => 209,
   							    "destination_country_id" => 209,
   							    "primary_cost" => 10.0,
   							    "secondary_cost" => 10.0
           )));


 return array (
  'consumer_key' => 'df7df6s5fdsf9sdh8gf9jhg98',
  'consumer_secret' => 'sdgd6sd4d',
  'token_secret' => 'a1234567890qwertyu',
  'token' => '3j3j3h33h3g5',
  'access_token' => '8asd8as8gag5sdg4fhg4fjfgj',
  'access_token_secret' => 'f8dgdf6gd5f4s',
);


 =  = new Etsy\EtsyClient($auth['consumer_key'], $auth['consumer_secret']);
$client->authorize($auth['access_token'], $auth['access_token_secret']);

$api = new Etsy\EtsyApi($client);

print_r($api->getUser(array('params' => array('user_id' => '__SELF__'))));

print_r($api->createShippingTemplate(array(
 						'data' => array(
							    "title" => "First API Template",
							    "origin_country_id" => 209,
							    "destination_country_id" => 209,
							    "primary_cost" => 10.0,
							    "secondary_cost" => 10.0
							))));

# Upload local files: the item value must be an array with the first value as a string starting with "@":
$listing_image = array(
		'params' => array(
			'listing_id' => '152326352'
		),
		'data' => array(
			'image' => array('@/path/to/file.jpg;type=image/jpeg')
));
print_r($api->uploadListingImage($listing_image));


    $args = array(
            'params' => array(
                'listing_id' => 654321
            ),
            // A list of associations
            'associations' => array(
                // Could be a simple association, sending something like: ?ive:1:0/DestinationCountry(name,slug)
                'ShippingInfo' => array(
                    'scope' => 'active',
                    'limit' => 1,
                    'offset' => 0,
                    'select' => array('currency_code', 'primary_cost'),
                    // The only issue here is that sub-associations couldn't be more than one, I guess.
                    'associations' => array(
                        'DestinationCountry' => array(
                            'select' => array('name', 'slug')
                        )
                    )
                )
            )
        );
   $result = $this->api->getListing($args);

    $args = array(
        'params' => array(
            'listing_id' => 654321
        ),
        'data' => array(
          'variations' => array(
            'json' => json_encode(
                array(
                    array(
                        'property_id' => 200,
                        'value' => "Black"
                    ),
                    array(
                        'property_id' => 200,
                        'value' => "White"
                    )
                )
            )
        )
      )
    );

    $result = $this->api->createListingVariations($args);
json
{
  "kiabt/etsy-php": ">=0.10"
  }
}
bash
export ETSY_CONSUMER_KEY=qwertyuiop123456dfghj
export ETSY_CONSUMER_SECRET=qwertyuiop12

php scripts/auth-setup.php /path/to/my-oauth-config-destination.php