Sales Order API Operations - Examples Of Use

Sales Order API Operations - Examples Of Use

 

 

Sales Orders

Get a filtered list of sales orders

Using v_Jiwa_SalesOrder_ListQuery

A view, v_Jiwa_SalesOrder_List is provided with a corresponding query class v_Jiwa_SalesOrder_ListQuery to facilitate retrieving a filtered, paginated list of sales orders.  The data returned includes data from several tables to bring together customer, sales order, delivery information from one query.

Which fields are returned can be limited with the Fields property - so only the required fields are returned.

With the Include property set to "Total" the response will include the total count of records matching the query - this is useful for pagination. The Skip and Take properties can be added specify the starting record number to return and the number of records to return.

Retrieve first 25 sales orders from the NSW/Main warehouse, ordered by InvoiceNo.
 ServiceStack Client C#
var client = new ServiceStack.JsonServiceClient("https://api.jiwa.com.au");
var authResponse = client.Get(new ServiceStack.Authenticate() { UserName = "admin", Password = "password" });

var salesOrderListRequest = new JiwaFinancials.Jiwa.JiwaServiceModel.Tables.v_Jiwa_SalesOrder_ListQuery() { PhysicalWarehouseDescription = "New South Wales", LogicalWarehouseDescription = "Main", Fields = "InvoiceID,InvoiceNo,InvoiceInitDate,DebtorID,DebtorAccountNo,DebtorName",OrderBy = "InvoiceNo", Include = "Total", Take = 25 };
ServiceStack.QueryResponse<JiwaFinancials.Jiwa.JiwaServiceModel.Tables.v_Jiwa_SalesOrder_List> salesOrderListResponse = client.Get(salesOrderListRequest);
 C#
using (var webClient = new System.Net.WebClient())
{
    // Authenticate               
    webClient.QueryString.Add("username", "Admin");
    webClient.QueryString.Add("password", "password");
     
    string responsebody = webClient.DownloadString("https://api.jiwa.com.au/auth");               
    // Above returns something like this: {"SessionId":"0hKBFAnutUk8Mw6YY6DN","UserName":"api","DisplayName":"","ResponseStatus":{}}
 
    // Deserialise response into a dynamic - below requires the Newtonsoft.Json nuget package
    var authResponse = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(responsebody);
    var sessionId = authResponse.SessionId;
 
    webClient.Headers.Add(System.Net.HttpRequestHeader.Cookie, string.Format("ss-id={0}", sessionId));               
    responsebody = webClient.DownloadString("https://api.jiwa.com.au/Queries/SalesOrderList?PhysicalWarehouseDescription=New South Wales&LogicalWarehouseDescription=Main&Fields=InvoiceID,InvoiceNo,InvoiceInitDate,DebtorID,AccountNo,DebtorName&OrderBy=InvoiceNo&Include=Total&Take=25");                
}
 Curl
curl -H 'Accept: application/json' -H 'Content-Type: application/json' -X GET https://api.jiwa.com.au/auth -d '{"username":"Admin","password":"password"}'

Returns the following authentication response, containing the SessionId which subsequent requests will need to include in the cookie "ss-id"

{"SessionId":"6w1nLX8r0sIrJHClX9Vj","UserName":"Admin","DisplayName":"","ResponseStatus":{}}

Then, with the SessionId now known, the route can be called:

 curl -H 'Accept: application/json' -H 'Content-Type: application/json' --cookie 'ss-id=6w1nLX8r0sIrJHClX9Vj' -X GET https://api.jiwa.com.au/Queries/SalesOrderList?PhysicalWarehouseDescription=New%20South%20Wales&LogicalWarehouseDescription=Main&Fields=InvoiceID,InvoiceNo,InvoiceInitDate,DebtorID,AccountNo,DebtorName&OrderBy=InvoiceNo&Include=Total&Take=25

Instead of using URL parameters as above, you can also use a DTO to set the parameters:

 curl -H 'Accept: application/json' -H 'Content-Type: application/json' --cookie 'ss-id=6w1nLX8r0sIrJHClX9Vj' -X GET https://api.jiwa.com.au/Queries/SalesOrderList -d '{"PhysicalWarehouseDescription":"New South Wales", "LogicalWarehouseDescription":"Main","Fields":"InvoiceID,InvoiceNo,InvoiceInitDate,DebtorID,AccountNo,DebtorName", "OrderBy":"InvoiceNo", "Include":"Total", "Take":25}'
 Web Browser

Navigate to the auth URL and provide the username and password as parameters:

https://api.jiwa.com.au/auth?username=admin&password=password

This authenticates the user and creates a cookie, so a subsequent request can be made:

https://api.jiwa.com.au/Queries/SalesOrderList?PhysicalWarehouseDescription=New%20South%20Wales&LogicalWarehouseDescription=Main&Fields=InvoiceID,InvoiceNo,InvoiceInitDate,DebtorID,DebtorAccountNo,DebtorName&OrderBy=InvoiceNo&Include=Total&Take=25&format=json

Note the &format=json in the above URL this overrides the content type returned. For browsers the default content type is HTML - if a content type override is omitted, then a HTML razor view of the data will be returned instead of json. xml and csv are also valid overrides for the content type to be returned.

With the above example, simply setting the Skip property of the request DTO to 25 will have the effect of retrieving the next 25 records.  Because we include in the request Include=Total, the response will contain a property, Total, which is the count of the total number of records matching the query.

Using SO_MainQuery

An alternative to using the v_Jiwa_SalesOrder_ListQuery is to simply use the SO_MainQuery.

