I am trying to import Jobs from a public job board as separate posts into the database. Basically it already works, but as soon as I want to add the job description (HTML) into the MobileDoc part the API blocks me and gives me a 500 and I am not sure why.
Here is the JS I use (without my login credentials …)
const GREENHOUSE_URL = 'https://api.greenhouse.io/v1/boards/kilabs';
const GHOST_URL = 'ghost/api/v0.1';
// const GHOST_URL = ghost.url.api('posts').replace(/\/?\?.*$/, '');
const GHOST_CLIENT_ID = 'ghost-frontend';
const GHOST_CLIENT_SECRET = '85f5bc2d8daa';
const uuid = () => {
const s4 = () =>
Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
return `${s4()}${s4()}-${s4()}-${s4()}-${s4()}-${s4()}${s4()}${s4()}`;
};
const fetchAllJobs = () =>
fetch(`${GREENHOUSE_URL}/jobs`)
.then(x => x.json())
.then(x => x.jobs);
const fetchJob = id =>
fetch(`${GREENHOUSE_URL}/jobs/${id}`).then(x => x.json());
const authenticateGhost = (username, password) =>
fetch(`${GHOST_URL}/authentication/token`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
username,
password,
grant_type: 'password',
client_id: GHOST_CLIENT_ID,
client_secret: GHOST_CLIENT_SECRET,
}),
})
.then(x => x.json())
.then(x => x.access_token);
const postJobs = (token, posts) =>
fetch(`${GHOST_URL}/posts`, {
method: 'POST',
headers: {
Authorization: `Bearer ${token}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
posts,
}),
});
const transferJobs = async () => {
const jobsList = await fetchAllJobs();
const jobs = await Promise.all(jobsList.map(x => fetchJob(x.id)));
const ghostToken = await authenticateGhost(
'xxx',
'xxx',
);
const makeMobileDoc = (content) => {
return {
version: "0.3.1",
markups: [],
atoms: [],
cards: [
["card-markdown", {
"cardName": "card-markdown",
"markdown": content
}
],
],
sections: [[10,0]]
}
}
const posts = jobs.map(x =>
Object.assign(
{},
{
uuid: uuid(),
title: x.title,
author: "1",
mobiledoc: makeMobileDoc(x.content),
status: "published",
published_by: "None",
page: false,
featured: false,
},
),
);
postJobs(ghostToken, posts);
};
transferJobs();
And I always end up getting this with MobileDoc:
POST http://localhost:2368/ghost/api/v0.1/posts 500 (Internal Server Error)
Can anybody give me hint why this is happening?