How to create ASN's with the Infoplus API

You can set up Infoplus to automatically create ASNs by utilizing the Infoplus API and a script.

Many users of the Infoplus API need a way to push Purchase Order (PO) data from a source system, such as an ERP or other in-house system into Infoplus, to provide Infoplus Advanced Shipment Notification (ASN) data for inventory that is on its way to be received in an Infoplus managed warehouse. This is relatively straightforward to do with the Infoplus API.  


The purpose of this article is to explain the basic set of required fields for creating an ASN with the Infoplus API, to give you a starting point that you can build upon.  


From a mechanical standpoint, creating an ASN is as simple as a single HTTP POST to the order endpoint in the Infoplus API.  For example, using version 1.0 of the api, on the command line:    

curl -s -H API-Key:YOUR-API-KEY -H Content-Type:application/json -X POST -d @asn.
json \    https://YOUR-INFOPLUS-DOMAIN/infoplus-wms/api/v1.0/asn

The interesting part is all about the data that is included in that POST (i.e., in the asn.json file on the command line shown above).


The simplest example ASN that can be placed through the Infoplus API looks like the following:    

 

Going through that JSON object field-by-field, we have:

Field Description Notes
poNo String; Unique identifier (within the LOB) for this ASN.  PO No and LOB Id form a unique constraint on ASN's in Infoplus. PO No's are limited to 40 characters.  
lobId Integer; Id of the Line of Business (LOB) that the ASN belongs to.  You can find your LOB Id by using the lineOfBusiness/search endpoint in the Infoplus API, as in:
curl -H API-Key:YOUR-API-KEY \
https://YOUR-INFOPLUS-DOMAIN/infoplus-wms/api/v1.0/lineOfBusiness/search
warehouseId Integer; Id of the Warehouse that the ASN will be received into. You can find your Warehouse Id in the Warehouse Table, within Infoplus.
Or, you can use the warehouse/search endpoint in the Infoplus API, as in:
curl -H API-Key:YOUR-API-KEY \
https://YOUR-INFOPLUS-DOMAIN/infoplus-wms/api/v1.0/warehouse/search
vendorId Integer; Id of the Vendor in Infoplus that the ASN was sent from. You can find your Vendor Ids in the Vendor Table, within Infoplus.
Or, you can use the vendor/search endpoint in the Infoplus API, as in:
curl -H API-Key:YOUR-API-KEY \
https://YOUR-INFOPLUS-DOMAIN/infoplus-wms/api/v1.0/vendor/search
orderDate Date (YYYY-MM-DD); Date that the ASN was placed in the source system.  
type  Enumerated String; Classifier for behavior type of the ASN. Must be one of the following: Normal, Kit, Transfer.
Note: Use "Normal" unless you have a specific reason not to.
lineItems List of Line Items on the ASN.  At least 1 line Item is required.  
lineItems[i].sku String;  Unique identifier (within the LOB) for the Item being ordered. All SKU's on an ASN must be unique (i.e., you can not have 2 or more line items for the same SKU).
lineItems[i].orderQuantity Integer; Unit quantity being ordered.   
lineItems[i].lobId Integer; Id of the Line of Business (LOB) that the Line Items belongs to. Must match the lobId on the header of the ASN.

 

Beyond these required fields, there are many more optional fields that can be included when you create (or update) an ASN. You can consult the API Reference Site for a listing of all fields.  


For updating an ASN, the recommended usage pattern is:  

  1. Use a GET to have a clean, up-to-date copy of the asn object that you want to update.  
  2. Modify the object as needed (removing line Items, adjusting quantities, adding line items, editing header fields, etc, as needed).  
  3. Use a PUT to send the updated object back in Infoplus.

Using an Infoplus Script to Create an ASN from an Order


Many Infoplus users have inquired on how they can automatically create an ASN based off of an existing order in the system. For example, business ABC sells wedding decorations that can either be purchased to keep or rented to return. For the orders that are rented, they want Infoplus to automatically create an ASN that can be used to receive the products as they are returned to their warehouse. 

Using the ASN Construct model described above, an Infoplus script can be deployed (and typically ran via trigger) to accomplish this automation. Below is an example script that can be copy and pasted (with some variable tweaking) directly into your own instance.

// Specify the vendor for the ASN. Vendor is a required field of ASN's.
var VENDOR_ID = 1;
utils.log("Starting Script To Create ASN");


// set the PO Number variable. In this example we are setting "Return: "  + the customer order number as the PO.var poNo = "Return: " + order.customerOrderNo;

// Now we are going to build up a filter to use in an API search that checks the ASN table to see if the PO already exists. 
var filter = "poNo eq '" + poNo + "'";
utils.log("Searching for existing ASN with [" + filter + "]");
var itemList = infoplusApi.search("asn", filter, null, 1, null);

//if the ASN already exists, throw a message and exit the script
if(itemList.size() > 0)
{
   utils.log("Found existing ASN with poNo of '" + poNo + "', exiting...");
   return;
}

// if the ASN does not exist, continue building up the ASN using the construct model. utils.log("Creating new ASN record");
var asn = infoplusApi.constructModel("ASN");
asn.poNo = poNo;
asn.vendorId = VENDOR_ID;
asn.lobId = 123456;
asn.warehouseId = order.warehouseId;
asn.orderDate = new Date();

// update 'misc' ASN fields with order information
asn.shipToName = order.shipToCompany; 
asn.shipToStreet1 = order.shipToStreet;

if(order.shipToStreet2)
{
    asn.shipToStreet2 = order.shipToStreet2; 
}
asn.shipToCity = order.shipToCity; 
asn.shipToState = order.shipToState; 
asn.shipToZipCode = order.shipToZip; 

// iterate over order lines, consolidating shipped quantities 
var consolidatedLineItems = {} // map of SKU to shipped qty.
for(var i=0; i<order.lineItems.size(); i++)
{
    var sourceLineItem = order.lineItems.get(i);
    var sku = sourceLineItem.sku;
    var orderedQuantity = Number(sourceLineItem.orderedQty);
    
    if(orderedQuantity > 0)
    {
        if(consolidatedLineItems[sku])
        {
            consolidatedLineItems[sku] += orderedQuantity;
        }
        else
        {
            consolidatedLineItems[sku] = orderedQuantity;
        }
    }
}

// iterate over line items, creating ASN lines for each //
for(var sku in consolidatedLineItems)
{
    var asnLineItem = infoplusApi.constructModel("ItemReceipt");
    asnLineItem.orderQuantity = consolidatedLineItems[sku];
    asnLineItem.sku = sku;
    asnLineItem.lobId = 17778;
    asn.addToLineItems(asnLineItem);
    
}

// create the ASN
var newAsn = infoplusApi.add("ASN", asn);