API plugin using SQL LIKE query returns error  Topic is solved

Discussions relating to Jiwa 7 plugin development, and the Jiwa 7 API.

Re: API plugin using SQL LIKE query returns error

Postby JuiceyBrucey » Mon Mar 29, 2021 5:34 pm

so are you saying that my request URL should look something like this:
/Custom/GetInventoryItemsLikeNameRequest/?ItemName=GREY%20SUNFLOWER
JuiceyBrucey
Frequent Contributor
Frequent Contributor
 
Posts: 188
Joined: Tue Aug 18, 2020 7:19 pm
Topics Solved: 1

Re: API plugin using SQL LIKE query returns error

Postby Mike.Sheen » Mon Mar 29, 2021 5:40 pm

JuiceyBrucey wrote:so are you saying that my request URL should look something like this:
/Custom/GetInventoryItemsLikeNameRequest/?ItemName=GREY%20SUNFLOWER


Yes.

This will set the property ItemName in your request DTO (an instance of GetInventoryItemsLikeNameRequest) and that instance of GetInventoryItemsLikeNameRequest gets passed to the Get method.
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: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807

Re: API plugin using SQL LIKE query returns error

Postby JuiceyBrucey » Mon Mar 29, 2021 6:13 pm

So I tried this URL in testing:
http://localhost/Custom/GetInventoryIte ... mName=GREY SUNFLOWER
http://localhost/Custom/GetInventoryIte ... mName=GREY SUNFLOWER

With:
main.Description LIKE @ItemName
ORDER BY main.Description ;";
string sinput = "%" + request.ItemName + "%"; // note no single quotes surrounding wildcard string

And
main.Description LIKE @ItemName
ORDER BY main.Description ;";
string sinput = "''%" + request.ItemName + "%''"; // has single quotes surrounding wildcard string

But I am getting error:
HTTP Error 400. The request is badly formed.
JuiceyBrucey
Frequent Contributor
Frequent Contributor
 
Posts: 188
Joined: Tue Aug 18, 2020 7:19 pm
Topics Solved: 1

Re: API plugin using SQL LIKE query returns error

Postby Mike.Sheen » Mon Mar 29, 2021 6:16 pm

Ok, so can you use SQL Profiler to capture the actual SQL query being issued?

If that query isn't being reached, or if it is and you find copying and pasting the query into Query Analyzer yields no problem when run, then try temporarily paring back the query to be just an equality instead of LIKE.
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: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807

Re: API plugin using SQL LIKE query returns error

Postby SBarnes » Mon Mar 29, 2021 6:20 pm

Shouldn't http://localhost/Custom/GetInventoryIte ... mName=GREY SUNFLOWER be http://localhost/Custom/GetInventoryIte ... mName=GREY%20SUNFLOWER ?

Edit I tested two words in the swagger ui this morning and it worked.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191

Re: API plugin using SQL LIKE query returns error

Postby SBarnes » Mon Mar 29, 2021 6:29 pm

Swagger just sent this for network server

Code: Select all
http://localhost:81/Custom/PostInventoryItemsLikeNameRequest/?ItemName=network%20server


which produces results.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191

Re: API plugin using SQL LIKE query returns error

Postby JuiceyBrucey » Mon Mar 29, 2021 6:37 pm

(SBarnes)
I have tried using URL encode so that a space becomes %20, and instead of two words, I just used one to see if this was an issue. I got the same result.
It has worked many times and with many variations in the Swagger, but then when I do the real thing, I get errors. Is this normal?

(Mike.Sheen)
I have tried this a few different ways and still the same result. I even hard coded in the string that I was searching for direct into the SQL using ='GREY' and still got an error.
I will give it another shot and see how I go. I will try the hard coded version first.
First up:
WHERE
main.Description='GREY'

Then:
WHERE
main.Description LIKE '%GREY%'

I have already tried this, but maybe something was missing. I will try again.
Thanks for you help guys.
Cheers
JuiceyBrucey
Frequent Contributor
Frequent Contributor
 
Posts: 188
Joined: Tue Aug 18, 2020 7:19 pm
Topics Solved: 1

Re: API plugin using SQL LIKE query returns error

Postby Mike.Sheen » Mon Mar 29, 2021 6:42 pm

JuiceyBrucey wrote:It has worked many times and with many variations in the Swagger, but then when I do the real thing, I get errors. Is this normal?


No, not normal... but what do you mean "when I do the real thing"? How are you performing the GET which produces the error?

If it doesn't happen in the Swagger UI, then it's a fair indication that the error reported "HTTP Error 400. The request is badly formed." is telling you what the problem is.

If you don't already, in Jiwa set "Debug Mode" to on for the REST API system settings and have a look at the log of the requests - should given you a clue. Also Postman I found is a good tool for testing out the API - try it in Postman and see if you get the same 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: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807

Re: API plugin using SQL LIKE query returns error

Postby JuiceyBrucey » Mon Mar 29, 2021 6:45 pm

So this:
WHERE
main.Description='GREY'
ORDER BY main.Description

Using this URL, even though the string is hard coded direct into the SQL:
http://localhost/Custom/GetInventoryIte ... mName=GREY

Yielded:
404 Handler for Request not found

In the above example, Is it possible that the plugin is not working because variables are declared but not utilised?
string sinput = "'%" + request.ItemName + "%'";
And
new {ItemName = sinput}
JuiceyBrucey
Frequent Contributor
Frequent Contributor
 
Posts: 188
Joined: Tue Aug 18, 2020 7:19 pm
Topics Solved: 1

Re: API plugin using SQL LIKE query returns error

Postby JuiceyBrucey » Mon Mar 29, 2021 6:55 pm

Mike.Sheen wrote:
JuiceyBrucey wrote:It has worked many times and with many variations in the Swagger, but then when I do the real thing, I get errors. Is this normal?


No, not normal... but what do you mean "when I do the real thing"? How are you performing the GET which produces the error?

If it doesn't happen in the Swagger UI, then it's a fair indication that the error reported "HTTP Error 400. The request is badly formed." is telling you what the problem is.

If you don't already, in Jiwa set "Debug Mode" to on for the REST API system settings and have a look at the log of the requests - should given you a clue. Also Postman I found is a good tool for testing out the API - try it in Postman and see if you get the same problem.


"No, not normal... but what do you mean "when I do the real thing"? How are you performing the GET which produces the error?"
I am using CURL do this. I have made a class with automatically authenticates. I have made several plugins now all of which use this class to authenticate, and using the same CURL settings.
All of the other ones work perfectly, but this one does not want to play ball.
I have set the API to debug mode. Not sure where to see the logs, where is that?
Cheers
JuiceyBrucey
Frequent Contributor
Frequent Contributor
 
Posts: 188
Joined: Tue Aug 18, 2020 7:19 pm
Topics Solved: 1

PreviousNext

Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 1 guest