- Created by Scott Pearce , last modified on Sept 18, 2017
You are viewing an old version of this page. View the current version.
Compare with Current View Page History
« Previous Version 6 Next »
Customers
Get a filtered list of customers
All tables have a corresponding Query class. For example, the table DB_Main has a class DB_MainQuery. The DB_MainQuery class is the DTO used for query operations against the DB_Main table. By setting various properties of an instance of this class, a filtered, ordered set of results can be obtained.
var client = new ServiceStack.JsonServiceClient("https://api.jiwa.com.au"); var authResponse = client.Get(new ServiceStack.Authenticate() { UserName = "admin", Password = "password" }); var DB_MainQueryRequest = new JiwaFinancials.Jiwa.JiwaServiceModel.Tables.DB_MainQuery() { AccountNoStartsWith = "1", OrderBy = "AccountNo", Take = 5 }; ServiceStack.QueryResponse<JiwaFinancials.Jiwa.JiwaServiceModel.Tables.DB_Main> DB_MainQueryResponse = client.Get(DB_MainQueryRequest);
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"); // 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/DB_Main?AccountNoStartsWith=1&OrderBy=AccountNo&Take=5"); }
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/DB_Main -d '{"AccountNoStartsWith":"1","OrderBy":"AccountNo","Take":"5"}'
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/DB_Main?AccountNoStartsWith=1&OrderBy=AccountNo&Take=5&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.
var client = new ServiceStack.JsonServiceClient("https://api.jiwa.com.au"); var authResponse = client.Get(new ServiceStack.Authenticate() { UserName = "admin", Password = "password" }); var DB_MainQueryRequest = new JiwaFinancials.Jiwa.JiwaServiceModel.Tables.DB_MainQuery() { AccountNoStartsWith = "1", OrderBy = "AccountNo", Take = 5, Fields = "DebtorID,AccountNo,Name,EmailAddress" }; ServiceStack.QueryResponse<JiwaFinancials.Jiwa.JiwaServiceModel.Tables.DB_Main> DB_MainQueryResponse = client.Get(DB_MainQueryRequest);
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/DB_Main?AccountNoStartsWith=1&OrderBy=AccountNo&Take=5&Fields=DebtorID,AccountNo,Name,EmailAddress"); }
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/DB_Main -d '{"AccountNoStartsWith":"1","OrderBy":"AccountNo","Take":"5","Fields":"DebtorID,AccountNo,Name,EmailAddress"}'
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/DB_Main?AccountNoStartsWith=1&OrderBy=AccountNo&Take=5&Fields=DebtorID,AccountNo,Name,EmailAddress&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.
var client = new ServiceStack.JsonServiceClient("https://api.jiwa.com.au"); var authResponse = client.Get(new ServiceStack.Authenticate() { UserName = "admin", Password = "password" }); var DB_MainQueryRequest = new JiwaFinancials.Jiwa.JiwaServiceModel.Tables.DB_MainQuery() { AccountNoStartsWith = "1", OrderBy = "AccountNo", Take = 5, Skip = 5, Fields = "DebtorID,AccountNo,Name,EmailAddress" }; ServiceStack.QueryResponse<JiwaFinancials.Jiwa.JiwaServiceModel.Tables.DB_Main> DB_MainQueryResponse = client.Get(DB_MainQueryRequest);
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/DB_Main?AccountNoStartsWith=1&OrderBy=AccountNo&Take=5&Skip=5&Fields=DebtorID,AccountNo,Name,EmailAddress"); }
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/DB_Main -d '{"AccountNoStartsWith":"1","OrderBy":"AccountNo","Take":"5","Skip":"5","Fields":"DebtorID,AccountNo,Name,EmailAddress"}'
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/DB_Main?AccountNoStartsWith=1&OrderBy=AccountNo&Take=5&Skip=5&Fields=DebtorID,AccountNo,Name,EmailAddress&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 customer
In order to read a customer, the DebtorID must be provided. Note this is a full read of the debtor business logic - so it will include associated elements such as notes, documents, prices and so on.
var client = new ServiceStack.JsonServiceClient("https://api.jiwa.com.au"); var authResponse = client.Get(new ServiceStack.Authenticate() { UserName = "admin", Password = "password" }); var debtorGETRequest = new JiwaFinancials.Jiwa.JiwaServiceModel.DebtorGETRequest() { DebtorID= "0000000061000000001V" }; JiwaFinancials.Jiwa.JiwaServiceModel.Debtors.Debtor Debtor = client.Get(debtorGETRequest);
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/Debtors/0000000061000000001V"); }
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/Debtors/0000000061000000001V
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/Debtors/0000000061000000001V?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.
The response returned from the above request will be a json document representing the full debtor DTO model from the business logic - see the meta data page for the DebtorGETRequest for more detail.
Create a new customer
You don't need to provide anything to create a customer- an AccountNo and DebtorID will be generated for you - however it's usual practice to provide a AccountNo. All other fields can be provided, but are not mandatory. The response DTO will contain the generated DebtorID , and all other fields of the customer.
var client = new ServiceStack.JsonServiceClient("https://api.jiwa.com.au"); var authResponse = client.Get(new ServiceStack.Authenticate() { UserName = "admin", Password = "password" }); var debtorPOSTRequest = new JiwaFinancials.Jiwa.JiwaServiceModel.DebtorPOSTRequest { AccountNo = "NewAccountNo", Name = "A new customer", EmailAddress = "name@example.com", WebAccess = true }; JiwaFinancials.Jiwa.JiwaServiceModel.Debtors.Debtor Debtor = client.Post(debtorPOSTRequest);
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"; 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 { AccountNo = "NewAccountNo", Name = "A new customer", EmailAddress = "name@example.com", WebAccess = true }); responsebody = webClient.UploadString("https://api.jiwa.com.au/Debtors", "POST", json); }
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 POST https://api.jiwa.com.au/Debtors -d '{"AccountNo":"NewAccountNo","Name":"A new customer","EmailAddress":"name@example.com", "WebAccess"""true"}'
The response returned from the above request will be a json document representing the full debtor DTO model from the business logic - see the meta data page for the DebtorPOSTRequest for more detail.
var client = new ServiceStack.JsonServiceClient("https://api.jiwa.com.au"); var authResponse = client.Get(new ServiceStack.Authenticate() { UserName = "admin", Password = "password" }); var debtorPOSTRequest = new JiwaFinancials.Jiwa.JiwaServiceModel.DebtorPOSTRequest { AccountNo = "NewAccountNo", Name = "A new customer", EmailAddress = "name@example.com", WebAccess = true }; debtorPOSTRequest.Notes.Add(new JiwaFinancials.Jiwa.JiwaServiceModel.Notes.Note() { NoteText = "Note text 1" }); debtorPOSTRequest.Notes.Add(new JiwaFinancials.Jiwa.JiwaServiceModel.Notes.Note() { NoteText = "Note text 2" }); JiwaFinancials.Jiwa.JiwaServiceModel.Debtors.Debtor Debtor = client.Post(debtorPOSTRequest);
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 { PartNo = "NewAccountNo", Description = "A new customer", EmailAddress = "name@example.com", WebAccess = true, Notes = new List<object>() { new { NoteText = "Note text 1" }, new { NoteText = "Note text 2" } } }); responsebody = webClient.UploadString("https://api.jiwa.com.au/Debtors", "POST", json); }
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 POST https://api.jiwa.com.au/Debtors -d '{"AccountNo":"NewAccountNo","Name":"A new Customer","EmailAddress ":"name@example.com", "WebAccess":"true", "Notes":[{"NoteText":"Note text 1"}, {"NoteText":"NoteText 2"}]}'
The response returned from the above request will be a json document representing the full debtor DTO model from the business logic - see the meta data page for the DebtorPOSTRequest for more detail.
Update an existing customer
var client = new ServiceStack.JsonServiceClient("https://api.jiwa.com.au"); var authResponse = client.Get(new ServiceStack.Authenticate() { UserName = "admin", Password = "password" }); var debtorPatchRequest = new JiwaFinancials.Jiwa.JiwaServiceModel.DebtorPATCHRequest { DebtorID = "0000000061000000001V", EmailAddress = "name2@example.com", WebAccess = false }; debtorPatchRequest.Notes.Add(new JiwaFinancials.Jiwa.JiwaServiceModel.Notes.Note() { NoteText = "A new note added" }); debtorPatchRequest.Notes.Add(new JiwaFinancials.Jiwa.JiwaServiceModel.Notes.Note() { NoteID = "DE91CC53-724A-47C6-8920-57AC82BFAD1F", NoteText = "A modified note text" }); JiwaFinancials.Jiwa.JiwaServiceModel.Debtors.Debtor Debtor = client.Patch(debtorPatchRequest);
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 { EmailAddress = "name2@example.com", WebAccess = "false", Notes = new List<object>() { new { NoteText = "A new note added" }, new { NoteID = "DE91CC53-724A-47C6-8920-57AC82BFAD1F", NoteText = "A modified note text" } } }); responsebody = webClient.UploadString("https://api.jiwa.com.au/Debtors/0000000061000000001V", "PATCH", json); }
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 PATCH http://localhost/Debtors/0000000061000000001V -d '{EmailAddress = "name2@example.com", WebAccess = "false","Notes":[{"NoteText":"A new note added"},{"NoteID":"DE91CC53-724A-47C6-8920-57AC82BFAD1F","NoteText":"A modified note text"}]}'
The response returned from the above request will be a json document representing the full debtor DTO model from the business logic - see the meta data page for the DebtorPOSTRequest for more detail.
Delete a customer
var client = new ServiceStack.JsonServiceClient("https://api.jiwa.com.au"); var authResponse = client.Get(new ServiceStack.Authenticate() { UserName = "admin", Password = "password" }); var debtorDELETERequest = new JiwaFinancials.Jiwa.JiwaServiceModel.DebtorDELETERequest { DebtorID = "1c4e1f674674465bb57a" }; client.Delete(debtorDELETERequest);
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.UploadString("http://localhost/Debtors/a256102d4b2c4202b0e8", "DELETE", ""); }
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 DELETE https://api.jiwa.com.au/Debtors/6c5b4a30c1b645ad9ebb
- No labels