Class properties for calling Jiwa API from other application  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

Class properties for calling Jiwa API from other application

Postby sameermoin » Tue Nov 08, 2022 5:34 am

Hi Everyone,

Is there any way to get all the class properties for API calling from a different application?

I am trying to perform some actions from a different application for POST/GET requests with Jiwa for Product, SalesOrder, etc for that I want to do serialization and deserialization with the appropriate class in my application.

I am not using ServiceStack for API calls I am using the RestSharp client. I can see the ServiceStack DTOs in the localhost:8000/types/csharp and each verb has a different DTO and I don't want to create a separate class for every verb. It makes my work easy if I directly get all the classes instead of checking the swagger docs and creating them manually


Regards
Sameer
sameermoin
Regular Contributor
Regular Contributor
 
Posts: 75
Joined: Wed Jun 15, 2022 4:02 am
Topics Solved: 1

Re: Class properties for calling Jiwa API from other applica

Postby SBarnes » Tue Nov 08, 2022 7:52 am

Yes there is I have never done it with RestSharp although there should be no reason why you can't but there is no reason you can't use both see https://docs.servicestack.net/clients-overview for ServiceStack clients which have a lot of what you need baked in. With RESTSharp you just need to get the response as a string and deserialise it.

If it is on the same machine as Jiwa you can directly instantiate a manger, log it in and use it like in a plugin, you just reference the Jiwa DLLs. See viewtopic.php?f=27&t=172
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Class properties for calling Jiwa API from other applica

Postby Mike.Sheen » Tue Nov 08, 2022 11:29 am

sameermoin wrote:each verb has a different DTO and I don't want to create a separate class for every verb.


The DTO's often are subtlety different for each verb.

For instance, the sales order DTO is our base DTO for the sales order operations - GET of a sales order uses this without alteration, but the POST accepts an altered version which excludes the InvoiceID, but it does return the sales order DTO as the same as the GET.

And some operations inject their own property into the DTO which they expect to be set.

Can you provide an example of how you would want it to look?
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: Class properties for calling Jiwa API from other applica

Postby sameermoin » Tue Nov 08, 2022 5:40 pm

let's consider the example in which I have a model of a
Code: Select all
Product
and I am using RestSharp

Code: Select all
public class Product {
        public long Id { get; set; }
        public string Title { get; set; }

}


and I want to do a POST request I simply do

Code: Select all
           var request = new RestRequest($"URI", Method.Post);
            var body = JsonConvert.SerializeObject(new Product
            {
                Id = x.Id,
                Title = x.Title

            });

            request.AddParameter("application/json", body, ParameterType.RequestBody);
            var response = JsonConvert.DeserializeObject<Product>(await _client.ExecuteAsync(request).Data);


This is just an example, not an actual code. This class is usable with other calls like GET/PUT
sameermoin
Regular Contributor
Regular Contributor
 
Posts: 75
Joined: Wed Jun 15, 2022 4:02 am
Topics Solved: 1

Re: Class properties for calling Jiwa API from other applica

Postby Mike.Sheen » Tue Nov 08, 2022 5:53 pm

You can do that with our API.

We provide verb specific types which remove the irrelevant fields, but there is no reason why you can't use the base class these inherit from.

For example, if you perform a GET on /Inventory/{InventorID} that returns a class of type JiwaFinancials.Jiwa.JiwaServiceModel.Inventory.InventoryItem

When you perform a POST or a PATCH you can also use the same type - we'll ignore the fields we are not interested in for the operation (such as LastSavedDateTime).

We just offer in addition to the JiwaFinancials.Jiwa.JiwaServiceModel.Inventory.InventoryItem class tailored classes which inherit from JiwaFinancials.Jiwa.JiwaServiceModel.Inventory.InventoryItem and hide / omit the unnecessary fields.

Those tailored classes, in the case of Inventory Items are InventoryPOSTRequest for creating new items and InventoryPATCHRequest for updating existing items - both of these just inherit from JiwaFinancials.Jiwa.JiwaServiceModel.Inventory.InventoryItem.

Does that satisfy your requirements?
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: Class properties for calling Jiwa API from other applica

Postby sameermoin » Tue Nov 08, 2022 6:27 pm

where all these base classes are located?

Do I need to decompile the Jiwa ?
sameermoin
Regular Contributor
Regular Contributor
 
Posts: 75
Joined: Wed Jun 15, 2022 4:02 am
Topics Solved: 1

Re: Class properties for calling Jiwa API from other applica  Topic is solved

Postby Mike.Sheen » Tue Nov 08, 2022 6:40 pm

sameermoin wrote:where all these base classes are located?

Do I need to decompile the Jiwa ?


No, you can get them a couple of ways.

The easiest in my opinion is you can have the API generate the classes for you provided it's one of the languages we support (C#, VB.NET, F#, Typescript, Jaca, Kotlin or Swift) - Again scroll down to the bottom of the metadata page and choose one.
API_Generate_Links.png


In the generated code, you can find the classes of interest and copy-paste into your code - for example, the InventoryItem class as accepted by the GET, POST and PATCH operations for the /Inventory operations:
API_Generate_CSharp_InventoryItem.png


The XSD's for everything can also be obtained from the XSD's link on the metadata page - scroll down to the bottom. With the XSD's many modern tools exist to generate the class in your language of choice.

And if you're using .NET, you can use the JiwaServiceModel.dll which is deployed by Jiwa - it contains all these DTO's and is dependency free - add a reference to that assembly in your project to use them this way.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 34 guests