DebtorNotesGETManyRequest API Key Bug

Discussions relating to the REST API of Jiwa 7.

DebtorNotesGETManyRequest API Key Bug

Postby SBarnes » Sun Oct 14, 2018 11:19 am

Hi Guys

I think I have found a bug with DebtorNotesGETManyRequest in the Web API, basically I have a situation where I use the same JSonServiceClient to make a number of calls to the API before logging off, using a user name and password the code works perfectly but as soon as you change it to use an API key the call to DebtorNotesGETManyRequest produces a null reference exception on the manager, interestingly subsequent calls using the same client work so long as the exception has been caught and ignored.

A call to the same route with a brand new JSonServiceClient also fails.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1617
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: DebtorNotesGETManyRequest API Key Bug

Postby Scott.Pearce » Wed Nov 21, 2018 8:45 am

Working OK for me using Postman to hit https://api.jiwa.com.au/Debtors/0000000 ... 001V/Notes with an API Key. Are you able to provide further information, perhaps a test project that demonstrates the issue?
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: DebtorNotesGETManyRequest API Key Bug

Postby SBarnes » Wed Nov 21, 2018 5:15 pm

Hi Scott,

It happens using JsonServiceClient, I am adding extra headers but I am not clearing them so that can't be the problem and I have a general routine to login as shown below, you can see where I tried the API key and then commented it out:

Code: Select all
public static JsonServiceClient GetAPIClient(string URL = "", bool LoggedIn = true)
        {
            string methodName = MethodBase.GetCurrentMethod().Name;
            string className = "ERP";
            ERP.LogString("User: " + ERP.GetUser().UserLogString(), "Class : " + className + " Method: " + methodName);

            try
            {
               // JsConfig.IncludeNullValues = true;
               // ServiceStack.ClientConfig.SkipEmptyArrays
                if (URL == "")
                {
                    URL = ConfigManager().GetString("JiwaAPIURL");
                }
               
                JsonServiceClient client = new JsonServiceClient(URL);
                client.Headers.Add("jiwa-stateful", "false");
                client.Timeout = new TimeSpan(0, ERP.ConfigManager().GetInt("APITimeOut"), 0);
                client.ReadWriteTimeout = new TimeSpan(0, ERP.ConfigManager().GetInt("APITimeOut"), 0);
                //var cookie1 = new Cookie("USERDETAILS", GetUser().UserLogString());
                client.SetCookie("USERDETAILS", GetUser().UserSSString());
               // client.CookieContainer.Add(cookie1);
               

                if (bool.Parse(ConfigManager().GetString("LogRequests")))
                {
                    client.RequestFilter = request =>
                    {
                        //request.GetRequestStream
                        //string dstring = request.Dump();
                        //string json = request.ToSafeJson();
                        //string strreq = request.SerializeToString();
                        string strMethod = request.Method;
                        string straddress = request.Address.ToString();
                        ERP.LogString("Request ", "Method : " + strMethod + " Address: " + straddress);

                       

                    };
                }

                //{
                //    //string strresp = response.SerializeToString();
                //    //using (var stream = request.GetRequestStream())
                //    //using (var sr = new StreamReader(stream))
                //    //{
                //    //    var text = sr.ReadToEnd();

                //    //}
                //};
                if (bool.Parse(ConfigManager().GetString("LogResponses")))
                {
                    client.ResponseFilter = response =>
                    {

                        string strStatusCode = response.StatusDescription;
                        //string strresp = response.SerializeToString();
                        string straddress = response.ResponseUri.ToString();
                        ERP.LogString("Response ", "Status Code : " + strStatusCode + " Address: " + straddress);
                        //using (var stream = response.GetResponseStream())
                        //using (var sr = new StreamReader(stream))
                        //{
                        //    var text = sr.ReadToEnd();

                        //}
                    };
                }



                //client.Headers.Add("Authorization", "BearerAPI KEy goes here");
                //return client;
                if (LoggedIn)
                {
                    var authResponse = client.Send<ServiceStack.AuthenticateResponse>(new ServiceStack.Authenticate()
                    {
                        provider = "credentials",

                        UserName = ConfigManager().GetString("JiwaAPIUser"),
                        Password = ConfigManager().GetString("JiwaAPIPassword"),
                        RememberMe = true
                    });
                }
                return client;

            }
            catch (Exception ex)
            {
                string error = ex.Message;
                return null;
            }
        }



and the routine that calls the request is

Code: Select all
public static  List<Note> GetJiwaAPIDebtorNotes(JsonServiceClient inClient = null, string DebtorID = "")
        {
            string methodName = MethodBase.GetCurrentMethod().Name;
            string className = "ERP";
            ERP.LogString("User: " + ERP.GetUser().UserLogString(), "Class : " + className + " Method: " + methodName);

            List<Note> result = new List<Note>();
            DebtorNotesGETManyRequest req = new DebtorNotesGETManyRequest();
            try
            {
                User user = GetUser();
                if (DebtorID == "")
                {
                    DebtorID = user.DebtorID;
                }
                req.DebtorID = DebtorID;

                JsonServiceClient client;
                bool nullclient = inClient == null;
                if (nullclient)
                {
                    client = GetAPIClient();
                }
                else
                {
                    client = inClient;
                }
                result = client.Get<List<Note>>(req);
                if (nullclient)
                {
                    Logout(client);
                }

            }
            catch (Exception ex)
            {
                result = new List<Note>();
            }
            return result;

        }



I can't actually send you the project as its fairly massive and is an upgrade of a current production system that was written about fifteen years ago. By the way GetAPIClient works with the API Key for other request just not the notes get many.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1617
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175


Return to REST API

Who is online

Users browsing this forum: No registered users and 1 guest

cron