Tryk på enter for at se resultater eller esc for at annullere.

En ydmyg Introduktion til Prisync API V2.0

Dette indlæg er en introduktion til Prisync API V2.0, med henblik på at forklare grunden og ud.

Lad os komme direkte ind i det.

The Problem

Let’s assume you are running an ecommerce website, kaldet som “Dejlig butik”, Dejlig butik har en brugerdefineret teknologi stack, hvilket betyder, at du (og dit team) udviklet det internt. (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, også: –> 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. Selvfølgelig, 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, som:

  • Hver dag, some products goes out of stock, some of them gets new stock availability in your inventory,
  • Stock unavailability happens on competitors’ hjemmesider,
  • New products arrives 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, højre?

Godt, if you are selling bare 10 produkter, that’s right. Alt du skal gøre er at:

  • 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.

Hvis du har 10 produkter og 5 major konkurrenter, which makes 50 Besøg for just one data set of collection. You need to complete this robotic mission at least several times a day. Let’s say you spend 30 second 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.)

Tillykke! You are spending 50 visits x 30 seconds/visit x 4 times which makes more than one and a half hour for just 10 produkter, igen, for just this robotic mission.

More Problems On The Way

Let’s keep this straight, you don’t have just 10 produkter. En average e-commerce website has 1000 til 5000 SKUs, excluding variants [Quora Answer]. Let’s say The Lovely Store have 1200 SKUs. Now we have a conundrum: we need 144,000 sekunder to check and set all the prices, På den anden side, a day has only 86,400 sekunder. Godt, 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 right tools for competitor price tracking and dynamic pricing. You can either import your products, track competitors and set your prices using Prisync web dashboard, or you can use API V2.0. I dette indlæg, 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. Ingen bekymringer, even if you don’t like to read the docs, I’ll provide a sweet level of details below.

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:

Jeg. 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

Prisync 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:

Empty Prisync Dashboard - API Tutorial

We can now add our first product from a 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.

Bemærk: The code is tested with Python 2.7.3 og 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:

Faktisk, 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:

Prisync Dashboard With Single Product - API Tutorial

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

Nu we’ve told Prisync that we are selling an iPhone X. Prisync Engine will start collection of prices and stock availability, right after we add our own URL og competitor URLs. Let’s assume we have 3 major konkurrenter, selling exact same iPhone X configuration. So we need to add 4 Webadresser (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

Første, we’ll generate a list of URLs including those:

Derefter, let’s make a request to /add/url endpoint for each of the URLs.

…og, 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:

Prisync Dashboard with Single Product and 4 Webadresser - API Tutorial

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}')

Bemærk: 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.

Normalt, 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:

Prisync Dashboard with 4 Produkter - API Tutorial

We can now return to adding URLs to the product we’ve just added, as we’ve done in example 2.

Konklusion

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!