Inventory API Production

Using our developer’s site as a point of entry, our Inventory API allows Ve clients to upload their entire collection of products to our database. This gives our clients full reign over which products can be pulled into product feeds and recommended products within VePanel. The API can be called at any time giving clients the flexibility to add, update, promote and blacklist products from the database at any point.


About the Inventory API

Upon logging into the VeLabs site clients will be able to access the end point, giving them the ability to send products to the Inventory API, at which point the product feeds must be uploaded. The associated customer identification and journey code will then be called internally, allowing the Inventory API with the correct parameters and feeds to be selected.

Ve’s Inventory API can be called at any time giving clients the flexibility to add, update, delete, promote and blacklist products from the database at any point.


The Customer Tier

The Customer Tier includes the following limits:

  • Working against our production DBs.
  • Request size limits: 0.5kb (double than the average request).
  • Requests per minute: unlimited.
  • Timeout limit: 400ms (based on usual peaks, even though the average is 172ms of server response time).


Add Product

Inserting products

Products sent to the API that are not registered in the Inventory databases will be considered new products and will be processed accordingly.

The product URL is the key used to identify each product uniquely.


Updating products

Whenever an existing product is uploaded to the Inventory it will be used to update the information stored with the new product information received.


Promoting products

To promote a product the client will need to fill the "isPromoted" field with the value of "true". To un-promote a product the client will need to fill the "isPromoted" field with the value of "false" or null. Promoted products are to be prioritised in the recommendations algorithm.


Blacklisting products

To blacklist products the client will need to fill the "isBlacklisted" field with the value of "true". To un-blacklist products the client will need to fill the "isBlacklisted" field with the value of "false" or null. Blacklisted products are to be excluded in the recommendations algorithm.


Request requirements

There are some parameters that should be passed to this method which will return a JSON object with properties as described below. The request requirements are the following:

  • The request must be a HTTPS POST request
  • The request must include an Accept header with the value of application/json
  • The request must include an Content-Type header with the value of application/json
  • The request must include an Ocp-Apim-Subscription-Key header key with the value of <API Key obtained at step 2 from your profile>
  • The body of the request must contain the following parameters (the required ones will have an * next to them, the others are optional)

Request parameters:

  • domain: customer domain
  • products*: a list of products
  • attributes: custom attributes
  • avgRating: average rating of the product
  • bigImageUrl: product's big image valid URL, protocol required
  • brandName: product's brand name
  • categories*: list of product categories and its paths
  • code: SKU or ISBN or EAN
  • cultureCode: valid culture code according to http://www.iso.org/iso/language_codes
  • currencyCode*: valid currency code according to http://www.iso.org/iso/home/standards/currency_codes.htm
  • description*: product's description
  • discountAmount: discount amount for the given product
  • discountType: discount type of the given product
  • externalProductId: customer's product identifier
  • isBlacklisted*: indicates if the product is blacklisted
  • isFreeDelivery: indicates if the product has free delivery
  • isInStock: indicates if the product is available
  • isOnSale: indicates if the product is on sale
  • isPromoted*: indicates if the product is promoted
  • name*: product's name
  • oldPriceValue: indicates the old price value
  • oldPriceWithCurrencySymbol: indicates the old price value without currency
  • priceValue*: product's price without currency
  • ratingCount: product's rating
  • reviewCount: product's number of reviews
  • shippingAmount: product's shipping cost
  • shippingCurrencyCode: valid currency code according to http://www.iso.org/iso/home/standards/currency_codes.htm
  • shippingInfo: shipping information
  • smallImageUrl*: product's small image valid URL, protocol required.
  • stockQuantity: number of available product units
  • url*: product's page URL, protocol required

Try it

Request URL

Request headers

(optional)
string
Media type of the body sent to the API.
string
Subscription key which provides access to this API. Found in your Profile.

Request body

Example of use

Example of feed with one product to be sent to the API:

