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

Specifying "fields" in a GET request to /posts is broken #9763

Closed
john-mcgowan1992 opened this issue Jul 31, 2018 · 4 comments
Closed

Specifying "fields" in a GET request to /posts is broken #9763

john-mcgowan1992 opened this issue Jul 31, 2018 · 4 comments
Assignees

Comments

@john-mcgowan1992
Copy link

When making a request with fields specified in the query string, the request fails.

Request.get('https://www.yourdomain.com/ghost/api/v0.1/posts/', {
           qs: {
               client_secret: ghostClientSecret,
               client_id: ghostClientId,
               filter: 'tag:-press,featured:true',
               fields: '[id,slug]'
           }
       })

with the following error:

{"errors":[{"message":"select `id`, `slug`, `published_at`, `author_id` from `posts` left outer join `posts_tags` on `posts_tags`.`post_id` = `posts`.`id` left outer join `tags` on `posts_tags`.`tag_id` = `tags`.`id` where (`posts`.`status` = \'published\' and `posts`.`page` = false) and (`tags`.`slug` != \'press\' or `posts`.`featured` = true) group by `posts`.`id` order by CASE WHEN posts.status = \'scheduled\' THEN 1 WHEN posts.status = \'draft\' THEN 2 ELSE 3 END ASC,posts.published_at DESC,posts.updated_at DESC,posts.id DESC limit 15 - ER_NON_UNIQ_ERROR: Column \'id\' in field list is ambiguous","errorType":"InternalServerError"}]}

I'm using request-promise in node

@kevinansfield
Copy link
Contributor

@john-mcgowan1992 I think you may need to use fields: 'post.id,post.slug' but I may be wrong.

@kirrg001 should this be handled automatically?

@kirrg001
Copy link
Contributor

kirrg001 commented Aug 1, 2018

See #8649.

@kevinansfield
Copy link
Contributor

Closing as a duplicate of #8649, #5604, #5615. There's on-going work on the underlying GQL library that will either resolve this or put us in a position where it can be resolved.

@john-mcgowan1992 for now the recommendation is to not use fields with the filter param.

@john-mcgowan1992
Copy link
Author

@kevinansfield apologies for the duplicate. One more quick question, and I was unable to find a ticket for this after doing a quick search. Is there also a known issue when combining fields and include in the same query? I also tried the following query string to no avail:

          qs: {
               client_secret: ghostClientSecret,
               client_id: ghostClientId,
               fields: '[id,slug]',
               include: 'tags'
           }

Basically, I need a way to query the slug and id of my posts and then filter them by tag. Given the previously mentioned tickets, the only other way is to do the filtering on the client side. However, the above query only returns the id and slug, leaving out the tags. This leaves me with the only option of querying the entire post object in order to filter down these properties, which is overkill. Anyway, I understand you guys have your hands full. Just wanted to check if combining fields and include is also a no op

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants