? ? Pending

User tests: Successful: Unsuccessful:

avatar alikon
alikon
29 May 2021

Pull Request for Issue #34261 + #34269

Summary of Changes

fix PATCH
return the record in case of success
return a 404 in case of not found

Testing Instructions

see #34261

PATCH an existing article
PATCH an unexisting article

Actual result BEFORE applying this Pull Request

you must add title and category_id to change only 1 field

Expected result AFTER applying this Pull Request

you can PATCH the fields in the body request

Documentation Changes Required

avatar alikon alikon - open - 29 May 2021
avatar alikon alikon - change - 29 May 2021
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 29 May 2021
Category Libraries
avatar alikon alikon - change - 29 May 2021
Title
letsgo
[wip] letsgo
avatar alikon alikon - edited - 29 May 2021
avatar alikon alikon - change - 29 May 2021
Labels Added: ? ?
22539a1 29 May 2021 avatar alikon cs
avatar alikon alikon - change - 29 May 2021
Title
[wip] letsgo
[4][webservices] PATCH verb
avatar alikon alikon - edited - 29 May 2021
avatar pjdevries
pjdevries - comment - 29 May 2021

Like I proposed in issue #34261, I would prefer to incorporate this logic in the edit() as opposed to the save() method. After all, we only need it for PATCH requests. I would add the logic in a separate method, because I like modularity and keep the original method as clean as possible, and call it from the edit() method just before line https://github.com/joomla/joomla-cms/blob/4.0-dev/libraries/src/MVC/Controller/ApiController.php#L396.

Not critical but personal preferences :)

avatar pjdevries
pjdevries - comment - 29 May 2021

@alikon Not sure how you did it, but a PATCH request with patch-126 gives me a 404.

avatar pjdevries
pjdevries - comment - 29 May 2021

@alikon Not sure how you did it, but a PATCH request with patch-126 gives me a 404.

Silly me this time. patch-126 does not have the pluralised endpoints :)

avatar pjdevries
pjdevries - comment - 29 May 2021

Like I proposed in issue #34261, I would prefer to incorporate this logic in the edit() as opposed to the save() method.

This proves a bit more complicated than I imagined. Several api controllers override the save() method, setting the data input attribute. It is possible to supplement and overwrite the original raw json input data, but that feels like a bad idea.

So let's stick to the current implementation, as suggested by @joomdonation. I tested this PR and it does solve the PATCH validation issue.

avatar wilsonge
wilsonge - comment - 30 May 2021

This proves a bit more complicated than I imagined. Several api controllers override the save() method, setting the data input attribute. It is possible to supplement and overwrite the original raw json input data, but that feels like a bad idea.

I've fixed most of these in #34280 - just leaves the OverridesController which fully overrides this method.

I would prefer to incorporate this logic in the edit() as opposed to the save() method. After all, we only need it for PATCH requests

So I agree with this but like mentioned it's pretty hard because we don't actually grab any data in the edit method and like you say passing it around is tricky. However in the save method what we can and should do is check the request type (if $this->getInput()->getMethod() === 'PATCH') before we try and run any of this in save save function.

avatar alikon alikon - change - 30 May 2021
Labels Added: ?
Removed: ?
avatar alikon alikon - change - 30 May 2021
Labels Added: ?
Removed: ?
b56bd91 30 May 2021 avatar alikon cs
avatar alikon alikon - change - 30 May 2021
The description was changed
avatar alikon alikon - edited - 30 May 2021
avatar alikon
alikon - comment - 30 May 2021

request type check added

avatar pjdevries
pjdevries - comment - 30 May 2021

I tested the previously failing PATCH request and it now succeeds.

avatar joomdonation
joomdonation - comment - 30 May 2021

@pjdevries Could you please help testing to see with the PATCH request, tags data for article is kept or lost? I am asking for this because the tags data is not populated in $data array for our current code, so I'm worry that it might be lost (sorry I could not check it myself, too busy today)

avatar pjdevries
pjdevries - comment - 30 May 2021

@pjdevries Could you please help testing to see with the PATCH request, tags data for article is kept or lost? I am asking for this because the tags data is not populated in $data array for our current code, so I'm worry that it might be lost (sorry I could not check it myself, too busy today)

I'm not sure that's relevant for this issue. The problem here is unnecessary validation of otherwise required attributes. For articles those would be title and catid for instance. Validation of those is required for new articles, but not when using PATCH to change one or more not required attributes. So I think supplementing the request data just like we do know, solvers this problem. Since tags are not required attributes, I think there is no problem there.

avatar alikon alikon - change - 1 Jun 2021
Labels Added: ?
Removed: ?
avatar alikon alikon - change - 1 Jun 2021
The description was changed
avatar alikon alikon - edited - 1 Jun 2021
avatar alikon alikon - change - 4 Jun 2021
Labels Added: ?
Removed: ?
avatar wilsonge wilsonge - change - 4 Jun 2021
Status Pending Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2021-06-04 17:25:39
Closed_By wilsonge
Labels Added: ?
Removed: ?
avatar wilsonge wilsonge - close - 4 Jun 2021
avatar wilsonge wilsonge - merge - 4 Jun 2021
avatar wilsonge
wilsonge - comment - 4 Jun 2021

Thanks!

avatar marconte21870
marconte21870 - comment - 6 Jun 2021

The same error:"{"errors":[{"title":"Field required: Title\nField required: Category"}]}"
when i send curl for new article:
curl -X POST [myhttspsite]/joomla/api/index.php/v1/content/articles
-H "Content-Type: application/json"
-H "X-Joomla-Token: mytoken"
-d "{'alias': 'my-article','articletext': 'My text','catid':'2,'language': '*','metadesc': '','metakey': '','title': 'Here's an article'}"

avatar alikon
alikon - comment - 6 Jun 2021

double check the ' vs "
this work fine

'{"alias": "my-article","articletext": "My text","catid": 2,"language": "*","metadesc": "","metakey": "","title": "Here is an article"}'

plus this pr was for PATCH not for POST

avatar marconte21870
marconte21870 - comment - 6 Jun 2021

Thanks for the reply, I didn't find anything on POST, as it seemed like a similar error I thought you could help me; I changed 'VS "but nothing are two idays that I try by changing all the url parameters, I try with postman with php file but nothing

avatar alikon
alikon - comment - 6 Jun 2021
`curl --location --request POST 'http://[yoursite]/api/index.php/v1/content/articles' \
--header 'Content-Type: application/json' \
--header 'X-Joomla-Token:  [yourtoken]' \
--data-raw '{"alias": "my-article-test","articletext": "My test text","catid": 2,"language": "*","metadesc": "","metakey": "","title": "Here is my test article"}'`

just exported from postam

avatar marconte21870
marconte21870 - comment - 6 Jun 2021

I solved with your advice, it works but on postman it does not work, it is not important postman but it is important that it works on php and my n8n platform,
a sincere thank you

Add a Comment

Login with GitHub to post a comment