Using the Webservices API to read an article Topic is solved

For Joomla! 5.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
davidascher
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 143
Joined: Tue Feb 28, 2006 3:23 pm

Re: Using the Webservices API to read an article

Post by davidascher » Tue Apr 16, 2024 12:21 pm

Thank you both - SharkyKZ and Victor- for all your help. I would have been banging my head against the wall forever without your helpful suggestions and solid information.

User avatar
Kubik-Rubik
Joomla! Explorer
Joomla! Explorer
Posts: 272
Joined: Wed Aug 25, 2010 1:59 pm
Location: Karlsruhe - Germany
Contact:

Re: Using the Webservices API to read an article

Post by Kubik-Rubik » Tue Apr 16, 2024 1:06 pm

You are welcome, David!
Cheers
Viktor

Kubik-Rubik Joomla! Extensions https://kubik-rubik.de
Former member of Joomla! Production Leadership Team, Security Strike Team and Bug Squash Team

davidascher
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 143
Joined: Tue Feb 28, 2006 3:23 pm

Re: Using the Webservices API to read an article

Post by davidascher » Wed Apr 17, 2024 8:14 pm

Kubik-Rubik wrote:
Mon Apr 15, 2024 2:26 pm
You are welcome!

For the alias, you may use the normal search filter:

Code: Select all

DOMAIN/api/index.php/v1/content/articles?filter[search]=newsletters
How should I deal with a search string like '<ul id="newsletters_list">' ??
I'm guessing that I need to do some substitution for the double quotes and/or spaces for this to have a chance to work.
I'm doing this (still) without using the Joomla Framework - just php and curl.

I hope your reply will be useful to other people who struggle to decode the mysteries of Joomla Webservices.
thank you in advance.

User avatar
Kubik-Rubik
Joomla! Explorer
Joomla! Explorer
Posts: 272
Joined: Wed Aug 25, 2010 1:59 pm
Location: Karlsruhe - Germany
Contact:

Re: Using the Webservices API to read an article

Post by Kubik-Rubik » Wed Apr 17, 2024 9:34 pm

Hey David,

You cannot search for HTML code parts since the search string is cleaned with the STRING filter (HTML tags are removed).

If you really need to search for HTML code, you must do a small core hack to set the filter to RAW instead of STRING. But remember that the change is not update-safe, and you must reapply it after the next core update!

Open: api/components/com_content/src/Controller/ArticlesController.php

Search:

Code: Select all

$this->modelState->set('filter.search', $filter->clean($apiFilterInfo['search'], 'STRING'));
Change to:

Code: Select all

$this->modelState->set('filter.search', $filter->clean($apiFilterInfo['search'], 'RAW'));
Now you can trigger your API call like:

Code: Select all

DOMAIN/api/index.php/v1/content/articles?filter[search]=content:<ul id="newsletters_list">
Have success!
Cheers
Viktor

Kubik-Rubik Joomla! Extensions https://kubik-rubik.de
Former member of Joomla! Production Leadership Team, Security Strike Team and Bug Squash Team

davidascher
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 143
Joined: Tue Feb 28, 2006 3:23 pm

Re: Using the Webservices API to read an article

Post by davidascher » Wed Apr 17, 2024 10:23 pm

That sounds sort of reasonable but when I am on the site backend and search articles for
CONTENT:<ul id="newsletters_list">
using Chrome on Windows, I get back the article I wanted - that has a ul element with id="newsletters_list". This would appear to contradict what you say is the behavior.

However, when I try the same thing using Chrome on my Android device - or even CONTENT:id="newsletters_list" - no articles are returned.

I am confused (again) as to
a) why "You cannot search for HTML code parts since the search string is cleaned with the STRING filter (HTML tags are removed)." What's the reasoning behind the removal of HTML tags?
b) why the behavior of the search would be different between Chrome on Android and Chrome on Windows.
c) how could this search work when I am using Windows if the HTML tags are removed?

I suppose I could get around this by adding an element with a special string that is not displayed using "display:none" and searching for that.

Are there plans afoot for a 2nd version of Joomla Webservices?

User avatar
Kubik-Rubik
Joomla! Explorer
Joomla! Explorer
Posts: 272
Joined: Wed Aug 25, 2010 1:59 pm
Location: Karlsruhe - Germany
Contact:

Re: Using the Webservices API to read an article

Post by Kubik-Rubik » Thu Apr 18, 2024 7:46 am

The search in the UI does not apply the STRING filter to the search input field, but the API request does. This is why you can also search for HTML tags in the UI while being signed in to the backend. This is entirely independent of the browser or operating system.

Please ask your questions for more detailed answers from the Joomla! team in the official Joomla! Issue Tracker (since I'm no maintainer in the project anymore) or propose some changes to the current API implementation to allow the full text content search with the entire HTML structure: https://issues.joomla.org/

Have success!
Cheers
Viktor

Kubik-Rubik Joomla! Extensions https://kubik-rubik.de
Former member of Joomla! Production Leadership Team, Security Strike Team and Bug Squash Team


Post Reply

Return to “Joomla! 5.x Coding”