Get Creditors via ServiceStack  Topic is solved

Discussions relating to the REST API of Jiwa 7.

Get Creditors via ServiceStack

Postby Andrew S » Thu Oct 14, 2021 4:28 am

Hello There,

I created a ServiceStack reference to JIWA API in my .NET application according to the JIWA documentation https://docs.jiwa.com.au/display/J7UG/C ... e+REST+API
I try to get the full list of Creditors using JiwaFinancials.Jiwa.JiwaServiceModel.Tables.CR_MainQuery
I get "Not Found" exception.
How can I get the full list of Creditors?

Regards,
Andrew
Andrew S
I'm new here
I'm new here
 
Posts: 5
Joined: Wed May 05, 2021 5:41 pm

Re: Get Creditors via ServiceStack

Postby SBarnes » Thu Oct 14, 2021 8:57 am

Hi Andrew,

CR_Main is a Jiwa table and JiwaFinancials.Jiwa.JiwaServiceModel.Tables.CR_MainQuery may not exposed, it should be but check the following.

You need to add a route or check for a route which should be something like the following code in the REST API plugin

Code: Select all
      AppHost.Routes.Add(typeof(CR_MainQuery), "/Queries/CR_Main", "GET", "Retrieves a list of creditors.", "");


If this exists then it could be a configuration issue which might be related to the user that you are logging into the api as, so go to System Settings -> Staff configuration -> User Group Maintenance -> Rest API and check what routes you have exposed for the user you can also look at the default permissions on the api which is directly above this tab. You will need to restart the api if you change anything here.

You can also go to the Swagger UI link for the your version of the API login and test the route there which should answer if its actually working and the issue is how it's being called in other words is the problem at the api/server end or the client end.

If all of this works then I suggest you post details of how you are actually making the call to help in diagnosing the problem.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Get Creditors via ServiceStack

Postby Scott.Pearce » Thu Oct 14, 2021 3:37 pm

This worked for me:

Code: Select all
        static void Main(string[] args)
        {
            var client = new ServiceStack.JsonServiceClient("https://api.jiwa.com.au");
            var authResponse = client.Get(new ServiceStack.Authenticate() { UserName = "admin", Password = "password" });

            var CR_MainQueryRequest = new JiwaFinancials.Jiwa.JiwaServiceModel.Tables.CR_MainQuery() { OrderBy = "AccountNo" };
            ServiceStack.QueryResponse<JiwaFinancials.Jiwa.JiwaServiceModel.Tables.CR_Main> CR_MainQueryResponse = client.Get(CR_MainQueryRequest);

            foreach (JiwaFinancials.Jiwa.JiwaServiceModel.Tables.CR_Main creditor in CR_MainQueryResponse.Results)
            {
                Console.WriteLine("{0} - {1}", creditor.AccountNo, creditor.Name);
            }
           
        }


Let me know if you want me to attach the whole project.
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 742
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 221

Re: Get Creditors via ServiceStack

Postby Andrew S » Fri Oct 15, 2021 9:57 pm

Scott.Pearce wrote:This worked for me:

Code: Select all
        static void Main(string[] args)
        {
            var client = new ServiceStack.JsonServiceClient("https://api.jiwa.com.au");
            var authResponse = client.Get(new ServiceStack.Authenticate() { UserName = "admin", Password = "password" });

            var CR_MainQueryRequest = new JiwaFinancials.Jiwa.JiwaServiceModel.Tables.CR_MainQuery() { OrderBy = "AccountNo" };
            ServiceStack.QueryResponse<JiwaFinancials.Jiwa.JiwaServiceModel.Tables.CR_Main> CR_MainQueryResponse = client.Get(CR_MainQueryRequest);

            foreach (JiwaFinancials.Jiwa.JiwaServiceModel.Tables.CR_Main creditor in CR_MainQueryResponse.Results)
            {
                Console.WriteLine("{0} - {1}", creditor.AccountNo, creditor.Name);
            }
           
        }


Let me know if you want me to attach the whole project.


Hello Scott,

This code works for me as well in case I call https://api.jiwa.com.au
When I execute this code for my JIWA API, I get "Not Found" exception. Maybe the issue relates to my JIWA configurations? Please advice which particular configurations.
Andrew S
I'm new here
I'm new here
 
Posts: 5
Joined: Wed May 05, 2021 5:41 pm

Re: Get Creditors via ServiceStack

Postby Andrew S » Fri Oct 15, 2021 10:05 pm

SBarnes wrote:CR_Main is a Jiwa table and JiwaFinancials.Jiwa.JiwaServiceModel.Tables.CR_MainQuery may not exposed, it should be but check the following.

