# Write API returning 404 "model not found"

**URL:** <https://forum.builder.io/t/write-api-returning-404-model-not-found/5345>\
**Category:** Bugs\
**Tags:** api\
**Created:** [April 10, 2024, 1:34pm UTC](https://forum.builder.io/t/write-api-returning-404-model-not-found/5345 "2024-04-10T13:34:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lucas\_aven](https://avatars.discourse-cdn.com/v4/letter/l/c89c15/32.png) [@lucas\_aven](https://forum.builder.io/u/lucas_aven)\
**Post date:** [April 10, 2024, 1:34pm UTC](https://forum.builder.io/t/write-api-returning-404-model-not-found/5345/1 "2024-04-10T13:34:49Z")

</div>

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](https://builder.io/api/v1/write/MODEL)) I always get 404 error with “Model not found”. I followed the guide [here](https://forum.builder.io/t/import-data-from-csv-or-json-to-builder-data-model/3700/2) 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](https://builder.io/content?model=0f01a5b1a6374a7baaefb17775a141ee) model:

```auto
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:

```auto
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

---

<div class="post-metadata">

**Author:** ![manish-sharma](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@manish-sharma](https://forum.builder.io/u/manish-sharma)\
**Post date:** [April 10, 2024, 1:40pm UTC](https://forum.builder.io/t/write-api-returning-404-model-not-found/5345/2 "2024-04-10T13:40:02Z")

</div>

> [@lucas\_aven](#):
>
> `apiKey`

Hello @lucas_aven,

Are you using the public key or private key in the auth header?

> **[Using the Builder API Key - Builder.io](https://www.builder.io/c/docs/using-your-api-key#managing-private-keys)**
>
> Drag and drop with your components, right within your existing site or app. Build and optimize digital experiences for any tech stack, visually.

---

<div class="post-metadata">

**Author:** ![lucas\_aven](https://avatars.discourse-cdn.com/v4/letter/l/c89c15/32.png) [@lucas\_aven](https://forum.builder.io/u/lucas_aven)\
**Post date:** [April 10, 2024, 1:42pm UTC](https://forum.builder.io/t/write-api-returning-404-model-not-found/5345/3 "2024-04-10T13:42:21Z")

</div>

Hi @manish-sharma thx for the quick response! I’m using a private key (the one that starts with bpk-xxx

---

<div class="post-metadata">

**Author:** ![manish-sharma](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@manish-sharma](https://forum.builder.io/u/manish-sharma)\
**Post date:** [April 10, 2024, 2:13pm UTC](https://forum.builder.io/t/write-api-returning-404-model-not-found/5345/4 "2024-04-10T14:13:29Z")

</div>

> [@lucas\_aven](#):
>
> ```auto
> 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));
> 
> ```

Hello @lucas_aven,

I attempted to use your code with private-key from your store and had no issues, I recommend you verify the private key and check if the issue is with the node version, I used node 18 to execute the script

 ![Screenshot 2024-04-10 at 7.41.07 PM](https://us1.discourse-cdn.com/flex020/uploads/builder/original/2X/7/716dc162504deb1cd73619c21439fdd46efd5492.png)  
 ![Screenshot 2024-04-10 at 7.41.21 PM](https://us1.discourse-cdn.com/flex020/uploads/builder/original/2X/d/d0af0ac765d55565d52d48d4bc0538cae72bd2f9.png)

---

<div class="post-metadata">

**Author:** ![lucas\_aven](https://avatars.discourse-cdn.com/v4/letter/l/c89c15/32.png) [@lucas\_aven](https://forum.builder.io/u/lucas_aven)\
**Post date:** [April 10, 2024, 2:53pm UTC](https://forum.builder.io/t/write-api-returning-404-model-not-found/5345/5 "2024-04-10T14:53:51Z")

</div>

Thank you a lot @manish-sharma I double checked and the issue is the following **(Important to take into account since I think is a bug)** even though I had the correct private api key I had the role of **Developer** and that was causing the issue for what I can tell. As soon as I was promoted to **Admin** I was able to make it work with the same private key i was using when I was **Developer**.
