monday_ruby 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.env +1 -1
- data/.rubocop.yml +2 -1
- data/CHANGELOG.md +14 -0
- data/CONTRIBUTING.md +104 -0
- data/README.md +146 -142
- data/docs/.vitepress/config.mjs +255 -0
- data/docs/.vitepress/theme/index.js +4 -0
- data/docs/.vitepress/theme/style.css +43 -0
- data/docs/README.md +80 -0
- data/docs/explanation/architecture.md +507 -0
- data/docs/explanation/best-practices/errors.md +478 -0
- data/docs/explanation/best-practices/performance.md +1084 -0
- data/docs/explanation/best-practices/rate-limiting.md +630 -0
- data/docs/explanation/best-practices/testing.md +820 -0
- data/docs/explanation/column-values.md +857 -0
- data/docs/explanation/design.md +795 -0
- data/docs/explanation/graphql.md +356 -0
- data/docs/explanation/migration/v1.md +808 -0
- data/docs/explanation/pagination.md +447 -0
- data/docs/guides/advanced/batch.md +1274 -0
- data/docs/guides/advanced/complex-queries.md +1114 -0
- data/docs/guides/advanced/errors.md +818 -0
- data/docs/guides/advanced/pagination.md +934 -0
- data/docs/guides/advanced/rate-limiting.md +981 -0
- data/docs/guides/authentication.md +286 -0
- data/docs/guides/boards/create.md +386 -0
- data/docs/guides/boards/delete.md +405 -0
- data/docs/guides/boards/duplicate.md +511 -0
- data/docs/guides/boards/query.md +530 -0
- data/docs/guides/boards/update.md +453 -0
- data/docs/guides/columns/create.md +452 -0
- data/docs/guides/columns/metadata.md +492 -0
- data/docs/guides/columns/query.md +455 -0
- data/docs/guides/columns/update-multiple.md +459 -0
- data/docs/guides/columns/update-values.md +509 -0
- data/docs/guides/files/add-to-column.md +40 -0
- data/docs/guides/files/add-to-update.md +37 -0
- data/docs/guides/files/clear-column.md +33 -0
- data/docs/guides/first-request.md +285 -0
- data/docs/guides/folders/manage.md +750 -0
- data/docs/guides/groups/items.md +626 -0
- data/docs/guides/groups/manage.md +501 -0
- data/docs/guides/installation.md +169 -0
- data/docs/guides/items/create.md +493 -0
- data/docs/guides/items/delete.md +514 -0
- data/docs/guides/items/query.md +605 -0
- data/docs/guides/items/subitems.md +483 -0
- data/docs/guides/items/update.md +699 -0
- data/docs/guides/updates/manage.md +619 -0
- data/docs/guides/use-cases/dashboard.md +1421 -0
- data/docs/guides/use-cases/import.md +1962 -0
- data/docs/guides/use-cases/task-management.md +1381 -0
- data/docs/guides/workspaces/manage.md +502 -0
- data/docs/index.md +69 -0
- data/docs/package-lock.json +2468 -0
- data/docs/package.json +13 -0
- data/docs/reference/client.md +540 -0
- data/docs/reference/configuration.md +586 -0
- data/docs/reference/errors.md +693 -0
- data/docs/reference/resources/account.md +208 -0
- data/docs/reference/resources/activity-log.md +369 -0
- data/docs/reference/resources/board-view.md +359 -0
- data/docs/reference/resources/board.md +393 -0
- data/docs/reference/resources/column.md +543 -0
- data/docs/reference/resources/file.md +236 -0
- data/docs/reference/resources/folder.md +386 -0
- data/docs/reference/resources/group.md +507 -0
- data/docs/reference/resources/item.md +348 -0
- data/docs/reference/resources/subitem.md +267 -0
- data/docs/reference/resources/update.md +259 -0
- data/docs/reference/resources/workspace.md +213 -0
- data/docs/reference/response.md +560 -0
- data/docs/tutorial/first-integration.md +713 -0
- data/lib/monday/client.rb +24 -0
- data/lib/monday/configuration.rb +5 -0
- data/lib/monday/request.rb +15 -0
- data/lib/monday/resources/base.rb +4 -0
- data/lib/monday/resources/file.rb +56 -0
- data/lib/monday/util.rb +1 -0
- data/lib/monday/version.rb +1 -1
- metadata +87 -4
|
@@ -0,0 +1,713 @@
|
|
|
1
|
+
# Your First monday.com Integration
|
|
2
|
+
|
|
3
|
+
Build a working monday.com integration from scratch. You'll create a project board, add tasks, and read data back.
|
|
4
|
+
|
|
5
|
+
**Time**: ~15 minutes
|
|
6
|
+
**Level**: Beginner
|
|
7
|
+
|
|
8
|
+
## What You'll Build
|
|
9
|
+
|
|
10
|
+
By the end of this tutorial, you'll have a Ruby script that:
|
|
11
|
+
|
|
12
|
+
- Creates a new project board on monday.com
|
|
13
|
+
- Adds tasks with status and priority columns
|
|
14
|
+
- Retrieves and displays the data
|
|
15
|
+
- Handles errors gracefully
|
|
16
|
+
|
|
17
|
+
This covers the fundamentals you'll use in any monday.com integration.
|
|
18
|
+
|
|
19
|
+
## Prerequisites
|
|
20
|
+
|
|
21
|
+
Before starting, make sure you have:
|
|
22
|
+
|
|
23
|
+
- **Ruby 2.7 or higher** installed
|
|
24
|
+
- **A monday.com account** (free trial works)
|
|
25
|
+
- **Basic Ruby knowledge** (variables, methods, hashes)
|
|
26
|
+
- **10-15 minutes** of focused time
|
|
27
|
+
|
|
28
|
+
## Step 1: Installation
|
|
29
|
+
|
|
30
|
+
Install the monday_ruby gem:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
gem install monday_ruby
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Verify the installation by checking the version:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
gem list monday_ruby
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
You should see `monday_ruby` in the output with a version number.
|
|
43
|
+
|
|
44
|
+
## Step 2: Get Your API Token
|
|
45
|
+
|
|
46
|
+
Every request to monday.com requires authentication. Here's how to get your token:
|
|
47
|
+
|
|
48
|
+
1. Log in to your monday.com account
|
|
49
|
+
2. Click your profile picture in the top-right corner
|
|
50
|
+
3. Select **Administration**
|
|
51
|
+
4. Go to the **Connections** section
|
|
52
|
+
5. Select **Personal API token** in the sidebar
|
|
53
|
+
5. Copy your **Personal API Token**
|
|
54
|
+
|
|
55
|
+
::: warning <span style="display: inline-flex; align-items: center; gap: 6px;"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="11" width="18" height="11" rx="2" ry="2"></rect><path d="M7 11V7a5 5 0 0 1 10 0v4"></path></svg>Security</span>
|
|
56
|
+
Keep your API token secret. Never commit it to version control or share it publicly.
|
|
57
|
+
:::
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
### Set Up Environment Variable
|
|
62
|
+
|
|
63
|
+
Create a file called `.env` in your project directory:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
# .env
|
|
67
|
+
MONDAY_TOKEN=your_actual_token_here
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
We'll use this to keep your token secure.
|
|
71
|
+
|
|
72
|
+
## Step 3: Create Your First Board
|
|
73
|
+
|
|
74
|
+
Let's write a script that creates a project board.
|
|
75
|
+
|
|
76
|
+
Create a new file called `monday_tutorial.rb`:
|
|
77
|
+
|
|
78
|
+
```ruby
|
|
79
|
+
require "monday_ruby"
|
|
80
|
+
require "dotenv/load"
|
|
81
|
+
|
|
82
|
+
# Configure the client with your token
|
|
83
|
+
Monday.configure do |config|
|
|
84
|
+
config.token = ENV["MONDAY_TOKEN"]
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# Initialize the client
|
|
88
|
+
client = Monday::Client.new
|
|
89
|
+
|
|
90
|
+
# Create a new board
|
|
91
|
+
response = client.board.create(
|
|
92
|
+
args: {
|
|
93
|
+
board_name: "My Project Tasks",
|
|
94
|
+
board_kind: :public
|
|
95
|
+
},
|
|
96
|
+
select: ["id", "name"]
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
if response.success?
|
|
100
|
+
board = response.body.dig("data", "create_board")
|
|
101
|
+
puts "✓ Created board: #{board['name']} (ID: #{board['id']})"
|
|
102
|
+
puts "Board ID: #{board['id']} - Save this, we'll need it!"
|
|
103
|
+
else
|
|
104
|
+
puts "✗ Error creating board: #{response.code}"
|
|
105
|
+
puts response.body
|
|
106
|
+
end
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Install the dotenv gem to load environment variables:
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
gem install dotenv
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Run your script:
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
ruby monday_tutorial.rb
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
**Expected output:**
|
|
122
|
+
```
|
|
123
|
+
✓ Created board: My Project Tasks (ID: 1234567890)
|
|
124
|
+
Board ID: 1234567890 - Save this, we'll need it!
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
::: tip <span style="display: inline-flex; align-items: center; gap: 6px;"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"></path><polyline points="22 4 12 14.01 9 11.01"></polyline></svg>Verify in monday.com</span>
|
|
128
|
+
Open monday.com in your browser. You should see your new "My Project Tasks" board!
|
|
129
|
+
:::
|
|
130
|
+
|
|
131
|
+
## Step 4: Add Tasks to Your Board
|
|
132
|
+
|
|
133
|
+
Now let's add some tasks to the board. We'll start simple by creating items with just names:
|
|
134
|
+
|
|
135
|
+
```ruby
|
|
136
|
+
require "monday_ruby"
|
|
137
|
+
require "dotenv/load"
|
|
138
|
+
|
|
139
|
+
Monday.configure do |config|
|
|
140
|
+
config.token = ENV["MONDAY_TOKEN"]
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
client = Monday::Client.new
|
|
144
|
+
|
|
145
|
+
# Replace with your board ID from Step 3
|
|
146
|
+
BOARD_ID = 1234567890
|
|
147
|
+
|
|
148
|
+
# Create three tasks
|
|
149
|
+
tasks = ["Design database schema", "Set up development environment", "Write API documentation"]
|
|
150
|
+
|
|
151
|
+
puts "Creating tasks..."
|
|
152
|
+
|
|
153
|
+
tasks.each do |task_name|
|
|
154
|
+
response = client.item.create(
|
|
155
|
+
args: {
|
|
156
|
+
board_id: BOARD_ID,
|
|
157
|
+
item_name: task_name
|
|
158
|
+
},
|
|
159
|
+
select: ["id", "name"]
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
if response.success?
|
|
163
|
+
item = response.body.dig("data", "create_item")
|
|
164
|
+
puts "✓ Created: #{item['name']}"
|
|
165
|
+
else
|
|
166
|
+
puts "✗ Failed to create: #{task_name}"
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
puts "\nAll tasks created!"
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Run the script:
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
ruby monday_tutorial.rb
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
**Expected output:**
|
|
180
|
+
```
|
|
181
|
+
Creating tasks...
|
|
182
|
+
✓ Created: Design database schema
|
|
183
|
+
✓ Created: Set up development environment
|
|
184
|
+
✓ Created: Write API documentation
|
|
185
|
+
|
|
186
|
+
All tasks created!
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Check your board on monday.com - you should see all three tasks!
|
|
190
|
+
|
|
191
|
+
## Step 5: Discover Column IDs
|
|
192
|
+
|
|
193
|
+
Before we can update column values, we need to discover what columns exist on the board and their IDs:
|
|
194
|
+
|
|
195
|
+
```ruby
|
|
196
|
+
require "monday_ruby"
|
|
197
|
+
require "dotenv/load"
|
|
198
|
+
|
|
199
|
+
Monday.configure do |config|
|
|
200
|
+
config.token = ENV["MONDAY_TOKEN"]
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
client = Monday::Client.new
|
|
204
|
+
|
|
205
|
+
BOARD_ID = 1234567890 # Your board ID
|
|
206
|
+
|
|
207
|
+
# Query the board to get column information
|
|
208
|
+
response = client.board.query(
|
|
209
|
+
args: { ids: [BOARD_ID] },
|
|
210
|
+
select: [
|
|
211
|
+
"name",
|
|
212
|
+
{
|
|
213
|
+
columns: ["id", "title", "type"]
|
|
214
|
+
}
|
|
215
|
+
]
|
|
216
|
+
)
|
|
217
|
+
|
|
218
|
+
if response.success?
|
|
219
|
+
board = response.body.dig("data", "boards", 0)
|
|
220
|
+
|
|
221
|
+
puts "\n📋 Board: #{board['name']}"
|
|
222
|
+
puts "=" * 50
|
|
223
|
+
puts "\nAvailable Columns:"
|
|
224
|
+
|
|
225
|
+
board["columns"].each do |column|
|
|
226
|
+
puts " • #{column['title']} (ID: #{column['id']}, Type: #{column['type']})"
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
puts "\n" + "=" * 50
|
|
230
|
+
else
|
|
231
|
+
puts "✗ Error fetching board"
|
|
232
|
+
puts response.body
|
|
233
|
+
end
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
Run the script:
|
|
237
|
+
|
|
238
|
+
```bash
|
|
239
|
+
ruby monday_tutorial.rb
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
**Expected output:**
|
|
243
|
+
```
|
|
244
|
+
📋 Board: My Project Tasks
|
|
245
|
+
==================================================
|
|
246
|
+
|
|
247
|
+
Available Columns:
|
|
248
|
+
• Name (ID: name, Type: name)
|
|
249
|
+
• Status (ID: status__1, Type: color)
|
|
250
|
+
• Person (ID: person__1, Type: multiple-person)
|
|
251
|
+
• Date (ID: date4__1, Type: date)
|
|
252
|
+
|
|
253
|
+
==================================================
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
::: tip <span style="display: inline-flex; align-items: center; gap: 6px;"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="16" x2="12" y2="12"></line><line x1="12" y1="8" x2="12.01" y2="8"></line></svg>Column IDs</span>
|
|
257
|
+
Notice that column IDs have auto-generated suffixes like `__1` or random characters (e.g., `status__1`, `color_a8d9f`). The Status column type is `color`, not `status`. Always query the board first to discover the actual column IDs before updating values.
|
|
258
|
+
:::
|
|
259
|
+
|
|
260
|
+
## Step 6: Update Column Values
|
|
261
|
+
|
|
262
|
+
Now that we know the column IDs, let's update the status for our tasks.
|
|
263
|
+
|
|
264
|
+
**Important**: Replace `status__1` below with the actual Status column ID you saw in Step 5:
|
|
265
|
+
|
|
266
|
+
```ruby
|
|
267
|
+
require "monday_ruby"
|
|
268
|
+
require "dotenv/load"
|
|
269
|
+
|
|
270
|
+
Monday.configure do |config|
|
|
271
|
+
config.token = ENV["MONDAY_TOKEN"]
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
client = Monday::Client.new
|
|
275
|
+
|
|
276
|
+
BOARD_ID = 1234567890 # Your board ID
|
|
277
|
+
STATUS_COLUMN_ID = "status__1" # Replace with your actual Status column ID from Step 5
|
|
278
|
+
|
|
279
|
+
# First, get the items
|
|
280
|
+
response = client.board.query(
|
|
281
|
+
args: { ids: [BOARD_ID] },
|
|
282
|
+
select: [
|
|
283
|
+
{
|
|
284
|
+
items: ["id", "name"]
|
|
285
|
+
}
|
|
286
|
+
]
|
|
287
|
+
)
|
|
288
|
+
|
|
289
|
+
if response.success?
|
|
290
|
+
board = response.body.dig("data", "boards", 0)
|
|
291
|
+
items = board["items"]
|
|
292
|
+
|
|
293
|
+
puts "Updating task statuses...\n"
|
|
294
|
+
|
|
295
|
+
# Update each item's status
|
|
296
|
+
items.each_with_index do |item, index|
|
|
297
|
+
status_labels = ["Working on it", "Done", "Stuck"]
|
|
298
|
+
|
|
299
|
+
update_response = client.column.update_value(
|
|
300
|
+
args: {
|
|
301
|
+
item_id: item["id"],
|
|
302
|
+
board_id: BOARD_ID,
|
|
303
|
+
column_id: STATUS_COLUMN_ID,
|
|
304
|
+
value: { label: status_labels[index] }
|
|
305
|
+
}
|
|
306
|
+
)
|
|
307
|
+
|
|
308
|
+
if update_response.success?
|
|
309
|
+
puts "✓ Updated: #{item['name']} → #{status_labels[index]}"
|
|
310
|
+
else
|
|
311
|
+
puts "✗ Failed to update: #{item['name']}"
|
|
312
|
+
end
|
|
313
|
+
end
|
|
314
|
+
|
|
315
|
+
puts "\nAll statuses updated!"
|
|
316
|
+
else
|
|
317
|
+
puts "✗ Error fetching items"
|
|
318
|
+
end
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
Run the script:
|
|
322
|
+
|
|
323
|
+
```bash
|
|
324
|
+
ruby monday_tutorial.rb
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
**Expected output:**
|
|
328
|
+
```
|
|
329
|
+
Updating task statuses...
|
|
330
|
+
|
|
331
|
+
✓ Updated: Design database schema → Working on it
|
|
332
|
+
✓ Updated: Set up development environment → Done
|
|
333
|
+
✓ Updated: Write API documentation → Stuck
|
|
334
|
+
|
|
335
|
+
All statuses updated!
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
Check your board on monday.com - you should now see the status labels on each task!
|
|
339
|
+
|
|
340
|
+
## Step 7: Read Data Back
|
|
341
|
+
|
|
342
|
+
Now let's query the board to see all our items with their column values:
|
|
343
|
+
|
|
344
|
+
```ruby
|
|
345
|
+
require "monday_ruby"
|
|
346
|
+
require "dotenv/load"
|
|
347
|
+
|
|
348
|
+
Monday.configure do |config|
|
|
349
|
+
config.token = ENV["MONDAY_TOKEN"]
|
|
350
|
+
end
|
|
351
|
+
|
|
352
|
+
client = Monday::Client.new
|
|
353
|
+
|
|
354
|
+
BOARD_ID = 1234567890 # Your board ID
|
|
355
|
+
|
|
356
|
+
# Query the board with items and column values
|
|
357
|
+
response = client.board.query(
|
|
358
|
+
args: { ids: [BOARD_ID] },
|
|
359
|
+
select: [
|
|
360
|
+
"name",
|
|
361
|
+
{
|
|
362
|
+
items: [
|
|
363
|
+
"id",
|
|
364
|
+
"name",
|
|
365
|
+
{
|
|
366
|
+
column_values: ["id", "text", "title"]
|
|
367
|
+
}
|
|
368
|
+
]
|
|
369
|
+
}
|
|
370
|
+
]
|
|
371
|
+
)
|
|
372
|
+
|
|
373
|
+
if response.success?
|
|
374
|
+
board = response.body.dig("data", "boards", 0)
|
|
375
|
+
|
|
376
|
+
puts "\n📋 Board: #{board['name']}"
|
|
377
|
+
puts "=" * 50
|
|
378
|
+
|
|
379
|
+
board["items"].each do |item|
|
|
380
|
+
puts "\n#{item['name']}"
|
|
381
|
+
|
|
382
|
+
# Find and display the status column
|
|
383
|
+
status = item["column_values"].find { |col| col["title"] == "Status" }
|
|
384
|
+
if status
|
|
385
|
+
puts " Status: #{status['text']}"
|
|
386
|
+
end
|
|
387
|
+
end
|
|
388
|
+
|
|
389
|
+
puts "\n" + "=" * 50
|
|
390
|
+
puts "Total tasks: #{board['items'].length}"
|
|
391
|
+
else
|
|
392
|
+
puts "✗ Error fetching board"
|
|
393
|
+
puts response.body
|
|
394
|
+
end
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
Run the script:
|
|
398
|
+
|
|
399
|
+
```bash
|
|
400
|
+
ruby monday_tutorial.rb
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
**Expected output:**
|
|
404
|
+
```
|
|
405
|
+
📋 Board: My Project Tasks
|
|
406
|
+
==================================================
|
|
407
|
+
|
|
408
|
+
Design database schema
|
|
409
|
+
Status: Working on it
|
|
410
|
+
|
|
411
|
+
Set up development environment
|
|
412
|
+
Status: Done
|
|
413
|
+
|
|
414
|
+
Write API documentation
|
|
415
|
+
Status: Stuck
|
|
416
|
+
|
|
417
|
+
==================================================
|
|
418
|
+
Total tasks: 3
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
---
|
|
422
|
+
|
|
423
|
+
## Step 8: Handle Errors
|
|
424
|
+
|
|
425
|
+
Professional integrations need error handling. Let's add it:
|
|
426
|
+
|
|
427
|
+
```ruby
|
|
428
|
+
require "monday_ruby"
|
|
429
|
+
require "dotenv/load"
|
|
430
|
+
|
|
431
|
+
Monday.configure do |config|
|
|
432
|
+
config.token = ENV["MONDAY_TOKEN"]
|
|
433
|
+
end
|
|
434
|
+
|
|
435
|
+
client = Monday::Client.new
|
|
436
|
+
|
|
437
|
+
BOARD_ID = 1234567890
|
|
438
|
+
|
|
439
|
+
def create_task(client, board_id, task_name, status)
|
|
440
|
+
response = client.item.create(
|
|
441
|
+
args: {
|
|
442
|
+
board_id: board_id,
|
|
443
|
+
item_name: task_name,
|
|
444
|
+
column_values: {
|
|
445
|
+
status: { label: status }
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
)
|
|
449
|
+
|
|
450
|
+
if response.success?
|
|
451
|
+
item = response.body.dig("data", "create_item")
|
|
452
|
+
puts "✓ Created: #{item['name']}"
|
|
453
|
+
true
|
|
454
|
+
else
|
|
455
|
+
puts "✗ Failed to create: #{task_name}"
|
|
456
|
+
puts " Error code: #{response.code}"
|
|
457
|
+
false
|
|
458
|
+
end
|
|
459
|
+
rescue Monday::AuthorizationError
|
|
460
|
+
puts "✗ Authentication failed. Check your API token."
|
|
461
|
+
false
|
|
462
|
+
rescue Monday::Error => e
|
|
463
|
+
puts "✗ monday.com API error: #{e.message}"
|
|
464
|
+
false
|
|
465
|
+
rescue StandardError => e
|
|
466
|
+
puts "✗ Unexpected error: #{e.message}"
|
|
467
|
+
false
|
|
468
|
+
end
|
|
469
|
+
|
|
470
|
+
# Test error handling
|
|
471
|
+
puts "Creating task with proper error handling..."
|
|
472
|
+
create_task(client, BOARD_ID, "Test task", "Working on it")
|
|
473
|
+
|
|
474
|
+
# Test with invalid board ID
|
|
475
|
+
puts "\nTesting error handling with invalid board..."
|
|
476
|
+
create_task(client, 999999999, "This will fail", "Working on it")
|
|
477
|
+
```
|
|
478
|
+
|
|
479
|
+
Run it:
|
|
480
|
+
|
|
481
|
+
```bash
|
|
482
|
+
ruby monday_tutorial.rb
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
**Expected output:**
|
|
486
|
+
```
|
|
487
|
+
Creating task with proper error handling...
|
|
488
|
+
✓ Created: Test task
|
|
489
|
+
|
|
490
|
+
Testing error handling with invalid board...
|
|
491
|
+
✗ Failed to create: This will fail
|
|
492
|
+
Error code: 200
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
::: tip <span style="display: inline-flex; align-items: center; gap: 6px;"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="16" x2="12" y2="12"></line><line x1="12" y1="8" x2="12.01" y2="8"></line></svg>Error Types</span>
|
|
496
|
+
monday_ruby provides specific error classes:
|
|
497
|
+
- `Monday::AuthorizationError` - Invalid token
|
|
498
|
+
- `Monday::ResourceNotFoundError` - Board/item doesn't exist
|
|
499
|
+
- `Monday::RateLimitError` - Too many requests
|
|
500
|
+
- `Monday::Error` - General API errors
|
|
501
|
+
:::
|
|
502
|
+
|
|
503
|
+
## Complete Script
|
|
504
|
+
|
|
505
|
+
Here's the final, production-ready version with everything combined:
|
|
506
|
+
|
|
507
|
+
```ruby
|
|
508
|
+
require "monday_ruby"
|
|
509
|
+
require "dotenv/load"
|
|
510
|
+
|
|
511
|
+
# Configure client
|
|
512
|
+
Monday.configure do |config|
|
|
513
|
+
config.token = ENV["MONDAY_TOKEN"]
|
|
514
|
+
end
|
|
515
|
+
|
|
516
|
+
client = Monday::Client.new
|
|
517
|
+
|
|
518
|
+
def create_board(client, name)
|
|
519
|
+
response = client.board.create(
|
|
520
|
+
args: { board_name: name, board_kind: :public },
|
|
521
|
+
select: ["id", "name"]
|
|
522
|
+
)
|
|
523
|
+
|
|
524
|
+
if response.success?
|
|
525
|
+
board = response.body.dig("data", "create_board")
|
|
526
|
+
puts "✓ Created board: #{board['name']} (ID: #{board['id']})"
|
|
527
|
+
board['id'].to_i
|
|
528
|
+
else
|
|
529
|
+
puts "✗ Failed to create board"
|
|
530
|
+
nil
|
|
531
|
+
end
|
|
532
|
+
rescue Monday::Error => e
|
|
533
|
+
puts "✗ Error: #{e.message}"
|
|
534
|
+
nil
|
|
535
|
+
end
|
|
536
|
+
|
|
537
|
+
def create_task(client, board_id, name)
|
|
538
|
+
response = client.item.create(
|
|
539
|
+
args: {
|
|
540
|
+
board_id: board_id,
|
|
541
|
+
item_name: name
|
|
542
|
+
}
|
|
543
|
+
)
|
|
544
|
+
|
|
545
|
+
if response.success?
|
|
546
|
+
item = response.body.dig("data", "create_item")
|
|
547
|
+
puts "✓ Created task: #{item['name']}"
|
|
548
|
+
true
|
|
549
|
+
else
|
|
550
|
+
puts "✗ Failed to create task: #{name}"
|
|
551
|
+
false
|
|
552
|
+
end
|
|
553
|
+
rescue Monday::Error => e
|
|
554
|
+
puts "✗ Error creating task: #{e.message}"
|
|
555
|
+
false
|
|
556
|
+
end
|
|
557
|
+
|
|
558
|
+
def update_task_status(client, board_id, item_id, column_id, status)
|
|
559
|
+
response = client.column.update_value(
|
|
560
|
+
args: {
|
|
561
|
+
item_id: item_id,
|
|
562
|
+
board_id: board_id,
|
|
563
|
+
column_id: column_id,
|
|
564
|
+
value: { label: status }
|
|
565
|
+
}
|
|
566
|
+
)
|
|
567
|
+
|
|
568
|
+
if response.success?
|
|
569
|
+
puts "✓ Updated status: #{status}"
|
|
570
|
+
true
|
|
571
|
+
else
|
|
572
|
+
puts "✗ Failed to update status"
|
|
573
|
+
false
|
|
574
|
+
end
|
|
575
|
+
rescue Monday::Error => e
|
|
576
|
+
puts "✗ Error updating status: #{e.message}"
|
|
577
|
+
false
|
|
578
|
+
end
|
|
579
|
+
|
|
580
|
+
def display_board(client, board_id)
|
|
581
|
+
response = client.board.query(
|
|
582
|
+
args: { ids: [board_id] },
|
|
583
|
+
select: [
|
|
584
|
+
"name",
|
|
585
|
+
{ items: ["id", "name", { column_values: ["id", "text", "title"] }] }
|
|
586
|
+
]
|
|
587
|
+
)
|
|
588
|
+
|
|
589
|
+
if response.success?
|
|
590
|
+
board = response.body.dig("data", "boards", 0)
|
|
591
|
+
|
|
592
|
+
puts "\n📋 #{board['name']}"
|
|
593
|
+
puts "=" * 50
|
|
594
|
+
|
|
595
|
+
board["items"].each do |item|
|
|
596
|
+
status = item["column_values"].find { |c| c["title"] == "Status" }
|
|
597
|
+
puts "• #{item['name']} - #{status&.dig('text') || 'No status'}"
|
|
598
|
+
end
|
|
599
|
+
|
|
600
|
+
puts "=" * 50
|
|
601
|
+
board["items"]
|
|
602
|
+
else
|
|
603
|
+
puts "✗ Failed to fetch board"
|
|
604
|
+
[]
|
|
605
|
+
end
|
|
606
|
+
rescue Monday::Error => e
|
|
607
|
+
puts "✗ Error: #{e.message}"
|
|
608
|
+
[]
|
|
609
|
+
end
|
|
610
|
+
|
|
611
|
+
# Main execution
|
|
612
|
+
puts "🚀 Building your first monday.com integration\n\n"
|
|
613
|
+
|
|
614
|
+
# Step 1: Create board
|
|
615
|
+
board_id = create_board(client, "My Project Tasks")
|
|
616
|
+
exit unless board_id
|
|
617
|
+
|
|
618
|
+
puts "\n"
|
|
619
|
+
|
|
620
|
+
# Step 2: Add tasks
|
|
621
|
+
tasks = ["Design database schema", "Set up development environment", "Write API documentation"]
|
|
622
|
+
|
|
623
|
+
item_ids = []
|
|
624
|
+
tasks.each do |task_name|
|
|
625
|
+
if create_task(client, board_id, task_name)
|
|
626
|
+
# Get the created item's ID
|
|
627
|
+
items = display_board(client, board_id)
|
|
628
|
+
item_ids = items.map { |item| item["id"] }
|
|
629
|
+
end
|
|
630
|
+
end
|
|
631
|
+
|
|
632
|
+
puts "\n"
|
|
633
|
+
|
|
634
|
+
# Step 3: Discover the Status column ID
|
|
635
|
+
columns_response = client.board.query(
|
|
636
|
+
args: { ids: [board_id] },
|
|
637
|
+
select: [{ columns: ["id", "title", "type"] }]
|
|
638
|
+
)
|
|
639
|
+
|
|
640
|
+
status_column_id = nil
|
|
641
|
+
if columns_response.success?
|
|
642
|
+
board = columns_response.body.dig("data", "boards", 0)
|
|
643
|
+
status_column = board["columns"].find { |col| col["title"] == "Status" }
|
|
644
|
+
status_column_id = status_column["id"] if status_column
|
|
645
|
+
puts "Found Status column ID: #{status_column_id}"
|
|
646
|
+
end
|
|
647
|
+
|
|
648
|
+
puts "\n"
|
|
649
|
+
|
|
650
|
+
# Step 4: Update task statuses
|
|
651
|
+
if status_column_id
|
|
652
|
+
statuses = ["Working on it", "Done", "Stuck"]
|
|
653
|
+
item_ids.each_with_index do |item_id, index|
|
|
654
|
+
update_task_status(client, board_id, item_id, status_column_id, statuses[index])
|
|
655
|
+
end
|
|
656
|
+
else
|
|
657
|
+
puts "⚠ Could not find Status column. Skipping status updates."
|
|
658
|
+
end
|
|
659
|
+
|
|
660
|
+
# Step 5: Display final results
|
|
661
|
+
display_board(client, board_id)
|
|
662
|
+
|
|
663
|
+
puts "\n✨ Integration complete! Check monday.com to see your board."
|
|
664
|
+
```
|
|
665
|
+
|
|
666
|
+
## What You've Learned
|
|
667
|
+
|
|
668
|
+
Congratulations! You've built a complete monday.com integration. Here's what you now know:
|
|
669
|
+
|
|
670
|
+
<span style="display: inline-flex; align-items: center; gap: 8px;"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"></path><polyline points="22 4 12 14.01 9 11.01"></polyline></svg>**Installing and configuring** monday_ruby</span>
|
|
671
|
+
|
|
672
|
+
<span style="display: inline-flex; align-items: center; gap: 8px;"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"></path><polyline points="22 4 12 14.01 9 11.01"></polyline></svg>**Authenticating** with the API</span>
|
|
673
|
+
|
|
674
|
+
<span style="display: inline-flex; align-items: center; gap: 8px;"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"></path><polyline points="22 4 12 14.01 9 11.01"></polyline></svg>**Creating boards** programmatically</span>
|
|
675
|
+
|
|
676
|
+
<span style="display: inline-flex; align-items: center; gap: 8px;"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"></path><polyline points="22 4 12 14.01 9 11.01"></polyline></svg>**Adding items** to boards</span>
|
|
677
|
+
|
|
678
|
+
<span style="display: inline-flex; align-items: center; gap: 8px;"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"></path><polyline points="22 4 12 14.01 9 11.01"></polyline></svg>**Discovering column IDs** dynamically</span>
|
|
679
|
+
|
|
680
|
+
<span style="display: inline-flex; align-items: center; gap: 8px;"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"></path><polyline points="22 4 12 14.01 9 11.01"></polyline></svg>**Updating column values** on items</span>
|
|
681
|
+
|
|
682
|
+
<span style="display: inline-flex; align-items: center; gap: 8px;"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"></path><polyline points="22 4 12 14.01 9 11.01"></polyline></svg>**Querying data** and parsing responses</span>
|
|
683
|
+
|
|
684
|
+
<span style="display: inline-flex; align-items: center; gap: 8px;"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"></path><polyline points="22 4 12 14.01 9 11.01"></polyline></svg>**Handling errors** gracefully</span>
|
|
685
|
+
|
|
686
|
+
## Next Steps
|
|
687
|
+
|
|
688
|
+
Now that you understand the basics, explore more:
|
|
689
|
+
|
|
690
|
+
### Learn More Operations
|
|
691
|
+
- [Update board settings](/guides/boards/update)
|
|
692
|
+
- [Work with different column types](/guides/columns/update-values)
|
|
693
|
+
- [Handle pagination for large datasets](/guides/advanced/pagination)
|
|
694
|
+
|
|
695
|
+
### Build Real Use Cases
|
|
696
|
+
- [Task management integration](/guides/use-cases/task-management)
|
|
697
|
+
- [Automated reporting dashboard](/guides/use-cases/dashboard)
|
|
698
|
+
- [Data import from CSV/JSON](/guides/use-cases/import)
|
|
699
|
+
|
|
700
|
+
### Deep Dive
|
|
701
|
+
- [Understand the architecture](/explanation/architecture)
|
|
702
|
+
- [Learn GraphQL query building](/explanation/graphql)
|
|
703
|
+
- [Best practices for production](/explanation/best-practices/errors)
|
|
704
|
+
|
|
705
|
+
## Get Help
|
|
706
|
+
|
|
707
|
+
Stuck? Here's how to get help:
|
|
708
|
+
|
|
709
|
+
- **Check the [how-to guides](/guides/installation)** for specific tasks
|
|
710
|
+
- **Browse the [API reference](/reference/client)** for detailed documentation
|
|
711
|
+
- **Open an issue** on [GitHub](https://github.com/sanifhimani/monday_ruby/issues)
|
|
712
|
+
|
|
713
|
+
Happy coding! 🎉
|