This post is an introduction to Prisync API V2.0, aiming to explain the foundations and beyond.
Let’s get directly into it.
The Problem
Let’s assume you are running an e-commerce website, called “The Lovely Store”, The Lovely Store has a custom technology stack, which means you (and your team) developed it internally. (If you are using Magento, we have an app for that –> Prisync Magento App. If you are using Shopify, we have an app for that, too: –> Prisync Shopify App)
The Lovely Store has a bunch of serious competitors and the competition is so hot that in some products, prices change several times within a day. Of course, there are more quiet product groups which see price changes just a few times in a week or less.
There are other concerns to handle, such as:
- Every day, some products go out of stock, some of them get new stock availability in your inventory,
- Stock unavailability happens on competitors’ websites,
- New products arrive in your inventory every month
Intuitive Solution
What you basically want is to find and set the right prices for your products, so that you want to stay in the competition and still be profitable! So easy, right?
Well, if you are selling just 10 products, that’s right. All you need to do is:
- Visit your 5 major competitors’ websites several times a day,
- Collect the price and stock availability information,
- Save them into an Excel file,
- Run your price formulas on the Excel,
- Note the results of the formulas,
- Log in to admin dashboard of The Lovely Store,
- Set new prices
- Wait for your competitors to response and set their prices accordingly,
- Rinse and repeat.
If you have 10 products and 5 major competitors, which makes 50 visits for just one data set of collections. You need to complete this robotic mission at least several times a day. Let’s say you spend 30 seconds on average for each webpage visit, noting the price and stock, checking the result of the formula and setting a new price on your admin dashboard. (30 seconds would be a world record, but anyway, let’s keep this simple.)
Congratulations! You are spending 50 visits x 30 seconds/visit x 4 times which makes more than one and a half hours for just 10 products, again, for just this robotic mission.
More Problems On The Way
Let’s keep this straight, you don’t have just 10 products. An average e-commerce website has 1000 to 5000 SKUs, excluding variants. Let’s say The Lovely Store has 1200 SKUs. Now we have a conundrum: we need 144,000 seconds to check and set all the prices, on the other hand, a day has only 86,400 seconds. Well, even if you don’t sleep, eat or leave the task for a second, you can only check half of your inventory manually.
Smarter Solution
Let’s do what smart people do and automate this boring task. Prisync provides just the right tools for competitor price tracking and dynamic pricing. You can either import your products, track competitors and set your prices using the Prisync web dashboard, or you can use API V2.0. In this post, we’ll go into the tech parts and automate your daily job using the API V2.0.
You can quickly visit Prisync API V2.0 documentation for a quick glance. No worries, even if you don’t like to read the docs, I’ll provide a sweet level of details below.
Prisync API Basics Tutorial
1. Create API Key and API Token
Create a test account on https://prisync.com/register, then get your API Key and API Token via:
I. Click My Account dropdown menu on your dashboard, on the right top corner (see the image below)
II. Click Settings from the dropdown
III. Click API Access Details tab from the opened page
IV. Note your API Key and API Token
You are ready to go now. Let’s proceed.
2. Adding the First Product
Your Prisync Dashboard has no products right now, as can be seen below:
We can now add our first product from an API consuming piece of code. You can call Prisync API V2.0 endpoints using any programming language, such as PHP, Python, Java, Perl or any other programming language.
I quickly implemented a generic method in Python language for making API requests. It takes 3 parameters:
make_request(path, method, payload=None)
path:
Path of the API endpoint. E.g.: /add/product
method:
HTTP method, choose GET or POST according to the endpoint.
payload:
HTTP POST data, required for POST requests.
Note: The code is tested with Python 2.7.3 and Python 3.5. You need just one Python package to run the examples: requests. You can install it via pip:
pip install requests
That’s all. Whole code of make_request method is just 20 lines, shown below:
We’ll use make_request method through all examples in rest of the blogpost.
We’re all set for adding the first product. Let’s prepare the data of our first product. Let’s assume our first product is the new mighty Apply iPhone X:
As a matter of fact, the rest of addition is just calling the make_request method with the payload we prepared.
Result: (200, u'{"id":"2055805","result":true}')
Voilà! We added our first product to our Prisync account. This is how Prisync Dashboard looks now:
Let’s look into the API result, we’ll need that later:
response.status_code: 200, HTTP 200 code, indicating that
the operation was successful.
response.text: A JSON string, including a success message
if the operation is successful. If there happens an error,
this message will clarify the situation. Now addition
is successful, so that it returns the product_id of the
product we added and "result: true" message. Write down
the product_id, we'll use it in next example.
3. Adding my URL and competitor URLs to the product
Now we’ve told Prisync that we are selling an iPhone X. Prisync Engine will start collecting prices and stock availability, right after we add our own URL and competitor URLs. Let’s assume we have 3 major competitors, selling exact same iPhone X configuration. So we need to add 4 URLs (1 for us and 3 for competitors) to the product we’ve added in previous example.
–– My product page URL (which I sell iPhone X at): https://thelovelystore.com/products/8893774-apple-iphonex-64gb-spacegray (Obviously a fake URL)
–– Competitor-1 product page URL: https://www.coolblue.nl/product/793610/apple-iphone-x-64gb-zilver.html
–– Competitor-2 product page URL: https://www.apple.nl/shop/buy-iphone/iphone-x/5,8-inch-display-256gb-zilver
–– Competitor-3 product page URL: https://eurogsm.ro/apple-iphone-x-5-8-4g.html
First, we’ll generate a list of URLs including those:
Then, let’s make a request to /add/url endpoint for each of the URLs.
…and, done. You’ve successfully added your URL and 3 competitor URLs. You’ll see 4 lines of response, each indicating a successful-200 result:
(200, u'{"id":"8273503","result":true}')
(200, u'{"id":"8273504","result":true}')
(200, u'{"id":"8273505","result":true}')
(200, u'{"id":"8273506","result":true}')
Right now, you have a fully operational product on your Prisync Dashboard. Let’s see how it looks:
Since Prisync already gathered some of the URLs you track, it showed the price and stock availability, immediately. For the rest of the URLs, it’ll collect all the required information and start showing the prices/stocks in a few hours.
––
Now you can code a small middleware, connect your database and iterate over all your products; making a /add/product request for each of your products.
Then you can collect your own URLs and your competitor URLs, then you can call /add/url endpoint to complete your Prisync Dashboard.
3. Batch Import Your Products
There is a batch import endpoint in the API V2.0, so that instead of making one API call for each of your products, you can make a batch import to add up to 1000 products at a time.
/add/batch endpoint is very similar to /add/product endpoint, the only thing to change is the payload.
Let’s add 3 products at once:
Then call /add/batch endpoint:
Batch imports are queued for your convenience, so that request returns a progress status immediately, instead of making your request wait until all is done:
(200, u'{"message":"Processing.
(%0)","status":"on_progress","total":"3","processed":0}')
Note: Now you can either wait a bit to let the progress being completed, or you can make a call to /progress/batchImport endpoint to see the percentage completed.
Usually, batch imports are processed very fast, so this time there is no need to make a /progress/batchImport call. Now our Prisync Dashboard looks like this:
We can now return to adding URLs to the product we’ve just added, as we’ve done in example 2.
Prisync API Takeaways
In this introductory blog post, I explained simply how to use Prisync API V2.0. The examples I showed was really the introduction. After a few hours, Prisync will provide you full price and stock availability information and beyond that, you will be able to create custom reports according to your company’s need, dynamically add/edit and delete products, add new competitors, set up a dynamic pricing engine with the rules you specified.
There are other API blog posts showing more examples, so stay in touch!
prisync