Import data from csv or json to Builder data model

Hi all,

I have problem and need help here.
I created a data model in Builder IO and it had 2 field (title: text, url: url)


I want to import data from a csv file to this data model.
Is there a way/guide to create it.

Thanks.

Hi @ducanh,

With the Write API, you can POST , PATCH , PUT , and DELETE Builder content. You can use the Write API for use cases such as writing programmatically from your own internal application, or as part of a code release and build process.

You can certainly create a custom script to read from CSV file and use write API to upload data to the builder data model.

Sample script

var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
myHeaders.append("Authorization", "Bearer bpk-private-key");

var raw = JSON.stringify({
  "ownerId": "c782aff3c66f48acb425981b997feb10",
  "@version": 3,
  "name": "test-out-json",
  "modelId": "f546a1c3030946009bef3e0433ce3901",
  "published": "draft",
  "query": [
    {
      "@type": "@builder.io/core:Query",
      "property": "urlPath",
      "operator": "is",
      "value": "/test-out-json"
    }
  ],
  "data": {
    "someProperty": "hello"
  }
});

var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: raw,
  redirect: 'follow'
};

fetch("https://builder.io/api/v1/write/page", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));
1 Like

Hi @manish-sharma

I did it, Thank you.

Hi, I am getting error
{“status”:404,“message”:“Model not found”}

whenever i try to create Model using WriteApi

2 Likes

Hello!

Did you manage to solve this problem? I ask because I am exploring the feasibility of this implementation.