Skip to content
EN

Publishing data with Integration API

Last updated

Immediately after registering an item via Integration API, its status is Draft. To make it retrievable as published data via Public API, you need to change its status to Published.

  1. Get the ID of the item you created
  2. Send a request to the publish endpoint to change its status to Published

Sample code for publishing an item with a specified ID

Section titled “Sample code for publishing an item with a specified ID”
Terminal window
curl -X POST \
'https://api.cms.reearth.io/api/<workspace>/projects/<project>/models/<model>/items/<item-id>/publish' \
--header 'Authorization: Bearer <your_integration_token>'

Sample code for creating and publishing an item in one go

Section titled “Sample code for creating and publishing an item in one go”

To create and publish an item in one flow, use the item ID returned at creation time directly in the publish request.

const WORKSPACE_ID = "<workspace_id_or_alias>";
const PROJECT_ID = "<project_id_or_alias>";
const MODEL_ID = "<model_id_or_key>";
const TOKEN = "<your_integration_token>";
const baseUrl = `https://api.cms.reearth.io/api/${WORKSPACE_ID}/projects/${PROJECT_ID}`;
// 1. Create the item
const createResp = await fetch(`${baseUrl}/models/${MODEL_ID}/items`, {
method: "POST",
headers: {
Authorization: `Bearer ${TOKEN}`,
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify({
fields: [
{ key: "name", type: "text", value: "Sample" },
],
}),
});
if (!createResp.ok) throw new Error(`Create failed: HTTP ${createResp.status}`);
const item = await createResp.json();
// 2. Publish the created item
const publishResp = await fetch(`${baseUrl}/models/${MODEL_ID}/items/${item.id}/publish`, {
method: "POST",
headers: {
Authorization: `Bearer ${TOKEN}`,
Accept: "application/json",
},
});
if (!publishResp.ok) throw new Error(`Publish failed: HTTP ${publishResp.status}`);
console.log("Create and publish complete.");

Before publishing, the status is Draft.

An item before publishing, with its status set to Draft.

Calling the publish endpoint changes the status to Published, making it retrievable via Public API.

An item after publishing via Integration API, with its status set to Published.

For the full endpoint specification, see Integration API Reference.