{
"domain": "http://test.com",
"products":
[
  {
    "attributes": {
    	"size":"20"
    },
    "avgRating": 0,
    "bigImageUrl": "http://www.test.com",
    "brandName": "string",
    "categories": {
    	"clothes":"/clothes"
    },
    "code": "10",
    "cultureCode": "en",
    "currencyCode": "GBP",
    "description": "string",
    "discountAmount": "10",
    "discountType": "1",
    "externalProductId": "58",
    "isBlacklisted": false,
    "isFreeDelivery": true,
    "isInStock": false,
    "isOnSale": false,
    "isPromoted": false,
    "name": "icatest",
    "oldPriceValue": 5,
    "oldPriceWithCurrencySymbol": "5 GBP",
    "priceValue": 500,
    "ratingCount": 10,
    "reviewCount": 10,
    "shippingAmount": 10,
    "shippingCurrencyCode": "GBP",
    "shippingInfo": "string",
    "smallImageUrl": "http://test.com",
    "stockQuantity": 10,
    "url": "http://test.com"
  }
]
}

Code samples

@ECHO OFF

curl -v -X POST "https://api.veinteractive.com/InventoryApi/add"
-H "Content-Type: application/json"
-H "Ocp-Apim-Subscription-Key: {subscription key}"

--data-ascii "{body}" 
using System;
using System.Net.Http.Headers;
using System.Text;
using System.Net.Http;
using System.Web;

namespace CSHttpClientSample
{
    static class Program
    {
        static void Main()
        {
            MakeRequest();
            Console.WriteLine("Hit ENTER to exit...");
            Console.ReadLine();
        }
        
        static async void MakeRequest()
        {
            var client = new HttpClient();
            var queryString = HttpUtility.ParseQueryString(string.Empty);

            // Request headers
            client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "{subscription key}");

            var uri = "https://api.veinteractive.com/InventoryApi/add?" + queryString;

            HttpResponseMessage response;

            // Request body
            byte[] byteData = Encoding.UTF8.GetBytes("{body}");

            using (var content = new ByteArrayContent(byteData))
            {
               content.Headers.ContentType = new MediaTypeHeaderValue("< your content type, i.e. application/json >");
               response = await client.PostAsync(uri, content);
            }

        }
    }
}	
// // This sample uses the Apache HTTP client from HTTP Components (http://hc.apache.org/httpcomponents-client-ga/)
import java.net.URI;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

public class JavaSample 
{
    public static void main(String[] args) 
    {
        HttpClient httpclient = HttpClients.createDefault();

        try
        {
            URIBuilder builder = new URIBuilder("https://api.veinteractive.com/InventoryApi/add");


            URI uri = builder.build();
            HttpPost request = new HttpPost(uri);
            request.setHeader("Content-Type", "application/json");
            request.setHeader("Ocp-Apim-Subscription-Key", "{subscription key}");


            // Request body
            StringEntity reqEntity = new StringEntity("{body}");
            request.setEntity(reqEntity);

            HttpResponse response = httpclient.execute(request);
            HttpEntity entity = response.getEntity();

            if (entity != null) 
            {
                System.out.println(EntityUtils.toString(entity));
            }
        }
        catch (Exception e)
        {
            System.out.println(e.getMessage());
        }
    }
}

<!DOCTYPE html>
<html>
<head>
    <title>JSSample</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
</head>
<body>

<script type="text/javascript">
    $(function() {
        var params = {
            // Request parameters
        };
      
        $.ajax({
            url: "https://api.veinteractive.com/InventoryApi/add?" + $.param(params),
            beforeSend: function(xhrObj){
                // Request headers
                xhrObj.setRequestHeader("Content-Type","application/json");
                xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key","{subscription key}");
            },
            type: "POST",
            // Request body
            data: "{body}",
        })
        .done(function(data) {
            alert("success");
        })
        .fail(function() {
            alert("error");
        });
    });
</script>
</body>
</html>
#import <Foundation/Foundation.h>

