# First time using cURL - Notion.so API

**URL:** https://discourse.nodered.org/t/first-time-using-curl-notion-so-api/73174
**Category:** General
**Tags:** http-request
**Created:** [4 January 2023 17:01 UTC](https://discourse.nodered.org/t/first-time-using-curl-notion-so-api/73174 "2023-01-04T17:01:33Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![blacktoothgrin](https://avatars.discourse-cdn.com/v4/letter/b/9de0a6/32.png) [@blacktoothgrin](https://discourse.nodered.org/u/blacktoothgrin)
#### Post date: [4 January 2023 17:01 UTC](https://discourse.nodered.org/t/first-time-using-curl-notion-so-api/73174/1 "2023-01-04T17:01:33Z")

</div>

Hello!

I'm trying to do my first API cURL, following guidance from [the API documentation for Notion.so](https://developers.notion.com/docs/create-a-notion-integration).

Combined with some Googling, I'm just struggling to get this going through Node-RED. Could anyone provide some guidance? I would really appreciate it.

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [4 January 2023 18:11 UTC](https://discourse.nodered.org/t/first-time-using-curl-notion-so-api/73174/2 "2023-01-04T18:11:09Z")

</div>

In node-red you would convert the curl to a http request, or you could send a curl using the exec node and the OS.  
Here is an example of the curl from the docs you posted, used in a http request node.  
You need to add you db id in the inject payload JSON and your api key in the http request node, delete all asterisks and everything inbetween and replace with your id and key.

```auto
[{"id":"5515489234ec93df","type":"inject","z":"da8a6ef0b3c9a5c8","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"parent\":{\"database_id\":\" ****your_db_id**** \"},\"properties\":{\"title\":{\"title\":[{\"text\":{\"content\":\"Yurts in Big Sur, California\"}}]}}}","payloadType":"json","x":150,"y":3000,"wires":[["912704151f038109"]]},{"id":"912704151f038109","type":"http request","z":"da8a6ef0b3c9a5c8","name":"","method":"POST","ret":"obj","paytoqs":"ignore","url":"https://api.notion.com/v1/pages","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[{"keyType":"other","keyValue":"Authorization","valueType":"other","valueValue":"Bearer ****your_api_key*****"},{"keyType":"other","keyValue":"Content-Type","valueType":"other","valueValue":"application/json"},{"keyType":"other","keyValue":"Notion-Version","valueType":"other","valueValue":"2021-08-16"}],"x":330,"y":3020,"wires":[["b1a470fe0ca38d66"]]},{"id":"b1a470fe0ca38d66","type":"debug","z":"da8a6ef0b3c9a5c8","name":"debug 224","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":530,"y":2980,"wires":[]}]

```

[edit] fixed typo in Authorization header.

---

<div class="post-metadata">

### Author: ![blacktoothgrin](https://avatars.discourse-cdn.com/v4/letter/b/9de0a6/32.png) [@blacktoothgrin](https://discourse.nodered.org/u/blacktoothgrin)
#### Post date: [4 January 2023 18:45 UTC](https://discourse.nodered.org/t/first-time-using-curl-notion-so-api/73174/3 "2023-01-04T18:45:18Z")

</div>

You are AWESOME! Thank you so much. I was able to change the couple of things needed and it worked immediately. This gives me a great jumping off point for my project.

Thank you very much for your time! You made my day.

EDIT: Now if I'm being picky here, I'm actually using Node-RED with Home Assistant. I was hoping to be able to insert the state of a sensor, something like {{states.sensor.my\_sensor}} but it's outputting this as raw text. Do you know how I would insert that?

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [4 January 2023 20:35 UTC](https://discourse.nodered.org/t/first-time-using-curl-notion-so-api/73174/4 "2023-01-04T20:35:25Z")

</div>

Here is an example of an incoming sensor value, it is in the inject node as `sensor_value`

```auto
[{"id":"5515489234ec93df","type":"inject","z":"da8a6ef0b3c9a5c8","name":"","props":[{"p":"sensor_value","v":"12","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":70,"y":2940,"wires":[["a96b7eed97e8e573"]]},{"id":"a96b7eed97e8e573","type":"change","z":"da8a6ef0b3c9a5c8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\t \"parent\":{\"database_id\":\" ****your_db_id**** \"},\t \"properties\":{\t \"title\":{\t \"title\":[\t {\t \"text\":{\t \"content\": $$.sensor_value\t }\t }\t]\t }\t }\t}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":300,"y":2980,"wires":[["912704151f038109"]]},{"id":"912704151f038109","type":"http request","z":"da8a6ef0b3c9a5c8","name":"","method":"POST","ret":"obj","paytoqs":"ignore","url":"https://api.notion.com/v1/pages","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[{"keyType":"other","keyValue":"Authorization","valueType":"other","valueValue":"Bearer ****your_api_key****"},{"keyType":"other","keyValue":"Content-Type","valueType":"other","valueValue":"application/json"},{"keyType":"other","keyValue":"Notion-Version","valueType":"other","valueValue":"2021-08-16"}],"x":370,"y":3040,"wires":[["b1a470fe0ca38d66"]]},{"id":"b1a470fe0ca38d66","type":"debug","z":"da8a6ef0b3c9a5c8","name":"debug 224","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":530,"y":2980,"wires":[]}]

```

Now in the original example i have added it to the payload json, but instead of using JSON in the change node i have switched to JSONata. I have added the value using `$$.sensor_value`.

You can do the same with your incoming data.

In future if you want a more related example to what you are attempting, it is best to supply examples flows with data examples added or pasted separately in text format.

I don't use HA but i believe you can use JSONata in most HA nodes.

---

<div class="post-metadata">

### Author: ![blacktoothgrin](https://avatars.discourse-cdn.com/v4/letter/b/9de0a6/32.png) [@blacktoothgrin](https://discourse.nodered.org/u/blacktoothgrin)
#### Post date: [4 January 2023 20:55 UTC](https://discourse.nodered.org/t/first-time-using-curl-notion-so-api/73174/5 "2023-01-04T20:55:02Z")

</div>

This worked great and, once again, I have some working nodes to go off of and experiment with!

Since you're so helpful and knowledgable, I was attempting to adjust a property field in the flow and having some trouble with the indentations/nesting, I believe. Would you be able to help me with the JSON formatting like [in this example](https://developers.notion.com/docs/working-with-databases):

```auto
      "Grocery item": {
        "type": "title",
        "title": [{ "type": "text", "text": { "content": "Tomatoes" } }]

```

I think I am getting lost in the brackets.

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [4 January 2023 21:19 UTC](https://discourse.nodered.org/t/first-time-using-curl-notion-so-api/73174/6 "2023-01-04T21:19:06Z")

</div>

In the Json editor there are vertical lines, these are there to help

 ![chrome_screenshot_1672866699084](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/c/3c175f1ecfa5532f0f588ae9689e2836d62acbcc.png)  
The closing bracket is inline with the starting brackets line first char or bracket.

I believe yours has a missing `}` at end, difficult to tell though as you have not posted a full syntaxually correct JSON., rather a portion of one.

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [4 January 2023 21:19 UTC](https://discourse.nodered.org/t/first-time-using-curl-notion-so-api/73174/7 "2023-01-04T21:19:12Z")

</div>

Close but you are missing the final `}`

---

<div class="post-metadata">

### Author: ![blacktoothgrin](https://avatars.discourse-cdn.com/v4/letter/b/9de0a6/32.png) [@blacktoothgrin](https://discourse.nodered.org/u/blacktoothgrin)
#### Post date: [4 January 2023 21:34 UTC](https://discourse.nodered.org/t/first-time-using-curl-notion-so-api/73174/8 "2023-01-04T21:34:37Z")

</div>

Here is the flow I have been experimenting with, but I can't seem to make the editor happy. I'm still very new to all of this, so I do apologize.

```auto
[{"id":"e22ea111d6ef50b4","type":"change","z":"81f0b9e0.caa338","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\t \"parent\":{\t \"database_id\":\" **DATABASE_ID** \"\t},\t \"properties\":{\t \"Grocery item\": {\t \"type\": \"title\",\t \"title\": [\t {\t \"type\": \"text\",\t \"text\": { \"content\": \"Tomatoes\" } \t }\t]\t \"title\":{\t \"title\":[\t {\t \"text\":{\t \"content\": $$.sensor_value\t }\t }\t]\t }\t }\t}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":360,"wires":[["4a8ce503cfc04df1"]]},{"id":"4a8ce503cfc04df1","type":"http request","z":"81f0b9e0.caa338","name":"","method":"POST","ret":"obj","paytoqs":"ignore","url":"https://api.notion.com/v1/pages","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[{"keyType":"other","keyValue":"Authorization","valueType":"other","valueValue":"Bearer **API_KEY**"},{"keyType":"other","keyValue":"Content-Type","valueType":"other","valueValue":"application/json"},{"keyType":"other","keyValue":"Notion-Version","valueType":"other","valueValue":"2021-08-16"}],"x":750,"y":360,"wires":[["3ae014fa9b9ba61c"]]},{"id":"3ae014fa9b9ba61c","type":"debug","z":"81f0b9e0.caa338","name":"debug 224","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":930,"y":360,"wires":[]},{"id":"8b202a4b07d5c862","type":"inject","z":"81f0b9e0.caa338","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":360,"wires":[["dad5990bebb00cfe"]]},{"id":"dad5990bebb00cfe","type":"api-current-state","z":"81f0b9e0.caa338","name":"Number of Restarts","server":"b2e380c6.9da53","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"counter.homeassistant_restarts","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"sensor_value","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":350,"y":360,"wires":[["e22ea111d6ef50b4"]]},{"id":"b2e380c6.9da53","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30,"areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

```

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [4 January 2023 21:55 UTC](https://discourse.nodered.org/t/first-time-using-curl-notion-so-api/73174/9 "2023-01-04T21:55:55Z")

</div>

As said I don't run HA, so can not run your flow. Can you give a debug output of the HA node. In a text format, use the copy value button in the debug sidebar. It will appear when you hove mouse ovee property name. Copy whole message.

---

<div class="post-metadata">

### Author: ![blacktoothgrin](https://avatars.discourse-cdn.com/v4/letter/b/9de0a6/32.png) [@blacktoothgrin](https://discourse.nodered.org/u/blacktoothgrin)
#### Post date: [4 January 2023 22:03 UTC](https://discourse.nodered.org/t/first-time-using-curl-notion-so-api/73174/10 "2023-01-04T22:03:36Z")

</div>

> [@E1cid](#):
>
> e HA node. In a text format, use the copy value button in the debug sidebar. It will appear when you hove mouse ovee property name. Copy whole message.

The change node is where the error is showing. Here's a flow with the HA node removed. I can re-add it now that I understand how to use the $$.sensor\_value you pointed out.

```auto
[{"id":"e22ea111d6ef50b4","type":"change","z":"81f0b9e0.caa338","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\t \"parent\":{\t \"database_id\":\" **DATABASE_ID** \"\t},\t \"properties\":{\t \"Grocery item\": {\t \"type\": \"title\",\t \"title\": [\t {\t \"type\": \"text\",\t \"text\": { \"content\": \"Tomatoes\" } \t }\t]\t \"title\":{\t \"title\":[\t {\t \"text\":{\t \"content\": $$.sensor_value\t }\t }\t]\t }\t }\t}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":360,"wires":[["4a8ce503cfc04df1"]]},{"id":"4a8ce503cfc04df1","type":"http request","z":"81f0b9e0.caa338","name":"","method":"POST","ret":"obj","paytoqs":"ignore","url":"https://api.notion.com/v1/pages","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[{"keyType":"other","keyValue":"Authorization","valueType":"other","valueValue":"Bearer **API_KEY**"},{"keyType":"other","keyValue":"Content-Type","valueType":"other","valueValue":"application/json"},{"keyType":"other","keyValue":"Notion-Version","valueType":"other","valueValue":"2021-08-16"}],"x":750,"y":360,"wires":[["3ae014fa9b9ba61c"]]},{"id":"3ae014fa9b9ba61c","type":"debug","z":"81f0b9e0.caa338","name":"debug 224","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":930,"y":360,"wires":[]},{"id":"8b202a4b07d5c862","type":"inject","z":"81f0b9e0.caa338","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":360,"y":360,"wires":[["e22ea111d6ef50b4"]]}]

```

When I attempt to Deploy, Node-RED gives the following error:

The workspace contains some nodes that are not properly configured:

[Testing] set msg.payload (change)

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [4 January 2023 22:12 UTC](https://discourse.nodered.org/t/first-time-using-curl-notion-so-api/73174/11 "2023-01-04T22:12:52Z")

</div>

Yes I know but it is helpful to have all the information.

If some one asks for info, it is best to answer the question, as they are kind enough to help in first place.

The change node has a missing `}` and a `,`, to close `grocery` and open `title`

Not sure but this maybe correct.

```auto
[{"id":"e22ea111d6ef50b4","type":"change","z":"da8a6ef0b3c9a5c8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\t \"parent\":{\t \"database_id\":\" **DATABASE_ID** \"\t },\t \"properties\":{\t \"Grocery item\": {\t \"type\": \"title\",\t \"title\": [\t {\t \"type\": \"text\",\t \"text\": { \"content\": \"Tomatoes\" } \t }\t]\t },\t \"title\":{\t \"title\":[\t {\t \"text\":{\t \"content\": $$.sensor_value\t }\t }\t]\t }\t }\t}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":3180,"wires":[["4a8ce503cfc04df1"]]}]

```

---

<div class="post-metadata">

### Author: ![blacktoothgrin](https://avatars.discourse-cdn.com/v4/letter/b/9de0a6/32.png) [@blacktoothgrin](https://discourse.nodered.org/u/blacktoothgrin)
#### Post date: [4 January 2023 22:40 UTC](https://discourse.nodered.org/t/first-time-using-curl-notion-so-api/73174/12 "2023-01-04T22:40:10Z")

</div>

> [@E1cid](#):
>
> If some one asks for info, it is best to answer the question, as they are kind enough to help in first place.

I understand, sorry about that. The debug output from my HA node shows:  
1672871879673

I am also seeing the following error now in the request node:

```auto
{"object":"error","status":400,"code":"validation_error","message":"Grocery Item is expected to be rich_text."}

```

Your change did fix the error within the change node. Just chasing a different problem now, it seems.

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [4 January 2023 23:02 UTC](https://discourse.nodered.org/t/first-time-using-curl-notion-so-api/73174/13 "2023-01-04T23:02:00Z")

</div>

I would expect from the error message and [Docs](https://developers.notion.com/reference/rich-text#text-objects) that content value of the text object is not text, add a debug after the change node and see what you are sending.

---

<div class="post-metadata">

### Author: ![blacktoothgrin](https://avatars.discourse-cdn.com/v4/letter/b/9de0a6/32.png) [@blacktoothgrin](https://discourse.nodered.org/u/blacktoothgrin)
#### Post date: [4 January 2023 23:15 UTC](https://discourse.nodered.org/t/first-time-using-curl-notion-so-api/73174/14 "2023-01-04T23:15:09Z")

</div>

The change node is sending this:

```auto
{"parent":{"database_id":"*DATABASE_ID*"},"properties":{"Grocery Item":{"type":"title","title":[{"type":"text","text":{"content":"Tomatoes"}}]},"title":{"title":[{"text":{"content":"2"}}]}}}

```

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [4 January 2023 23:55 UTC](https://discourse.nodered.org/t/first-time-using-curl-notion-so-api/73174/15 "2023-01-04T23:55:46Z")

</div>

I am only guessing now, as I do not have anything to test. I think the Grocery Item is expected to be of type `rich_text` and not `title`. I think you are going to need someone using the api, or ask on there slack feed.

---

<div class="post-metadata">

### Author: ![blacktoothgrin](https://avatars.discourse-cdn.com/v4/letter/b/9de0a6/32.png) [@blacktoothgrin](https://discourse.nodered.org/u/blacktoothgrin)
#### Post date: [5 January 2023 00:42 UTC](https://discourse.nodered.org/t/first-time-using-curl-notion-so-api/73174/16 "2023-01-05T00:42:02Z")

</div>

I will do some experimenting! You got me much further along than I expected. Thank you so much. I genuinely appreciate your time!

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [19 January 2023 00:42 UTC](https://discourse.nodered.org/t/first-time-using-curl-notion-so-api/73174/17 "2023-01-19T00:42:54Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
