Hi, I’m trying to bulk add content using the Write API without success. No matter what model name I pass in the write api url (https://builder.io/api/v1/write/MODEL) I always get 404 error with “Model not found”. I followed the guide here and try with different models I have and it’s always the same. I’ll show a quick sample of this using my Document Meta model:
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
myHeaders.append("Authorization", `Bearer ${apiKey}`); // This is a private key (bpk-...)
var raw = JSON.stringify({
ownerId: "f127073fccdc44a590bf4362d8bb100b",
"@version": 3, // also tried with 2 here
name: "document-meta test",
modelId: "0f01a5b1a6374a7baaefb17775a141ee",
published: "draft",
data: {
title: "this is a title",
description: "entry.description",
openGraphImage:
"https://cdn.builder.io/api/v1/image/assets%2Ff127073fccdc44a590bf4362d8bb100b%2F00cbd27d8d5d482f86e6d93c35306230",
twitterCardImage:
"https://cdn.builder.io/api/v1/image/assets%2Ff127073fccdc44a590bf4362d8bb100b%2F9ade3b32a42b4d5da643f17fe54b3284",
canonicalUrl: "https://sporttrade.io/",
},
});
var requestOptions = {
method: "POST",
headers: myHeaders,
body: raw,
redirect: "follow",
};
fetch("https://builder.io/api/v1/write/document-meta", requestOptions)
.then((response) => response.text())
.then((result) => console.log(result))
.catch((error) => console.log("error", error));
Also rewrite it simpler like this:
async function importToBuilder() {
const body = {
name: "sample entry",
modelId: "0f01a5b1a6374a7baaefb17775a141ee",
published: "published",
data: {
title: "this is a title",
description: "entry.description",
openGraphImage:
"https://cdn.builder.io/api/v1/image/assets%2Ff127073fccdc44a590bf4362d8bb100b%2F00cbd27d8d5d482f86e6d93c35306230",
twitterCardImage:
"https://cdn.builder.io/api/v1/image/assets%2Ff127073fccdc44a590bf4362d8bb100b%2F9ade3b32a42b4d5da643f17fe54b3284",
canonicalUrl: "https://spor.io/",
},
};
console.log("Importing entry:", body);
try {
const response = await fetch(
`https://builder.io/api/v1/write/document-meta`,
{
method: "POST",
headers: {
Authorization: `Bearer ${apiKey}`, // This is a private key (bpk-...)
"Content-Type": "application/json",
},
body: JSON.stringify(body),
}
);
const data = await response.json();
console.log("Imported entry:", data);
} catch (error) {
console.error("Error importing entry:", error);
}
}
importToBuilder();
I really don’t know what else can I try so any help is really appreciated.
Builder public api key
f127073fccdc44a590bf4362d8bb100b
Code stack you are integrating Builder with
Gatsby