int main(int argc, const char * argv[])
{
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    
    NSString* path = @"https://api.veinteractive.com/InventoryApi/add";
    NSArray* array = @[
                         // Request parameters
                         @"entities=true",
                      ];
    
    NSString* string = [array componentsJoinedByString:@"&"];
    path = [path stringByAppendingFormat:@"?%@", string];

    NSLog(@"%@", path);

    NSMutableURLRequest* _request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:path]];
    [_request setHTTPMethod:@"POST"];
    // Request headers
    [_request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    [_request setValue:@"{subscription key}" forHTTPHeaderField:@"Ocp-Apim-Subscription-Key"];
    // Request body
    [_request setHTTPBody:[@"{body}" dataUsingEncoding:NSUTF8StringEncoding]];
    
    NSURLResponse *response = nil;
    NSError *error = nil;
    NSData* _connectionData = [NSURLConnection sendSynchronousRequest:_request returningResponse:&response error:&error];

    if (nil != error)
    {
        NSLog(@"Error: %@", error);
    }
    else
    {
        NSError* error = nil;
        NSMutableDictionary* json = nil;
        NSString* dataString = [[NSString alloc] initWithData:_connectionData encoding:NSUTF8StringEncoding];
        NSLog(@"%@", dataString);
        
        if (nil != _connectionData)
        {
            json = [NSJSONSerialization JSONObjectWithData:_connectionData options:NSJSONReadingMutableContainers error:&error];
        }
        
        if (error || !json)
        {
            NSLog(@"Could not parse loaded json with error:%@", error);
        }
        
        NSLog(@"%@", json);
        _connectionData = nil;
    }
    
    [pool drain];

    return 0;
}
<?php
// This sample uses the Apache HTTP client from HTTP Components (http://hc.apache.org/httpcomponents-client-ga/)
require_once 'HTTP/Request2.php';

$request = new Http_Request2('https://api.veinteractive.com/InventoryApi/add');
$url = $request->getUrl();

$headers = array(
    // Request headers
    'Content-Type' => 'application/json',
    'Ocp-Apim-Subscription-Key' => '{subscription key}',
);

$request->setHeader($headers);

$parameters = array(
    // Request parameters
);

$url->setQueryVariables($parameters);

$request->setMethod(HTTP_Request2::METHOD_POST);

// Request body
$request->setBody("{body}");

try
{
    $response = $request->send();
    echo $response->getBody();
}
catch (HttpException $ex)
{
    echo $ex;
}

?>
########### Python 2.7 #############
import httplib, urllib, base64

headers = {
    # Request headers
    'Content-Type': 'application/json',
    'Ocp-Apim-Subscription-Key': '{subscription key}',
}

params = urllib.urlencode({
})

try:
    conn = httplib.HTTPSConnection('api.veinteractive.com')
    conn.request("POST", "/InventoryApi/add?%s" % params, "{body}", headers)
    response = conn.getresponse()
    data = response.read()
    print(data)
    conn.close()
except Exception as e:
    print("[Errno {0}] {1}".format(e.errno, e.strerror))

####################################

########### Python 3.2 #############
import http.client, urllib.request, urllib.parse, urllib.error, base64

headers = {
    # Request headers
    'Content-Type': 'application/json',
    'Ocp-Apim-Subscription-Key': '{subscription key}',
}

params = urllib.parse.urlencode({
})

try:
    conn = http.client.HTTPSConnection('api.veinteractive.com')
    conn.request("POST", "/InventoryApi/add?%s" % params, "{body}", headers)
    response = conn.getresponse()
    data = response.read()
    print(data)
    conn.close()
except Exception as e:
    print("[Errno {0}] {1}".format(e.errno, e.strerror))

####################################
require 'net/http'

uri = URI('https://api.veinteractive.com/InventoryApi/add')

request = Net::HTTP::Post.new(uri.request_uri)
# Request headers
request['Content-Type'] = 'application/json'
# Request headers
request['Ocp-Apim-Subscription-Key'] = '{subscription key}'
# Request body
request.body = "{body}"

response = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
    http.request(request)
end

puts response.body