I’m trying to update all my old posts to shed my custom Blogger template now that Google+ comments are getting killed.
I tried getting this done through the Ghost-admin API, but I can’t seem to get a valid edit done. Is there a way to just patch a single field?
const GhostAdminAPI = require('@tryghost/admin-api');
const api = new GhostAdminAPI({
url: 'https://scrumbug.ghost.io',
key: 'xxxx',
version: 'v2'
});
api.posts.browse({limit: 400}).then(
posts => {
for(var post in posts) {
console.log(posts[post].id);
...
}
}
).then( promises => Promise.all(promises) ).catch(e => console.error(e));
On the … I tried:
posts[post].custom_template = null;
return api.posts.edit( posts[post] );
jhouwing ~ node fix-content.js
5b18ec2e1b866300bfc10823
{ ValidationError: Validation error, cannot edit post.
at makeRequest.catch (/home/jhouwing/node_modules/@tryghost/admin-api/lib/index.js:290:33)
at processTicksAndRejections (internal/process/next_tick.js:81:5)
name: 'ValidationError',
context: "Validation failed for 'posts[0]'",
type: 'ValidationError',
details:
[ { keyword: 'additionalProperties',
dataPath: '.posts[0]',
schemaPath: '#/additionalProperties',
params: [Object],
message: 'should NOT have additional properties' },
{ keyword: 'additionalProperties',
dataPath: '.posts[0]',
schemaPath: '#/additionalProperties',
params: [Object],
message: 'should NOT have additional properties' } ],
property: 'posts[0]',
help: null,
code: null,
id: '11848300-49c6-11e9-a986-c7968b6671f1' }
and
return api.posts.edit( { id: posts[post].id, custom_template: null } );
jhouwing ~ node fix-content.js
5b18ec2e1b866300bfc10823
{ ValidationError: Validation error, cannot edit post.
at makeRequest.catch (/home/jhouwing/node_modules/@tryghost/admin-api/lib/index.js:290:33)
at processTicksAndRejections (internal/process/next_tick.js:81:5)
name: 'ValidationError',
context: "Validation failed for 'posts[0]'",
type: 'ValidationError',
details:
[ { keyword: 'required',
dataPath: '.posts[0]',
schemaPath: '#/properties/posts/items/required',
params: [Object],
message: "should have required property 'updated_at'" } ],
property: 'posts[0]',
help: null,
code: null,
id: 'd7845630-49c5-11e9-a986-c7968b6671f1' }
Neither works and the errors I get scare me a bit in that I may accidentally lose old markdown contents this way.