API Key Error  Topic is solved

Discussions relating to the REST API of Jiwa 7.

API Key Error

Postby SBarnes » Tue Jan 07, 2020 2:27 pm

Hi

https://api.jiwa.com.au/Queries/DB_Main ... uE-M8gBlA8

is producing the following error, our development server is getting the same response, how do we fix this?

In addition to this new custom route that is supposed to operate off a debtor api key is producing a screen asking for a Jiwa user name and password to login, saying that it needs to be authenticated?

Code: Select all
Response Status
Error CodeAggregateExceptionMessageOne or more errors occurred.Stack Traceat System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification) at System.Threading.Tasks.Task`1.get_Result() at JiwaFinancials.Jiwa.JiwaServiceModel.JiwaApiKeyAuthProvider.Authenticate(IServiceBase authService, IAuthSession session, Authenticate request) in c:\ProgramData\Jiwa Financials\Jiwa 7\7.2.1\SYSTEM\JiwaSupportSQL3\ApiJiwaComAu\Plugins\Admin\Compile\REST API\REST API.cs:line 3039 at ServiceStack.Auth.AuthenticateService.Authenticate(Authenticate request, String provider, IAuthSession session, IAuthProvider oAuthConfig) at ServiceStack.Auth.AuthenticateService.Post(Authenticate request) at JiwaFinancials.Jiwa.JiwaServiceModel.JiwaApiKeyAuthProvider.PreAuthenticateWithApiKey(IRequest req, IResponse res, v_APIKey apiKey) in c:\ProgramData\Jiwa Financials\Jiwa 7\7.2.1\SYSTEM\JiwaSupportSQL3\ApiJiwaComAu\Plugins\Admin\Compile\REST API\REST API.cs:line 3141 at JiwaFinancials.Jiwa.JiwaServiceModel.JiwaApiKeyAuthProvider.PreAuthenticate(IRequest req, IResponse res) in c:\ProgramData\Jiwa Financials\Jiwa 7\7.2.1\SYSTEM\JiwaSupportSQL3\ApiJiwaComAu\Plugins\Admin\Compile\REST API\REST API.cs:line 3088 at ServiceStack.AuthenticateAttribute.PreAuthenticate(IRequest req, IEnumerable`1 authProviders) at ServiceStack.AuthenticateAttribute.<ExecuteAsync>d__12.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at ServiceStack.ServiceStackHost.<ApplyRequestFiltersSingleAsync>d__317.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at ServiceStack.ServiceStackHost.<ApplyRequestFiltersAsync>d__316.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at ServiceStack.Host.RestHandler.<ProcessRequestAsync>d__14.MoveNext()
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: API Key Error

Postby SBarnes » Tue Jan 07, 2020 3:43 pm

Further to this on the custom route it's actually the following line that is producing the error

Code: Select all
await manager.LogonAsync(StartupManager.Database.ServerName, StartupManager.Database.DatabaseName, apiKey.KeyValue);

and the inner exception in the debugger is

Code: Select all
Inner Exception 1:
InvalidCastException: Specified cast is not valid.


But using a staff api key for admin gets inside the code of a custom route which then catches the error that the api key is of the wrong type.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: API Key Error

Postby Mike.Sheen » Sun Jan 12, 2020 8:00 pm

Odd... I just restarted the service at https://api.jiwa.com.au/ and now that query works - I did get the same error as you reported before, however.

I shall look into it - but I'm keen to know if restarting it for you works also.
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: API Key Error

Postby SBarnes » Mon Jan 13, 2020 8:59 am

Hi Mike,

Restarting makes no difference the call works with a staff api key and crashes with a debtor api key, in fact you can run them simultaneously and get the same result.

Interestingly though if you give the api an invalid key you get 404 not found and not a 403 error about unauthorised
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: API Key Error

Postby Mike.Sheen » Mon Jan 13, 2020 3:54 pm

SBarnes wrote:Restarting makes no difference the call works with a staff api key and crashes with a debtor api key, in fact you can run them simultaneously and get the same result.


Debtor API key definitely was failing for me until I restarted the service on api.jiwa.com.au - I didn't test the staff API Key, but that is certainly working now - must be something different...

SBarnes wrote:Interestingly though if you give the api an invalid key you get 404 not found and not a 403 error about unauthorised


Are you getting that only through a browser, or are you also getting that when using code to call the API? I ask because if using a browser, by default we redirect you to a login page if you are unauthenticated and that error will occur if it cannot redirect to the login page.
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: API Key Error

Postby SBarnes » Mon Jan 13, 2020 8:12 pm

Hi Mike,

In a browser but if you go to the link without the api key it does redirect to the login page.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: API Key Error

Postby SBarnes » Tue Jan 14, 2020 4:26 pm

Is there any update on why the debtor api keys aren't working?
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: API Key Error

Postby Mike.Sheen » Tue Jan 14, 2020 4:31 pm

SBarnes wrote:Is there any update on why the debtor api keys aren't working?


No - I cannot reproduce the problem anymore. When you created this topic the link you provided which was failing (https://api.jiwa.com.au/Queries/DB_Main ... uE-M8gBlA8) I could see was throwing an exception, but after restarting the service it worked and is still working now.

Can you test with it configured to point to a demo database and see if you still have the error? If you don't then it might be a plugin perhaps causing the problem.
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: API Key Error

Postby SBarnes » Tue Jan 14, 2020 5:33 pm

Hi Mike,

You were right and wrong at the same time, its not the database its the debtor, if I change the debtor it works. I will email you the xml for the debtor which might give you some idea.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: API Key Error

Postby Mike.Sheen » Wed Jan 15, 2020 8:58 am

SBarnes wrote:Hi Mike,

You were right and wrong at the same time, its not the database its the debtor, if I change the debtor it works. I will email you the xml for the debtor which might give you some idea.


Nothing about that debtor record appears to be the cause... but it's impossible to know for sure because there are references to other data I don't have - such as the custom fields originating from plugins I don't have.

The best way to solve this one is to provide a database - instructions on how to FTP it to us can be found here.

When that's uploaded, create a helpdesk ticket with the steps we need to take to repro and I'll pick it up from there.
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

Next

Return to REST API

Who is online

Users browsing this forum: No registered users and 2 guests

cron