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

Admin API Can't POST to /posts/ without cleaning up certain fields #11461

Closed
ErisDS opened this issue Dec 16, 2019 · 1 comment
Closed

Admin API Can't POST to /posts/ without cleaning up certain fields #11461

ErisDS opened this issue Dec 16, 2019 · 1 comment
Labels
affects:api Affects the Ghost API bug [triage] something behaving unexpectedly server / core Issues relating to the server or core of Ghost

Comments

@ErisDS
Copy link
Member

ErisDS commented Dec 16, 2019

When using the API, there is an expectation that any data fetched should be possible to be sent back.

This is currently not the case for posts.

Reproduction Steps

This snippet should work with valid credentials:

const GhostAdminAPI = require('@tryghost/admin-api');
const api = new GhostAdminAPI({
    url,
    key,
    version: 'v2'
});
const allPosts = await api.posts.browse({limit: 10});
allPosts.map(async (post) => {
   // Edit one field here e.g. add a tag, find and replace content, etc
   return await api.posts.edit(post);
});

Currently, you get an error like:

There was an error { ValidationError: Validation error, cannot edit post.
    at makeRequest.catch (/Users/hannah/Sites/api-experiments/node_modules/@tryghost/admin-api/lib/index.js:304:33)
    at process._tickCallback (internal/process/next_tick.js:68:7)
  name: 'ValidationError',
  context: 'Validation failed for \'posts[0]\'',
  type: 'ValidationError',
  details:
   [ { keyword: 'additionalProperties',
       dataPath: '.posts[0]',
       schemaPath: '#/additionalProperties',
       params: { additionalProperty: 'uuid' },
       message: 'should NOT have additional properties' },
     { keyword: 'additionalProperties',
       dataPath: '.posts[0]',
       schemaPath: '#/additionalProperties',
       params: { additionalProperty: 'comment_id' },
       message: 'should NOT have additional properties' },
     { keyword: 'additionalProperties',
       dataPath: '.posts[0]',
       schemaPath: '#/additionalProperties',
       params: { additionalProperty: 'send_email_when_published' },
       message: 'should NOT have additional properties' },
     { keyword: 'additionalProperties',
       dataPath: '.posts[0]',
       schemaPath: '#/additionalProperties',
       params: { additionalProperty: 'email_subject' },
       message: 'should NOT have additional properties' } ],
  property: 'posts[0]',
  help: null,
  code: null,
  id: '21257850-1fef-11ea-bb64-d53f5ec37026' }

Note:

uuid and comment_id are a problem in both v2 and v3
the 2x email fields are only a problem with v2

Technical details:

  • Ghost Version: master
@naz naz added admin-api affects:api Affects the Ghost API bug [triage] something behaving unexpectedly server / core Issues relating to the server or core of Ghost labels Dec 16, 2019
naz added a commit to naz/Ghost that referenced this issue Dec 16, 2019
refs  TryGhost#11461

- The email feature was introduced in API v3 and is not back compatible with API v2. These fields should not appear in any v2 responses.
- Added regression tests for API v2 so that cases like this are spotted
easier in the future.
naz added a commit that referenced this issue Dec 16, 2019
refs  #11461

- The email feature was introduced in API v3 and is not back compatible with API v2. These fields should not appear in any v2 responses.
- Added regression tests for API v2 so that cases like this are spotted
easier in the future.
@naz
Copy link
Contributor

naz commented Dec 16, 2019

With the above commits:

  • uuid and comment_id were allowed in v2 and v3 requests
  • send_email_when_published and email_subject were removed from API v2 responses

@naz naz closed this as completed Dec 16, 2019
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 server / core Issues relating to the server or core of Ghost
Projects
None yet
Development

No branches or pull requests

2 participants