User tests: Successful: Unsuccessful:
Pull Request for Issue #34261 + #34269
fix PATCH
return the record in case of success
return a 404 in case of not found
see #34261
PATCH an existing article
PATCH an unexisting article
you must add title and category_id to change only 1 field
you can PATCH the fields in the body request
Status | New | ⇒ | Pending |
Category | ⇒ | Libraries |
Title |
|
Labels |
Added:
?
?
|
Title |
|
Like I proposed in issue #34261, I would prefer to incorporate this logic in the
edit()
as opposed to thesave()
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.
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.
Labels |
Added:
?
Removed: ? |
Labels |
Added:
?
Removed: ? |
request type check added
I tested the previously failing PATCH
request and it now succeeds.
@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)
@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.
Labels |
Added:
?
Removed: ? |
Labels |
Added:
?
Removed: ? |
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: ? |
Thanks!
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'}"
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
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
`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
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
Like I proposed in issue #34261, I would prefer to incorporate this logic in the
edit()
as opposed to thesave()
method. After all, we only need it forPATCH
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 theedit()
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 :)