All tables have a corresponding Query class. For example, the table SO_Main has a class SO_MainQuery. The SO_MainQuery class is the DTO used for query operations against the SO_Main table. By setting various properties of an instance of this class, a filtered, ordered set of results can be obtained.

Retrieve first 25 sales orders, ordered by InvoiceNo.
 ServiceStack Client C#
var client = new ServiceStack.JsonServiceClient("https://api.jiwa.com.au");
var authResponse = client.Get(new ServiceStack.Authenticate() { UserName = "admin", Password = "password" });

var salesOrderListRequest = new JiwaFinancials.Jiwa.JiwaServiceModel.Tables.SO_MainQuery() { Fields = "InvoiceID, InvoiceNo, InvoiceInitDate, DebtorID", OrderBy = "InvoiceNo", Take = 25, Include = "Total" };
ServiceStack.QueryResponse<JiwaFinancials.Jiwa.JiwaServiceModel.Tables.SO_Main> salesOrderListResponse = client.Get(salesOrderListRequest);
 C#
using (var webClient = new System.Net.WebClient())
{
    // Authenticate               
    webClient.QueryString.Add("username", "Admin");
    webClient.QueryString.Add("password", "password");
     
    string responsebody = webClient.DownloadString("https://api.jiwa.com.au/auth");               
    // Above returns something like this: {"SessionId":"0hKBFAnutUk8Mw6YY6DN","UserName":"api","DisplayName":"","ResponseStatus":{}}
 
    // Deserialise response into a dynamic - below requires the Newtonsoft.Json nuget package
    var authResponse = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(responsebody);
    var sessionId = authResponse.SessionId;
 
    webClient.Headers.Add(System.Net.HttpRequestHeader.Cookie, string.Format("ss-id={0}", sessionId));               
    responsebody = webClient.DownloadString("https://api.jiwa.com.au/Queries/SO_Main?Fields=InvoiceID,InvoiceNo,InvoiceInitDate,DebtorID&OrderBy=InvoiceNo&Take=25&Include=Total");                            
}
 Curl
curl -H 'Accept: application/json' -H 'Content-Type: application/json' -X GET https://api.jiwa.com.au/auth -d '{"username":"Admin","password":"password"}'

Returns the following authentication response, containing the SessionId which subsequent requests will need to include in the cookie "ss-id"

{"SessionId":"6w1nLX8r0sIrJHClX9Vj","UserName":"Admin","DisplayName":"","ResponseStatus":{}}

Then, with the SessionId now known, the route can be called:

 curl -H 'Accept: application/json' -H 'Content-Type: application/json' --cookie 'ss-id=6w1nLX8r0sIrJHClX9Vj' -X GET https://api.jiwa.com.au/Queries/SO_Main?&Fields=InvoiceID,InvoiceNo,InvoiceInitDate,DebtorID&OrderBy=InvoiceNo&Include=Total&Take=25

Instead of using URL parameters as above, you can also use a DTO to set the parameters:

 curl -H 'Accept: application/json' -H 'Content-Type: application/json' --cookie 'ss-id=6w1nLX8r0sIrJHClX9Vj' -X GET https://api.jiwa.com.au/Queries/SO_Main -d '{"Fields":"InvoiceID,InvoiceNo,InvoiceInitDate,DebtorID", "OrderBy":"InvoiceNo", "Include":"Total", "Take":25}'
 Web Browser

Navigate to the auth URL and provide the username and password as parameters:

https://api.jiwa.com.au/auth?username=admin&password=password

This authenticates the user and creates a cookie, so a subsequent request can be made:

https://api.jiwa.com.au/Queries/SO_Main?Fields=InvoiceID,InvoiceNo,InvoiceInitDate,DebtorID&OrderBy=InvoiceNo&Include=Total&Take=25&format=json

Note: The &format=json in the above URL this overrides the content type returned. For browsers the default content type is HTML - if a content type override is omitted, then a HTML razor view of the data will be returned instead of json. xml and csv are also valid overrides for the content type to be returned.

Read a Sales Order

Create a new Sales Order

Update an existing Sales Order

Custom Fields

List all custom fields for sales orders

Get All Custom Field Values for a Single Sales Order

Get a Single Custom Field Value for a Sales Order and Custom Field

Update a Single Custom Field Value for a Sales Order and Custom Field

Sales Order History (Snapshot)

Retrieve a list of sales order histories

Retrieve a sales order history

Update a sales order history

Note that to update some fields of the sales order history, you need to not use the SalesOrderHistorysPATCHRequest on /SalesOrders/{InvoiceID}/Historys/{InvoiceHistoryID} but instead use the SalesOrderPATCHRequest - this will pass the values through to the current snaphot number of the sales order.  See Update An Existing Sales Order.

Custom Fields

List all custom fields for sales order historys

Get All Custom Field Values for a Single Sales Order History

Get a Single Custom Field Value for a Sales Order history and Custom Field

Update a Single Custom Field Value for a Sales Order history and Custom Field

Lines

Read all lines for a sales order

Read a sales order line

Add a line to a sales order

Inventory Item

Comment Line

Update a sales order line

Delete a sales order line

Custom Fields

List all custom fields for sales order lines

Get All Custom Field Values for a Single Sales Order Line

Get a Single Custom Field Value for a Sales Order line and Custom Field

Update a Single Custom Field Value for a Sales Order line and Custom Field

Notes

Documents

Processing a Sales Order

To process a sales order, a specific route must be called, this then performs the business logic for posting journals and debtor transactions.