You need to add a route or check for a route which should be something like the following code in the REST API plugin

Code: Select all
      AppHost.Routes.Add(typeof(CR_MainQuery), "/Queries/CR_Main", "GET", "Retrieves a list of creditors.", "");


If this exists then it could be a configuration issue which might be related to the user that you are logging into the api as, so go to System Settings -> Staff configuration -> User Group Maintenance -> Rest API and check what routes you have exposed for the user you can also look at the default permissions on the api which is directly above this tab. You will need to restart the api if you change anything here.


Hello Stuart,

I don't have any routes here System Settings -> Staff configuration -> User Group Maintenance -> Rest API. However, I have default permissions = Allow. Please look at the screenshot below. I can successfully get Debtors or Inventory for example, so these routes work, only Creditors doesn't

Untitled.png
Image


Could you please advice what exactly should I add to allow to get Creditors?
Andrew S
I'm new here
I'm new here
 
Posts: 5
Joined: Wed May 05, 2021 5:41 pm

Re: Get Creditors via ServiceStack

Postby Andrew S » Sat Oct 16, 2021 4:38 am

More to the point. The code provided by Scott works well in I call the server "https://api.jiwa.com.au"
If I call my server, it fails with "Not Found" exception on the row
ServiceStack.QueryResponse<JiwaFinancials.Jiwa.JiwaServiceModel.Tables.CR_Main> CR_MainQueryResponse = client.Get(CR_MainQueryRequest);

However, this code works well for my server
HttpWebResponse resp = client.Get("/Queries/CR_Main");

The class CR_Main was generated automatically by ServiceStack and it contains the correct URL. Apart from that, it works for the server https://api.jiwa.com.au

Untitled.png
Image


Could you please let me know why my ServiceStack reference doesn't work correctly and what I have to do in the current situation?
Andrew S
I'm new here
I'm new here
 
Posts: 5
Joined: Wed May 05, 2021 5:41 pm

Re: Get Creditors via ServiceStack

Postby SBarnes » Sun Oct 17, 2021 12:21 pm

OK that is weird as the route is definitely there a few things that you can try

1. Try creating a new Jiwa Demo database point the api at that and see if you still get the error, this will rule out it being related to a specific database if you still get the error.

2. Try the following lines of code for the call instead

Code: Select all
JiwaFinancials.Jiwa.JiwaServiceModel.Tables.CR_MainQuery CR_MainQueryRequest = new JiwaFinancials.Jiwa.JiwaServiceModel.Tables.CR_MainQuery() { OrderBy = "AccountNo" };
 ServiceStack.QueryResponse<JiwaFinancials.Jiwa.JiwaServiceModel.Tables.CR_Main> CR_MainQueryResponse = client.Get<ServiceStack.QueryResponse<JiwaFinancials.Jiwa.JiwaServiceModel.Tables.CR_Main>>(CR_MainQueryRequest);


3. You can have a look at the request logs and see what is being handed in at the bottom of the base page for api there is a link which will go to something like https://api.jiwa.com.au/requestlogs

4. Go to the rest api plugin and add some blank lines and save it or do something so it will detect the change then restart the api this will cause it recompile just in case there is an issue here. If you get errors on the save don't worry about it the compiler inside Jiwa doesn't like certain stuff in the login part but it will compile on start up. Then restart the api.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Get Creditors via ServiceStack

Postby Mike.Sheen » Sun Oct 17, 2021 1:19 pm

And step 5:

Provide a sample project which exhibits the problem. If you can, also the URL of the API which you're using.
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: 2445
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 757

Re: Get Creditors via ServiceStack

Postby Andrew S » Tue Oct 19, 2021 12:52 am

Mike.Sheen wrote:And step 5:

Provide a sample project which exhibits the problem. If you can, also the URL of the API which you're using.

Unfortunately, neither of the solutions provided above works for me. Test project with my detailed comments is attached to this message. I really appreciate it if you could check it and let me know what is wrong.
Attachments
JIWADemo.zip
Demo
(9.64 MiB) Downloaded 38 times
Andrew S
I'm new here
I'm new here
 
Posts: 5
Joined: Wed May 05, 2021 5:41 pm

Re: Get Creditors via ServiceStack

Postby Scott.Pearce » Tue Oct 19, 2021 11:50 am

I grabbed you project and pointed it to localhost demo data. Worked fine.

You now need to provide 2 things:

1. A copy of the REST API plugin you are using (i.e. XML Export the plugin via the Utilities ribbon menu on the plugin form and attach it here).
2. Access to your URL.
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 742
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 221

Next

Return to REST API

Who is online

Users browsing this forum: No registered users and 1 guest

cron