Deck |
---|
|
Card |
---|
id | SalesOrderPOSTRequest_csharp_servicestack |
---|
label | ServiceStack Client C# |
---|
|
Code Block |
---|
| var client = new ServiceStack.JsonServiceClient("https://api.jiwa.com.au");
var authResponse = client.Get(new ServiceStack.Authenticate() { UserName = "admin", Password = "password" });
var salesOrderPOSTRequest = new JiwaFinancials.Jiwa.JiwaServiceModel.SalesOrderPOSTRequest()
{
DebtorID = "00000000080000000002",
InitiatedDate = DateTime.Now,
OrderNo = "1234",
SOReference = "Test order"
};
salesOrderPOSTRequest.Lines.Add(new JiwaFinancials.Jiwa.JiwaServiceModel.SalesOrders.SalesOrderLine { PartNo = "1170", QuantityOrdered = 5 });
salesOrderPOSTRequest.Lines.Add(new JiwaFinancials.Jiwa.JiwaServiceModel.SalesOrders.SalesOrderLine { CommentLine = true, CommentText = "This is a comment line" });
salesOrderPOSTRequest.Lines.Add(new JiwaFinancials.Jiwa.JiwaServiceModel.SalesOrders.SalesOrderLine { InventoryID = "000000000K00000000BV", QuantityOrdered = 2, DiscountedPrice = 15.67M, CustomFieldValues = new List<JiwaFinancials.Jiwa.JiwaServiceModel.CustomFields.CustomFieldValue> { new JiwaFinancials.Jiwa.JiwaServiceModel.CustomFields.CustomFieldValue { SettingID = "1ae102b94dc54dfc8a45 ", Contents = "Fragile - do not drop" } } });
salesOrderPOSTRequest.Payments.Add(new JiwaFinancials.Jiwa.JiwaServiceModel.SalesOrders.SalesOrderPayment { PaymentRef = "S454873-J5", AmountPaid = 50.00M });
var salesOrderPOSTResponse = client.Post(salesOrderPOSTRequest);
|
|
Card |
---|
id | SalesOrderPOSTRequest_csharp |
---|
label | C# |
---|
|
Code Block |
---|
| 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));
webClient.Headers[System.Net.HttpRequestHeader.ContentType] = "application/json";
string json = Newtonsoft.Json.JsonConvert.SerializeObject(new
{
DebtorID = "00000000080000000002",
InitiatedDate = DateTime.Now,
OrderNo = "1234",
SOReference = "Test order",
Lines = new List<object>
{
new { PartNo = "1170", QuantityOrdered = 5 },
new { CommentLine = true, CommentText = "This is a comment line" },
new { InventoryID = "000000000K00000000BV", QuantityOrdered = 2, DiscountedPrice = 15.67M, CustomFieldValues = new List<object> { new { SettingID = "1ae102b94dc54dfc8a45 ", Contents = "Fragile - do not drop" } } }
},
Payments = new List<object>
{
new { PaymentRef = "S454873-J5", AmountPaid = 50.00M }
}
});
responsebody = webClient.UploadString("https://api.jiwa.com.au/SalesOrders", "POST", json);
} |
|
Card |
---|
id | SalesOrderPOSTRequest_curl |
---|
label | Curl |
---|
|
Code Block |
---|
| 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" No Format |
---|
{"SessionId":"6w1nLX8r0sIrJHClX9Vj","UserName":"Admin","DisplayName":"","ResponseStatus":{}} |
Then, with the SessionId now known, the route can be called: Code Block |
---|
| curl -H 'Accept: application/json' -H 'Content-Type: application/json' --cookie 'ss-id=6w1nLX8r0sIrJHClX9Vj' -X POST https://api.jiwa.com.au/SalesOrders -d '{"DebtorID":"00000000080000000002","InitiatedDate":"2017-09-20","OrderNo":"1234","SOReference":"Test order","Lines":[{"PartNo":"1170","QuantityOrdered":5},{"CommentLine":"true","CommentText":"This is a comment line"},{"InventoryID":"000000000K00000000BV","QuantityOrdered":2,"DiscountedPrice:15.67,"CustomFieldValues":[{"SettingID":"1ae102b94dc54dfc8a45 ", "Contents":"Fragile - do not drop"}]}],"Payments":[{"PaymentRef":"S454873-J5","AmountPaid":50.00}]}' |
|
|
The response returned from the above request will be a json document representing the full sales order DTO model from the business logic - see the meta data page for the SalesOrderPOSTRequest for more detail. Note(1): The DebtorID or DebtorAccountNo can be provided. If both are provided, then the DebtorID will be used to resolve the debtor. Note(2): The sales order line added can provide either the InventoryID, or the PartNo. If both are provided, then the InventoryID will be used to resolve the inventory item. Note(3): When sales order lines are added, omitting the price will cause Jiwa to determine the price per normal pricing scheme logic. Note(4): The last line added in the above example sets a custom line field value for a setting with ID "1ae102b94dc54dfc8a45" Note(5): When adding payments if the PaymentType is omitted, then the default payment type configured in Jiwa is used. |