Opened 10 years ago
Closed 10 years ago
#39466 closed defect (bug) (fixed)
Get list of post API request missing status
| Reported by: | gnanasekaran | Owned by: | jnylen0 |
|---|---|---|---|
| Priority: | normal | Milestone: | 4.7.3 |
| Component: | REST API | Version: | 4.7 |
| Severity: | normal | Keywords: | has-patch has-unit-tests fixed-major |
| Cc: | Focuses: | rest-api |
Description (last modified by )
when send "get posts" request, status ($data['status']) is missing by default. I did not get "status" in response.
For below request
Definition
GET /wp/v2/posts/
Example Request
Attachments (4)
Change History (24)
#2
follow-up:
↓ 3
@
10 years ago
- Description modified (diff)
- Keywords needs-patch needs-unit-tests added
- Milestone Awaiting Review → 4.7.2
We do only show the status in context=edit (ref).
This has been reported at least one other time in testing. I think it's a bit silly not to include status: we support querying for a post status unauthenticated, even if just for the default status of publish (ref) or inherit for attachments (ref).
Another status-related issue: It's not possible to query posts with the inherit status unauthenticated. But, it looks like they may show up in /wp/v2/posts if read permission is otherwise allowed. Needs some testing.
#3
in reply to: ↑ 2
@
10 years ago
Replying to jnylen0:
I think it's a bit silly not to include
status: we support querying for a post status unauthenticated, even if just for the default status ofpublish(ref) orinheritfor attachments (ref).
FWIW, this has been the case since this commit. Not sure why we made the decision then, but it does somewhat make sense to add this to the view context, if only to distinguish between publish and inherit (although inherit isn't actually allowed in WP on anything except attachment, to my knowledge).
This ticket was mentioned in Slack in #core by jnylen. View the logs.
10 years ago
This ticket was mentioned in Slack in #forums by jnylen. View the logs.
10 years ago
#7
@
10 years ago
@rachelbaker committed this https://github.com/WP-API/WP-API/commit/69f617d749e4f165b9e31c1c042eec45ade3e41f one. Can we get some suggestion from @rachelbaker before deciding something?
This ticket was mentioned in Slack in #core-restapi by kadamwhite. View the logs.
10 years ago
#9
@
10 years ago
@dhanendran I honestly don't remember the logic for moving status to the edit context. Only one that comes to mind is that the status/visibility of a resource is rarely exposed publically.
However, in v1 of the REST API we did expose post_status for all contexts: https://github.com/WP-API/WP-API/blob/master/lib/class-wp-json-posts.php#L556
I do not have a strong opinion here one way or another.
#10
follow-up:
↓ 11
@
10 years ago
Status has a small set of possible values that can be filtered publicly, so this parameter is effectively already public (exposing it provides no new information that can't already be obtained elsewhere).
#11
in reply to: ↑ 10
@
10 years ago
@rachelbaker @jnylen0 Thanks for your input.
Status has a small set of possible values that can be filtered publicly, so this parameter is effectively already public (exposing it provides no new information that can't already be obtained elsewhere).
Yes I do agree with this.
This ticket was mentioned in Slack in #core by jeffpaul. View the logs.
10 years ago
#13
@
10 years ago
- Keywords has-patch added; needs-patch removed
- Owner set to
- Status new → accepted
- Version 4.6.1 → 4.7
@dhanendran: can you update the test suite for this change, including a new test if needed? See: https://make.wordpress.org/core/handbook/testing/automated-testing/phpunit/
This ticket was mentioned in Slack in #core-restapi by adamsilverstein. View the logs.
10 years ago
#15
@
10 years ago
- Keywords has-unit-tests added; needs-unit-tests removed
@jnylen0 I have added the unit test case for this fix.
#16
@
10 years ago
@dhanendran I'd prefer to test the actual response coming from the API endpoint, as in 39466.2.diff.
I think this is good to go for 4.7.3. I'll wait a couple more days before committing to give others a chance to review.
#17
@
10 years ago
- Keywords commit added; good-first-bug removed
@jnylen0 Your 39466.2.diff looked good, just was missing an updated schema file for the qunit tests. I added this in 39466.3.diff.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
I'm on the go and haven't perused the code so this is just a shot in the dark, but most statuses require authentication to access -- it's possible that the status you're requesting is being overwritten because only "publish" is available to unauthenticated users. I'd suggest making the request with an authenticated JavaScript client from within the admin, or installing one of the authentication plugins if you want to use curl, and seeing if that resolves the issue; my hunch is that this is a docs problem more than it is a code problem.