Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"url" field is undefined when restricting returned fields via the API #6625

Closed
Windyo opened this issue Mar 22, 2016 · 6 comments
Closed

"url" field is undefined when restricting returned fields via the API #6625

Windyo opened this issue Mar 22, 2016 · 6 comments
Assignees
Labels
affects:api Affects the Ghost API bug [triage] something behaving unexpectedly

Comments

@Windyo
Copy link

Windyo commented Mar 22, 2016

Issue Summary

When querying a posts list with the API, the "url" field returns "undefined" if the fields to be returned have been specified.

Interestingly, if one wants to construct a full list of post urls with no further information, a list of all fields except the url is returned.

Steps to Reproduce

This first query returns a list of all posts with all their fields.

$.get(ghost.url.api('posts', {limit: "all"})).done(function(data) {
    var allposts = data.posts;
    console.log(allposts);
})

The following query, which should return exactly the same thing, returns all fields except "url" and "author".

$.get(ghost.url.api('posts', {limit: "all", fields: "id,uuid,title,slug,markdown,html,image,featured,page,status,language,meta_title,meta_description,created_at,created_by,updated_at,updated_by,published_at,published_by,author,url"})).done(function(data) {
    var allfields = data.posts;
    console.log(allfields);
})

The "author" can be added by using "include: "author", so this may be a feature and not a bug.
Using the syntax author_id also returns the expected result.

To test what happens if a list of URLs needs to be generated, the following query can be used :

$.get(ghost.url.api('posts', {limit: "all", fields: "url"})).done(function(data) {
    var urlquery = data.posts;
    console.log(urlquery);
})

Technical details:

  • Ghost Version: 0.7.8
  • Node Version: 2.14.7
  • Browser/OS: all tested.
  • Database: sqlite3
@ErisDS ErisDS added bug [triage] something behaving unexpectedly affects:api Affects the Ghost API labels Mar 22, 2016
@Windyo
Copy link
Author

Windyo commented Apr 12, 2016

Hi @jaswilli, thanks for taking a look at this!

Seeing as you committed yesterday, I take it that if I install the latest master I should be able to finish up testing and close the issue?

Thanks

@jaswilli
Copy link
Contributor

Hi @Windyo,

The fix won't be in the master branch until #6657 gets merged.

@ErisDS
Copy link
Member

ErisDS commented May 18, 2016

I'm reopening this as I've just spotted it is not fixed / has regressed.

E.g:

adding ?fields=url to an API request seems to have no effect
adding ?fields=title,url to an API request results in this (using blog.ghost.org as an example here):

{"posts":[{
  "title":"It's our birthday! Three years down, $600,000 annual revenue, and what's coming next",
  "url":"/undefined/"
}]...

@kirrg001
Copy link
Contributor

I am not able to reproduce this bug on current master. I've tested with postman and test-wise.
When i did it test-wise, i got "url":"/undefined/", but this was a problem from test setup.

@ErisDS
Copy link
Member

ErisDS commented Jul 14, 2016

I reproduced the two bugs on latest master by grabbing the access token and making a get request with the browser like:

http://localhost:2368/ghost/api/v0.1/posts/?fields=url&access_token=<access_token>

Bug 1: The above request results in all fields still being returned, the fields parameter has no effect in this case.

http://localhost:2368/ghost/api/v0.1/posts/?fields=title,url&access_token=<access_token>

Bug 2: the above request results in only the 2 fields specified being returned, but the URL is always "/undefined/". Also if I turn on dated permalinks in settings, then the URL is always something like "/2016/07/14/undefined/"

@kirrg001
Copy link
Contributor

kirrg001 commented Jul 14, 2016

Thanks @ErisDS , will try later again and then review #7089
see #7089 (comment)

kirrg001 pushed a commit that referenced this issue Jul 18, 2016
closes #6625

- "url" and "author" fields depend on {id, published_at, slug, author_id} to construct post url.
- implemented a generic solution by defining defaultColumnsToFetch() in
  base class for models.
- findPage() calls defaultColumnsToFetch() before loading models
- results are transformed by filtering out additional properties to return just the requested fields
- Added a test case to check for url and author fields
- Renamed allColumns as requestedColumns and used _.map instead of Promise.map
chris-brown pushed a commit to chris-brown/Ghost that referenced this issue Aug 14, 2016
…ost#7089)

closes TryGhost#6625

- "url" and "author" fields depend on {id, published_at, slug, author_id} to construct post url.
- implemented a generic solution by defining defaultColumnsToFetch() in
  base class for models.
- findPage() calls defaultColumnsToFetch() before loading models
- results are transformed by filtering out additional properties to return just the requested fields
- Added a test case to check for url and author fields
- Renamed allColumns as requestedColumns and used _.map instead of Promise.map
geekhuyang pushed a commit to geekhuyang/Ghost that referenced this issue Nov 20, 2016
Closes TryGhost#6625
- Adds a failing test for not returning computed columns as well
  as for the bookshelf bug where extra columns passed into a fetch
  will result in the model having an extra "quoted" column.
- Filter model attributes for passing into "fetch" but used the
  entire list of columns for `toJSON`.
geekhuyang pushed a commit to geekhuyang/Ghost that referenced this issue Nov 20, 2016
…ost#7089)

closes TryGhost#6625

- "url" and "author" fields depend on {id, published_at, slug, author_id} to construct post url.
- implemented a generic solution by defining defaultColumnsToFetch() in
  base class for models.
- findPage() calls defaultColumnsToFetch() before loading models
- results are transformed by filtering out additional properties to return just the requested fields
- Added a test case to check for url and author fields
- Renamed allColumns as requestedColumns and used _.map instead of Promise.map
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects:api Affects the Ghost API bug [triage] something behaving unexpectedly
Projects
None yet
Development

No branches or pull requests

5 participants