Etsy integration v2 with Symfony

  What is Etsy? Etsy is a e-commerce website focused on handmade, vintage and craft supplies, as of year 2019 Etsy has over 60 million items in its marketplace and the online marketplace connected 2.1 millions sellers with 39.4 million buyers. Pre integration requirements First of all, you will need to register an Etsy account, after this, you can apply to Etsy for an application here, after you do that, you will maybe have to wait a while for Etsy to allow you to have an app. Registering an Etsy application will grant you an API Key that we will use to have access to your store or other peoples store. Once you application has been deemed as ok by Etsy, you application will appear here where you can click on the “see api key details” text which will show you a dropdown of your api key parts which of there are two, the first beeing “keystring” and the other beeing “shared secret”. So now that we have a key we can do some integration stuff, but just before that a fair warning to people that if you wish to have access to other peoples stores, you will have to apply for Etsy’s full access which gives you the opportunity to ask people to link their stores to our application without them needing to give you credentials, you can apply for full access here. Integration
public function connectEtsy(){
$oauth = new \OAuth(consumer_key, shared_secret);

$req_token = $oauth->getRequestToken("https://openapi.etsy.com/v2/oauth/request_token?scope=email_r%20listings_r%20listings_w%20transactions_r%20transactions_w",return_url, "GET");

$customer = $this->getUser()->getCustomer();
$customer->setEtsyOauthSecret($req_token['oauth_token_secret']);

$this->em->flush();

return $this->getResponse($req_token['login_url']);
}
  What we have here is a function on our backend that we will call when our user wishes to connect to our application, when we send our request to Etsy, if our request is ok, we should get a link to send the user to, and that link should be to Etsy’s website where the user essentially agrees to gives us tokens with which we can access editing stuff on their store/account without them giving us any credentials. So first thing that you will have to change from this piece of code are the arguments sent to the Oauth function, here is where the registration of the application in previous steps comes in, the keystring is the consumer key and the shared secret is the consumer secret. The next part that needs to be addressed is the first parameter in the getRequestToken, here you can see in the url that there are scopes, essentially what these do is they give you access to different parts of the users account, so for example if you send listings_w and listings_r, that means that you can read and write listings to and from the users account, I would suggest taking a bit of time to read and consider which scopes you will need, because the user does see this when he is accepting to give you the tokens on the Etsy website. The third part which needs to be changed is the return_url, here you should add an url from your website where you wish Etsy to return your user after they have accepted giving you access to their account. Once the user has accepted to give you access and they are returned to the return_url that you put as an argument, you will have in that url additional parameters that etsy sent you, those parameters are oauth_token and oauth_verifier, now with these we are one step behind getting access to the users account.
$oauth_token = $this->getParameter('oauth_token');
$oauth_verifier = $this->getParameter('oauth_verifier');

$customer = $this->getUser()->getCustomer();

$request_token_secret = $customer->getEtsyOauthSecret();

// get the verifier from the url

$oauth = new \OAuth(consumer_key, consumer_secret);

// set the temporary credentials and secret
$oauth->setToken($oauth_token, $request_token_secret);

try {
// set the verifier and request Etsy's token credentials url
$acc_token = $oauth->getAccessToken("https://openapi.etsy.com/v2/oauth/access_token", null, $oauth_verifier, "GET");
} catch (\OAuthException $e) {
error_log($e->getMessage());
}

$customer->setEtsyOauthAccessToken($acc_token['oauth_token']);
$customer->setEtsyOauthAccessTokenSecret($acc_token['oauth_token_secret']);
  Now with the temporary credentials we got from the previous code snippet and which we saved to our database, here we use them to get permanent credentials from Etsy for our customer, that is the access token and the access token secret, with these two and the adequate scopes we requested, we can do almost anything with the users account and store.

You may also like

June 17, 2024

Quests in Code: Is Game Development the Ultimate IT Career Move for You?

Game development has captured the imagination of IT students and professionals alike. The video game industry, now a multi-billion dollar behemoth, is booming like never before.  But why is it suddenly the talk of the tech town? Is it the allure of cutting-edge tech or the tantalizing promise of dream jobs? Get ready to find […]

June 20, 2024

Mastering Client-Oriented Roles: Expert Advice for Junior Developers

Ever wondered what makes the magic happen behind the scenes in global software companies? Spoiler alert: it’s the client-oriented roles! These are the glue that keeps everything together, ensuring clients’ needs are met and expectations exceeded.  This blog post will share concrete, experience-based insights to help new employees thrive in these crucial positions. Whether you […]

June 10, 2024

Staying Motivated in the IT: Student's Guide

Securing a job in the IT field can feel like trying to crack the toughest code, especially without prior experience. That’s where internships and practical experience come into play, acting as the perfect stepping stones for your career path.  At Lilly021, we’ve noticed some young tech enthusiasts feeling a bit blue, likely due to market […]