Skip to content

Instantly share code, notes, and snippets.

@sandoche
Created August 25, 2021 12:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sandoche/c7b5ca70503d2e396923ed082bc98906 to your computer and use it in GitHub Desktop.
Save sandoche/c7b5ca70503d2e396923ed082bc98906 to your computer and use it in GitHub Desktop.
Notion API - Creating page with image
curl 'https://api.notion.com/v1/pages' \
-H 'Authorization: Bearer '"SECRET_HERE"'' \
-H "Content-Type: application/json" \
-H "Notion-Version: 2021-05-13" \
--data '{
"parent": {
"type": "page_id",
"page_id": "PAGE_ID_HERE"
},
"properties": {
"title": {
"title": [{ "type": "text", "text": { "content": "A note from your pals at Notion" } }]
}
},
"children": [
{
"object": "block",
"type": "paragraph",
"paragraph": {
"text": [{ "type": "text", "text": { "content": "You made this page using the Notion API. Pretty cool, huh? We hope you enjoy building with us." } }]
}
},
{
"object": "block",
"type": "image",
"image": {
"caption": [],
"type": "file",
"file": {
"url": "https://undesign.learn.uno/icon.png",
"expiry_time": "2021-08-26T22:12:29.066Z"
}
}
}
]
}'
@sandoche
Copy link
Author

I get this error:

{
  "object": "error",
  "status": 400,
  "code": "validation_error",
  "message": "body failed validation. Fix one: body.children[1].paragraph should be defined, instead was `undefined`. body.children[1].heading_1 should be defined, instead was `undefined`. body.children[1].heading_2 should be defined, instead was `undefined`. body.children[1].heading_3 should be defined, instead was `undefined`. body.children[1].bulleted_list_item should be defined, instead was `undefined`. body.children[1].numbered_list_item should be defined, instead was `undefined`. body.children[1].to_do should be defined, instead was `undefined`. body.children[1].toggle should be defined, instead was `undefined`. body.children[1].embed should be defined, instead was `undefined`. body.children[1].bookmark should be defined, instead was `undefined`. body.children[1].image should be defined, instead was `undefined`. body.children[1].video should be defined, instead was `undefined`. body.children[1].pdf should be defined, instead was `undefined`. body.children[1].file should be defined, instead was `undefined`. body.children[1].audio should be defined, instead was `undefined`."
}

@sandoche
Copy link
Author

sandoche commented Aug 25, 2021

The problem came from Notion-Version to 2021-08-16
And also the type was not correct here is the right code:

curl 'https://api.notion.com/v1/pages' \
  -H 'Authorization: Bearer '"SECRET"'' \
  -H "Content-Type: application/json" \
  -H "Notion-Version: 2021-08-16" \
  --data '{
  "parent": {
  "page_id": "PAGE_ID"
},
  "properties": {
        "title": {
      "title": [{ "type": "text", "text": { "content": "A note from your pals at Notion" } }]
        }
    },
    "children": [
    {
      "object": "block",
      "type": "paragraph",
      "paragraph": {
        "text": [{ "type": "text", "text": { "content": "You made this page using the Notion API. Pretty cool, huh? We hope you enjoy building with us." } }]
      }
    },
    {
      "object": "block",
      "type": "image",
      "image": {
          "caption": [],
          "type": "external",
          "external": {
              "url": "https://undesign.learn.uno/icon.png"
          }
      }
    }
  ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment