|
| 1 | +# Notion |
| 2 | + |
| 3 | +> Notion source connector |
| 4 | +
|
| 5 | +## Description |
| 6 | + |
| 7 | +Used to read data from Notion. |
| 8 | + |
| 9 | +## Key features |
| 10 | + |
| 11 | +- [x] [batch](../../concept/connector-v2-features.md) |
| 12 | +- [ ] [stream](../../concept/connector-v2-features.md) |
| 13 | +- [ ] [exactly-once](../../concept/connector-v2-features.md) |
| 14 | +- [x] [schema projection](../../concept/connector-v2-features.md) |
| 15 | +- [ ] [parallelism](../../concept/connector-v2-features.md) |
| 16 | +- [ ] [support user-defined split](../../concept/connector-v2-features.md) |
| 17 | + |
| 18 | +## Options |
| 19 | + |
| 20 | +| name | type | required | default value | |
| 21 | +| --------------------------- | ------ | -------- | ------------- | |
| 22 | +| url | String | Yes | - | |
| 23 | +| password | String | Yes | - | |
| 24 | +| version | String | Yes | - | |
| 25 | +| method | String | No | get | |
| 26 | +| schema.fields | Config | No | - | |
| 27 | +| format | String | No | json | |
| 28 | +| params | Map | No | - | |
| 29 | +| body | String | No | - | |
| 30 | +| json_field | Config | No | - | |
| 31 | +| content_json | String | No | - | |
| 32 | +| poll_interval_ms | int | No | - | |
| 33 | +| retry | int | No | - | |
| 34 | +| retry_backoff_multiplier_ms | int | No | 100 | |
| 35 | +| retry_backoff_max_ms | int | No | 10000 | |
| 36 | +| common-options | config | No | - | |
| 37 | + |
| 38 | +### url [String] |
| 39 | + |
| 40 | +http request url |
| 41 | + |
| 42 | +### password [String] |
| 43 | + |
| 44 | +API key for login, you can get more detail at this link: |
| 45 | + |
| 46 | +https://developers.notion.com/docs/authorization |
| 47 | + |
| 48 | +### version [String] |
| 49 | + |
| 50 | +The Notion API is versioned. API versions are named for the date the version is released |
| 51 | + |
| 52 | +### method [String] |
| 53 | + |
| 54 | +http request method, only supports GET, POST method |
| 55 | + |
| 56 | +### params [Map] |
| 57 | + |
| 58 | +http params |
| 59 | + |
| 60 | +### body [String] |
| 61 | + |
| 62 | +http body |
| 63 | + |
| 64 | +### poll_interval_ms [int] |
| 65 | + |
| 66 | +request http api interval(millis) in stream mode |
| 67 | + |
| 68 | +### retry [int] |
| 69 | + |
| 70 | +The max retry times if request http return to `IOException` |
| 71 | + |
| 72 | +### retry_backoff_multiplier_ms [int] |
| 73 | + |
| 74 | +The retry-backoff times(millis) multiplier if request http failed |
| 75 | + |
| 76 | +### retry_backoff_max_ms [int] |
| 77 | + |
| 78 | +The maximum retry-backoff times(millis) if request http failed |
| 79 | + |
| 80 | +### format [String] |
| 81 | + |
| 82 | +the format of upstream data, now only support `json` `text`, default `json`. |
| 83 | + |
| 84 | +when you assign format is `json`, you should also assign schema option, for example: |
| 85 | + |
| 86 | +upstream data is the following: |
| 87 | + |
| 88 | +```json |
| 89 | +{ |
| 90 | + "code": 200, |
| 91 | + "data": "get success", |
| 92 | + "success": true |
| 93 | +} |
| 94 | +``` |
| 95 | + |
| 96 | +you should assign schema as the following: |
| 97 | + |
| 98 | +```hocon |
| 99 | +
|
| 100 | +schema { |
| 101 | + fields { |
| 102 | + code = int |
| 103 | + data = string |
| 104 | + success = boolean |
| 105 | + } |
| 106 | +} |
| 107 | +
|
| 108 | +``` |
| 109 | + |
| 110 | +connector will generate data as the following: |
| 111 | + |
| 112 | +| code | data | success | |
| 113 | +|------|-------------|---------| |
| 114 | +| 200 | get success | true | |
| 115 | + |
| 116 | +when you assign format is `text`, connector will do nothing for upstream data, for example: |
| 117 | + |
| 118 | +upstream data is the following: |
| 119 | + |
| 120 | +```json |
| 121 | +{ |
| 122 | + "code": 200, |
| 123 | + "data": "get success", |
| 124 | + "success": true |
| 125 | +} |
| 126 | +``` |
| 127 | + |
| 128 | +connector will generate data as the following: |
| 129 | + |
| 130 | +| content | |
| 131 | +|---------| |
| 132 | +| {"code": 200, "data": "get success", "success": true} | |
| 133 | + |
| 134 | +### schema [Config] |
| 135 | + |
| 136 | +#### fields [Config] |
| 137 | + |
| 138 | +the schema fields of upstream data |
| 139 | + |
| 140 | +### content_json [String] |
| 141 | + |
| 142 | +This parameter can get some json data.If you only need the data in the 'book' section, configure `content_field = "$.store.book.*"`. |
| 143 | + |
| 144 | +If your return data looks something like this. |
| 145 | + |
| 146 | +```json |
| 147 | +{ |
| 148 | + "store": { |
| 149 | + "book": [ |
| 150 | + { |
| 151 | + "category": "reference", |
| 152 | + "author": "Nigel Rees", |
| 153 | + "title": "Sayings of the Century", |
| 154 | + "price": 8.95 |
| 155 | + }, |
| 156 | + { |
| 157 | + "category": "fiction", |
| 158 | + "author": "Evelyn Waugh", |
| 159 | + "title": "Sword of Honour", |
| 160 | + "price": 12.99 |
| 161 | + } |
| 162 | + ], |
| 163 | + "bicycle": { |
| 164 | + "color": "red", |
| 165 | + "price": 19.95 |
| 166 | + } |
| 167 | + }, |
| 168 | + "expensive": 10 |
| 169 | +} |
| 170 | +``` |
| 171 | +You can configure `content_field = "$.store.book.*"` and the result returned looks like this: |
| 172 | + |
| 173 | +```json |
| 174 | +[ |
| 175 | + { |
| 176 | + "category": "reference", |
| 177 | + "author": "Nigel Rees", |
| 178 | + "title": "Sayings of the Century", |
| 179 | + "price": 8.95 |
| 180 | + }, |
| 181 | + { |
| 182 | + "category": "fiction", |
| 183 | + "author": "Evelyn Waugh", |
| 184 | + "title": "Sword of Honour", |
| 185 | + "price": 12.99 |
| 186 | + } |
| 187 | +] |
| 188 | +``` |
| 189 | +Then you can get the desired result with a simpler schema,like |
| 190 | + |
| 191 | +```hocon |
| 192 | +Http { |
| 193 | + url = "http://mockserver:1080/contentjson/mock" |
| 194 | + method = "GET" |
| 195 | + format = "json" |
| 196 | + content_field = "$.store.book.*" |
| 197 | + schema = { |
| 198 | + fields { |
| 199 | + category = string |
| 200 | + author = string |
| 201 | + title = string |
| 202 | + price = string |
| 203 | + } |
| 204 | + } |
| 205 | +} |
| 206 | +``` |
| 207 | + |
| 208 | +Here is an example: |
| 209 | + |
| 210 | +- Test data can be found at this link [mockserver-contentjson-config.json](../../../../seatunnel-e2e/seatunnel-connector-v2-e2e/connector-http-e2e/src/test/resources/mockserver-contentjson-config.json) |
| 211 | +- See this link for task configuration [http_contentjson_to_assert.conf](../../../../seatunnel-e2e/seatunnel-connector-v2-e2e/connector-http-e2e/src/test/resources/http_contentjson_to_assert.conf). |
| 212 | + |
| 213 | + |
| 214 | +### json_field [Config] |
| 215 | + |
| 216 | +This parameter helps you configure the schema,so this parameter must be used with schema. |
| 217 | + |
| 218 | +If your data looks something like this: |
| 219 | + |
| 220 | +```json |
| 221 | +{ |
| 222 | + "store": { |
| 223 | + "book": [ |
| 224 | + { |
| 225 | + "category": "reference", |
| 226 | + "author": "Nigel Rees", |
| 227 | + "title": "Sayings of the Century", |
| 228 | + "price": 8.95 |
| 229 | + }, |
| 230 | + { |
| 231 | + "category": "fiction", |
| 232 | + "author": "Evelyn Waugh", |
| 233 | + "title": "Sword of Honour", |
| 234 | + "price": 12.99 |
| 235 | + } |
| 236 | + ], |
| 237 | + "bicycle": { |
| 238 | + "color": "red", |
| 239 | + "price": 19.95 |
| 240 | + } |
| 241 | + }, |
| 242 | + "expensive": 10 |
| 243 | +} |
| 244 | +``` |
| 245 | + |
| 246 | +You can get the contents of 'book' by configuring the task as follows: |
| 247 | + |
| 248 | +```hocon |
| 249 | +source { |
| 250 | + Http { |
| 251 | + url = "http://mockserver:1080/jsonpath/mock" |
| 252 | + method = "GET" |
| 253 | + format = "json" |
| 254 | + json_field = { |
| 255 | + category = "$.store.book[*].category" |
| 256 | + author = "$.store.book[*].author" |
| 257 | + title = "$.store.book[*].title" |
| 258 | + price = "$.store.book[*].price" |
| 259 | + } |
| 260 | + schema = { |
| 261 | + fields { |
| 262 | + category = string |
| 263 | + author = string |
| 264 | + title = string |
| 265 | + price = string |
| 266 | + } |
| 267 | + } |
| 268 | + } |
| 269 | +} |
| 270 | +``` |
| 271 | + |
| 272 | +- Test data can be found at this link [mockserver-jsonpath-config.json](../../../../seatunnel-e2e/seatunnel-connector-v2-e2e/connector-http-e2e/src/test/resources/mockserver-jsonpath-config.json) |
| 273 | +- See this link for task configuration [http_jsonpath_to_assert.conf](../../../../seatunnel-e2e/seatunnel-connector-v2-e2e/connector-http-e2e/src/test/resources/http_jsonpath_to_assert.conf). |
| 274 | + |
| 275 | +### common options |
| 276 | + |
| 277 | +Source plugin common parameters, please refer to [Source Common Options](common-options.md) for details |
| 278 | + |
| 279 | +## Example |
| 280 | + |
| 281 | +```hocon |
| 282 | +Notion { |
| 283 | + url = "https://api.notion.com/v1/users" |
| 284 | + password = "Seatunnel-test" |
| 285 | + version = "2022-06-28" |
| 286 | + content_field = "$.results.*" |
| 287 | + schema = { |
| 288 | + fields { |
| 289 | + object = string |
| 290 | + id = string |
| 291 | + type = string |
| 292 | + person = { |
| 293 | + email = string |
| 294 | + } |
| 295 | + avatar_url = string |
| 296 | + } |
| 297 | + } |
| 298 | +} |
| 299 | +``` |
| 300 | + |
| 301 | +## Changelog |
| 302 | + |
| 303 | +### next version |
| 304 | + |
| 305 | +- Add Notion Source Connector |
0 commit comments