Calling api.php?action=search

In this board you can talk about general questions about phpMyFAQ

Moderator: Thorsten

Post Reply
KT_
Posts: 24
Joined: Tue Nov 21, 2017 5:28 pm

Calling api.php?action=search

Post by KT_ »

I used to (on a 2.9 installation) be able to get a JSON response of search results using the Perl code:

Code: Select all

my $query = $cgi->param('q');
my $query_decoded = uri_decode($query);
my $ua = LWP::UserAgent->new;
my $response = $ua->get("https://mysite.com/kb/api.php?action=search&lang=en&q=$query");
my $results = decode_json($response->content);
Now, however, I receive either an empty result ([]) or a 404 error. (Looks like the 404 error is returned in api.php for an empty "search" action.)

However, pasting

Code: Select all

https://mysite.com/kb/api.php?action=search&lang=en&q=searchterm
into a browser will return JSON with the results for searchterm. But trying to use wget with that exact URL, from a shell prompt logged in to the server, gives me the same 404.

There's some configuration error, it seems, that's somehow getting the way.

Am I (still) supposed to be able to do this? I just want to get the raw search results so that I can format them.
KT_
Posts: 24
Joined: Tue Nov 21, 2017 5:28 pm

Re: Calling api.php?action=search

Post by KT_ »

Actually a correction: that wget line gives me a 500 internal server error.

But if I try either the Perl script or the wget line with kb-old/api.php instead of kb/api.php (to use my old 2.9 phpMyFaq installation) both work just fine.
KT_
Posts: 24
Joined: Tue Nov 21, 2017 5:28 pm

Re: Calling api.php?action=search

Post by KT_ »

To follow up further, it seems like this change to api.php:154 fixes it:

Code: Select all

$searchResults = $search->search($searchString, true); //false);
I assume something about default language handling has changed somewhere?
Thorsten
Posts: 15560
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Re: Calling api.php?action=search

Post by Thorsten »

Hi,

I assume you're on v3.1 now, the API changed in 3.0 and was improved with 3.1.

You can find the API documentation here: https://github.com/thorsten/phpMyFAQ/blob/3.1/API.md

Nevertheless, a 500 should not happen, I'll check this issue.

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
Post Reply