Use this API to get all item inventory associated with your DSCO account from all of your  trading partners (in the case of a retailer) or just your account (in the case of a supplier) in the Dsco Platform.

 Reference the AlltemInventoryResult JSON Object and the ItemInventory JSON Object.

 The Get All Item Inventory API documents the API's URL, it's arguments/return values and how to interact with it (GET, POST, PUT, etc.) in the Dsco Interactive Playground.

The API should be called the first time without a pageIdentifier attribute.  Each result returned will include the pageIdentifier for the next page of results and the next call to the API should include the previous result's pageIdentifier value.  There are no more pages if either the API returns no results or the pageIdentifier is not present or null.

The results differ depending on whether you want to get the list of item inventory objects back compressed or not.  Due to the possible number of items in the array (as much as 10,000) it is recommended that you set the compressed attribute to true.

If compress is true the result will either have the itemInventory attribute set or it will have the base64EncodedCompressedItemInventory attribute set.

The  itemInventory attribute, if present, is the list of ItemInventory objects for this page of results.

The base64EncodedCompressedItemInventory, if present, is a base64 encoded string of the GZip compressed itemInventory results.  So, first decode this base64 string into a byte array and then decompress it using the gzip algorithm.  The result will be an array of ItemInventory objects.

If the pageIdentifier is not present or null then this is the last page of results.

If both the itemInventory attribute and the base64EncodedCompressedItemInventory attribute are both either not present or null then there are no more pages of results.

If either the itemInventory attribute or the base64EncodedCompressedItemInventory attribute (once unencoded and decompressed) are an empty list then there are no more pages of results.

The  AllItemInventoryResult JSON Object document includes complete code examples of decoding and decompressing the base64EncodedCompressedItemInventory string in both Java and Node JS.

See a complete working Node JS example to retrieve all item inventory below.  Please replace the <oauth_token> with your oauth token to run the example.

Date Search Semantics

As of 10/26/2017, the search semantics for dates on this API have changed.  Previous to this change, searching by a date used the last update date of the actual object in question.  After this change, the last  update date used will be the date the object was replicated to its final destination within the Dsco environment.  The replicated last update date will be very close to the actual last update date.  The replicated last update date will be used in searching to prevent a race condition where objects could be "dropped" between searches.

 Input Params

The Get All Item Inventory API documents the exact attributes that may be passed.  

  • pageIdentifier
    What page of results to return; the first page should not include this value; subsequent pages should include the pageIdentifier value returned in the previous page's results
  • updatedSince
    An optional date/time (as an ISO 8601 string) value which if provided will only return item inventory updated since this date
  • compress
    If true, the resulting json object's base64EncodedCompressedItemInventory attribute will contain a base64 encoded and gzip compressed string of the itemInventory array.  If false or not present, the resulting json object's itemInventory attribute will contain the list of json ItemInventory objects for this page.

 Output Object

The result of calling this API is the AllItemInventoryResult JSON Object. It will contain the list of ItemInventory JSON Objects or the base64 encoded and gzip compressed string returned from this API for the specified page of results if any and also a pageIdentifier attribute used on the next request to identify the next page of results to be returned.

'use strict';

const https = require('https');
const zlib = require('zlib');

const hostname = 'api.dropship.com';
let done = false;

function getInventoryDate(pageIdentifier) {
    return new Promise((resolve, reject) => {
        let data = '';
        let path = '/api/v2/iteminventory/all?compress=true' +
                   (!pageIdentifier ? '' : ('&pageIdentifier=' + pageIdentifier));
        let options =
            {
                hostname: hostname,
                path: path,
                port: 443,
                headers: {'Authorization': 'bearer <oauth_token>', 'accept': '*/*'}
            };

        let callback = function(response)
        {
            let data = '';
            response.on('data', function (chunk)
            {
                data += chunk;
            });

            response.on('end', function ()
            {
                const json = JSON.parse(data);
                const str = json.base64EncodedCompressedItemInventory;

                if (str) {
                    let buffer = new Buffer(str, 'base64');
                    let decompressedData = [];
                    let decompressor = zlib.createGunzip();
                    decompressor.write(buffer);
                    decompressor.end();
                    decompressor.on('data', function(d) {
                        decompressedData.push(d);
                    });
                    decompressor.on('error', function(e) {
                        reject(e);
                    });
                    decompressor.on('end', function() {
                        let itemInventoryStr = decompressedData.join('');
                        let itemInventoryJson = JSON.parse(itemInventoryStr);

                        console.log(JSON.stringify(itemInventoryJson));

                        resolve(!itemInventoryJson || itemInventoryJson.length === 0 ||
                                !json.pageIdentifier ? null : json.pageIdentifier);
                    });
                } else {
                    resolve(!json.pageIdentifier || !str  ? null : json.pageIdentifier);
                }
            });
        };


        var req = https.request(options, callback);

        req.on('error', function(e) {
            console.log('problem with request: ' + e.message);
            reject(e);
        });

        req.end();
    });
}

async function getAllInventory()
{
    let pageIdentifier = null;
    let done = false;

    do
    {
        pageIdentifier = await getInventoryDate(pageIdentifier);
        if (!pageIdentifier) {done = true;}

    } while (!done);
};

async function main() {
    try {
        await getAllInventory();
    } catch(e) {
        console.log('failed: ' + e);
    }
}

main();
Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.