question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

API accepts non-ObjectID id's when creating posts

See original GitHub issue

Issue Summary

It’s possible to POST to the /posts/ endpoint including a numeric id attribute which is successfully saved to the database. When later trying to edit that post the server raises a 422 ValidationError with the message:

Saving failed: Validation (matches) failed for id

Steps to Reproduce

  1. Use Postman or similar to send a POST /posts/ request with a numeric ID property in the post’s JSON
  2. Open the new post in the admin area’s editor
  3. Attempt to save it

We should be ignoring (ideally) or at least validating ID attributes when creating posts via the API.

Technical details:

  • Ghost Version: 1.11.0

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
mdornseifcommented, Oct 4, 2017

I would suggest that forbidding is better than ignoring. So better send an 400 Bad Request (or 422) status back then silently drop the parameter.

1reaction
nazcommented, Feb 13, 2019

With JSON Schema validations landing in master for posts and tags Admin API endpoints, id fields are now stripped from the input and ignored during validation phase 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTTP REST API and Examples — Cordra documentation
The server will only accept POST and PUT requests for objects that conform to the schema corresponding to the object type; other requests...
Read more >
How to construct a REST API that takes an array of id's for the ...
println("zrssIds = " + Ids); //Here you need to use String tokenizer to make the array from the string. } Call the service...
Read more >
Designing APIs for humans: Object IDs - DEV Community ‍ ‍
When designing your table, you want a system where your IDs are easy to generate, unique and human readable. The most simplistic approach...
Read more >
REST api that accepts a list of IDS - Google Groups
Hi All,. I have a requirement where I need to implement a GET API with an array of IDs as input. since this...
Read more >
Posts | REST API Handbook - WordPress Developer Resources
Schema The schema defines all the fields that exist within a post record. ... Create a Post ... object, The globally unique identifier...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found