1

I'm planning a series of APIs to execute in a Joomla instance to provide data to other sites. Experiments ongoing to understand how to implement. Considering com_ajax, com_api or new component. Initially working with com_api from TechJoomla.com. Using their 'articles' plugin to provide response data.

Tests to retrieve an article using the browser command line request of 'http://127.0.0.1/site/index.php?option=com_api&app=articles&resource=article&format=raw&id=394' successful. The article's data is received in json format as expected.

Tests using cURL to initiate the request fail. Using the new Windows 10 cURL so I have to submit using POST request. Command is 'curl -d option=com_api -d app=articles -d resource=article -d format=raw -d id=394 http://127.0.0.1/site/index.php?'. The com_api returns the often seen '404 - Controller Not Found' error.

Tracing has found several facts:

  • Correct Query parameters are received by Joomla in both tests. The browser request places them in the PHP REQUEST array. The cURL request places them in the POST array in addition to REQUEST.
  • Query parameters (in the APP->input object) available at the beginning of com_api/api.php are modified. The view=article and itemid=nnn (nnn = index of home page menu) parameters are added.
  • Failure is at line ~50 of com_api/api.php due to the 'view' parameter being set. Code then attempts to access 'C:\Users\joesboat\websites\USPSd5/components/com_api/controllers/article.php'. File does not exist.

Please help. Why is Joomla adding query parameters. All documents found indicate the routing is supposed to pass parameters as received to the components. Thanks in advance..

3
  • I'm not familiar with com_api but it looks as if it's handling POST requests different from GET requests. Can you not just send a GET request with curl? I see that recent Windows versions now have the proper curl, rather than a pretend lookalike, so you shouldn't have problems with that. You will get Joomla input parameters eg Itemid added when Joomla routes the incoming request. Itemid will point to the closest matching menuitem, and if view is not in the received parameters then it's (probably) set to the view associated with that menuitem. Apr 20 '20 at 18:14
  • cURL was only sending one parameter from the GET request string. Thus I switched to using the POST and encountered the issue. Later I found a cURL technique to package everything as a GET. This allows some progress, but the question on why the router is adding parameters when a POST is used and not adding them for a GET remains....
    – joesboat
    Apr 20 '20 at 21:51
  • Try putting the URL inside double quotes, ie curl "127.0.0.1/site/…" Apr 20 '20 at 21:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.