BigCommerce API authentication
Background:
Recently I started using BigCommerce. I found very few resources about BigCommerce API authentication so here I am writing step by step process for that. I am using API V3 of BigCommerce.
Step 1: Create Account at BigCommerce
refer BigCommerce site and create account using your email address. BigCommerce will refer you as technical parter.
Step 2: Create an App
You need to create application at BigCommerce DevTool Site. You should be careful while filling point no 4, Technical Details. Keep following in your mind;
- Auth Callback URL should be secure i.e. HTTPS
- You should able to access server log of that URL. BigCommerce will send you temporarry code to that URL. You can get it by server log.
Step 3: Install your App
Now, go to your store adimn page. This is the same page you have landed on in step 1 after signup. Go to Apps > My Apps > My Draft App from left side navigator. Find your application there which you have created in above step. Now, You will get ‘Learn More’ link by hovering mouse over your app. Click on it. You will get install button, click on it. Then, you will be asked to confirm your installation, confirm it.
Step 4: Get Access Token
You will get temporary code via your Auth callback URL which you have provided in step 2. You can get useful data from your server log. It includes temporary code, scopes and store hash as a context, may look like this;
I am using my sample rails application and ngrok to receive call back from BigCommerce. Copy temporary data and paste it somewhere.
Now, use any tool that can send post request to BigCommerce. I am using Postman for that. Generate following URL using data from server log.
This URL includes following parameters:
- client_id : The Client ID for your app, obtained during registration.
- client_secret : The Client Secret for your app, obtained during registration.
- code : Temporary access code received in the GET request discussed above.
- scope : List of OAuth scopes received in the GET request discussed above.
- grant_type : Always use the following: authorization_code.
- redirect_uri : Must be identical to your registered Auth Callback URI.
- context : The store hash received in the GET request, in the format: stores/{_store_hash_}
Now make POST request to above URL. You will receive permanent access token in response. It may look like,
Aditionaly you will need client id and client secret for some api authentications. To get that go to https://devtools.bigcommerce.com/my/apps and find your app. You will find view client id link. By clicking on that you will have pop up which will have client id and client secret.
Step 5 : Access APIs
Now you are ready to access BigCommerce APIs. We will access product API as demo. For that send GET
request to https://api.bigcommerce.com/stores/nlxse1w1bi/v3/catalog/products?include=images,variants
with following details as a header.
- Accept : application/json
- Authorization : Basic
- Content-Type : application/json
- X-Auth-Client : This will be your client id, obtained during registration.
- X-Auth-Token : Your permanent access token which you obtained in step 4.
Here I am passing ?include=images,variants as an additional parameters to get images and variants information with this API. For more info please refer BigCommerce V3 API Documentation
As a response you will get whole product information from BigCommerce
If you have queries then I will happy to help you out. Please reach me out at mayurt20@gmail.com