Skip to content

Commit e73f69d

Browse files
authored
new demo tasks to support oAuth (#509)
1 parent 324cb2e commit e73f69d

File tree

11 files changed

+818
-0
lines changed

11 files changed

+818
-0
lines changed

docs/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,15 @@ This directory is built automatically. Each task's documentation is generated fr
189189
* [Demonstration, Tutorial: Fetch data from a shared Google sheet](./demonstration-fetch-data-from-a-shared-google-sheet)
190190
* [Demonstration: Add new orders to a Google Sheet](./demonstration-add-new-orders-to-google-sheet)
191191
* [Demonstration: Auto-tag new orders, with scheduled reconciliation](./demonstration-auto-tag-new-orders-with-reconciliation)
192+
* [Demonstration: Create and update a table in Airtable](./demonstration-create-and-update-a-table-in-airtable)
193+
* [Demonstration: Create sheets and list and create files in Google Drive](./demonstration-create-sheets-and-list-and-create-files-in-google-drive)
192194
* [Demonstration: Fetch an external configuration file](./demonstration-fetch-an-external-configuration-file)
193195
* [Demonstration: Fulfillment order move](./demonstration-fulfillment-order-move)
194196
* [Demonstration: Generate product sales report PDF with pie chart](./demonstration-generate-product-sales-report-pdf-with-pie-chart)
195197
* [Demonstration: Generating a file and uploading it to Shopify](./demonstration-generate-a-file-and-upload-to-shopify)
196198
* [Demonstration: Order editing](./demonstration-order-editing)
197199
* [Demonstration: Performing action runs in sequence](./demonstration-performing-action-runs-in-sequence)
200+
* [Demonstration: Post to a Slack channel](./demonstration-post-to-a-slack-channel)
198201
* [Demonstration: Query external paginated API](./demonstration-query-external-paginated-api)
199202
* [Demonstration: Shopify Flow integration](./demonstration-shopify-flow-integration)
200203
* [Demonstration: Trigger a custom event for specific product or variant changes](./demonstration-trigger-a-custom-event-for-specific-product-or-variant-changes)
@@ -394,6 +397,10 @@ This directory is built automatically. Each task's documentation is generated fr
394397

395398
* [Auto-tag products by age](./auto-tag-new-products-by-age)
396399

400+
### Airtable
401+
402+
* [Demonstration: Create and update a table in Airtable](./demonstration-create-and-update-a-table-in-airtable)
403+
397404
### Alert
398405

399406
* [Alert when daily order limit is reached](./alert-when-daily-order-limit-is-reached)
@@ -765,12 +772,15 @@ This directory is built automatically. Each task's documentation is generated fr
765772
* [Demonstration, Tutorial: Fetch data from a shared Google sheet](./demonstration-fetch-data-from-a-shared-google-sheet)
766773
* [Demonstration: Add new orders to a Google Sheet](./demonstration-add-new-orders-to-google-sheet)
767774
* [Demonstration: Auto-tag new orders, with scheduled reconciliation](./demonstration-auto-tag-new-orders-with-reconciliation)
775+
* [Demonstration: Create and update a table in Airtable](./demonstration-create-and-update-a-table-in-airtable)
776+
* [Demonstration: Create sheets and list and create files in Google Drive](./demonstration-create-sheets-and-list-and-create-files-in-google-drive)
768777
* [Demonstration: Fetch an external configuration file](./demonstration-fetch-an-external-configuration-file)
769778
* [Demonstration: Fulfillment order move](./demonstration-fulfillment-order-move)
770779
* [Demonstration: Generate product sales report PDF with pie chart](./demonstration-generate-product-sales-report-pdf-with-pie-chart)
771780
* [Demonstration: Generating a file and uploading it to Shopify](./demonstration-generate-a-file-and-upload-to-shopify)
772781
* [Demonstration: Order editing](./demonstration-order-editing)
773782
* [Demonstration: Performing action runs in sequence](./demonstration-performing-action-runs-in-sequence)
783+
* [Demonstration: Post to a Slack channel](./demonstration-post-to-a-slack-channel)
774784
* [Demonstration: Query external paginated API](./demonstration-query-external-paginated-api)
775785
* [Demonstration: Shopify Flow integration](./demonstration-shopify-flow-integration)
776786
* [Demonstration: Trigger a custom event for specific product or variant changes](./demonstration-trigger-a-custom-event-for-specific-product-or-variant-changes)
@@ -950,12 +960,14 @@ This directory is built automatically. Each task's documentation is generated fr
950960

951961
### Google Drive
952962

963+
* [Demonstration: Create sheets and list and create files in Google Drive](./demonstration-create-sheets-and-list-and-create-files-in-google-drive)
953964
* [Demonstration: Upload files to Google Drive](./demonstration-upload-files-to-google-drive)
954965

955966
### Google Sheets
956967

957968
* [Add new Shopify Forms submissions to a Google Sheet](./add-new-shopify-forms-submissions-to-a-google-sheet)
958969
* [Demonstration: Add new orders to a Google Sheet](./demonstration-add-new-orders-to-google-sheet)
970+
* [Demonstration: Create sheets and list and create files in Google Drive](./demonstration-create-sheets-and-list-and-create-files-in-google-drive)
959971

960972
### HTTP
961973

@@ -981,6 +993,9 @@ This directory is built automatically. Each task's documentation is generated fr
981993
### Integration
982994

983995
* [Bulk trigger Shopify Flow with historical data](./bulk-trigger-shopify-flow-with-historical-data)
996+
* [Demonstration: Create and update a table in Airtable](./demonstration-create-and-update-a-table-in-airtable)
997+
* [Demonstration: Create sheets and list and create files in Google Drive](./demonstration-create-sheets-and-list-and-create-files-in-google-drive)
998+
* [Demonstration: Post to a Slack channel](./demonstration-post-to-a-slack-channel)
984999
* [Demonstration: Shopify Flow integration](./demonstration-shopify-flow-integration)
9851000
* [Report Toaster: Pirate Ship Integration](./report-toaster-pirateship-integration)
9861001
* [Report Toaster: ShipStation Integration](./report-toaster-shipstation-integration)
@@ -1623,6 +1638,7 @@ This directory is built automatically. Each task's documentation is generated fr
16231638

16241639
### Slack
16251640

1641+
* [Demonstration: Post to a Slack channel](./demonstration-post-to-a-slack-channel)
16261642
* [Report Toaster: Deliver report PDF via email or Slack](./report-toaster-deliver-report-pdf-via-email-or-slack)
16271643
* [Send a message to Slack](./send-a-message-to-slack)
16281644

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Demonstration: Create and update a table in Airtable
2+
3+
Tags: Airtable, Demonstration, Integration
4+
5+
# Demonstration: Create and update a table in Airtable
6+
7+
* View in the task library: [tasks.mechanic.dev/demonstration-create-and-update-a-table-in-airtable](https://tasks.mechanic.dev/demonstration-create-and-update-a-table-in-airtable)
8+
* Task JSON, for direct import: [task.json](../../tasks/demonstration-create-and-update-a-table-in-airtable.json)
9+
* Preview task code: [script.liquid](./script.liquid)
10+
11+
## Default options
12+
13+
```json
14+
{
15+
"airtable_account__required": null,
16+
"airtable_base_id__required": null
17+
}
18+
```
19+
20+
[Learn about task options in Mechanic](https://learn.mechanic.dev/core/tasks/options)
21+
22+
## Subscriptions
23+
24+
```liquid
25+
mechanic/user/trigger
26+
mechanic/actions/perform
27+
```
28+
29+
[Learn about event subscriptions in Mechanic](https://learn.mechanic.dev/core/tasks/subscriptions)
30+
31+
## Documentation
32+
33+
# Demonstration: Create and update a table in Airtable
34+
35+
This task creates a new table in the Airtable base of your choice, and then populates it with demo data. Try it out to learn how the Airtable action works!
36+
37+
## Quick Start
38+
39+
1. Connect your Airtable account (Settings → Authentication → Airtable)
40+
- For this demonstration you will need to grant the "Write Records" and "Write Base Schema
41+
" scopes. Don't forget to adjust these scopes as you progress beyond this demo task.
42+
2. Set two task options:
43+
- Your Airtable account email
44+
- The Airtable base ID you wish to use
45+
3. Run the task
46+
47+
Look in your Airtable base for the generated table and data.
48+
49+
## Want to Learn More?
50+
51+
This task demonstrates how to:
52+
- Create a new table in an Airtable base, with 3 common field types: string, datetime, and checkbox
53+
- Handle API responses in Mechanic
54+
- Add data to a table
55+
56+
Take a look at the task code to see exactly how it works, then use these examples in your own tasks.
57+
58+
Review the [Airtable API reference](https://airtable.com/developers/web/api) for information on the many ways their API can be used. Airtable also auto-generates API docs for your base and each table in it, which can be found at `https://airtable.com/{{ airtable_base_id}}/api/docs`. The specific field parameters for each table will be documented there, which is very helpful when developing code for adding/updating records.
59+
60+
## Installing this task
61+
62+
Find this task [in the library at tasks.mechanic.dev](https://tasks.mechanic.dev/demonstration-create-and-update-a-table-in-airtable), and use the "Try this task" button. Or, import [this task's JSON export](../../tasks/demonstration-create-and-update-a-table-in-airtable.json) – see [Importing and exporting tasks](https://learn.mechanic.dev/core/tasks/import-and-export) to learn how imports work.
63+
64+
## Contributions
65+
66+
Found a bug? Got an improvement to add? Start here: [../../CONTRIBUTING.md](../../CONTRIBUTING.md).
67+
68+
## Task requests
69+
70+
Submit your [task requests](https://mechanic.canny.io/task-requests) for consideration by the Mechanic community, and they may be chosen for development and inclusion in the [task library](https://tasks.mechanic.dev/)!
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
{% assign airtable_account = options.airtable_account__required %}
2+
{% assign airtable_base_id = options.airtable_base_id__required %}
3+
4+
{% comment %}
5+
-- API REFERENCE: https://airtable.com/developers/web/api
6+
{% endcomment %}
7+
8+
{% if event.topic == "mechanic/user/trigger" %}
9+
{% comment %}
10+
** Airtable API - Create a new table **
11+
-- This action will create a new table in base of the connected Airtable account
12+
{% endcomment %}
13+
14+
{% action "airtable" %}
15+
{
16+
"account": {{ airtable_account | json }},
17+
"method": "POST",
18+
"url_path": "/v0/meta/bases/{{ airtable_base_id }}/tables",
19+
"headers": {
20+
"Content-Type": "application/json"
21+
},
22+
"body": {
23+
"name": "Demo Orders {{ "now" | date: "%Y-%m-%d %H:%M:%S" }}",
24+
"description": "Created by Mechanic demo task",
25+
"fields": [
26+
{
27+
"name": "Order Name",
28+
"type": "singleLineText"
29+
},
30+
{
31+
"name": "Order Date",
32+
"type": "dateTime",
33+
"options": {
34+
"dateFormat": {
35+
"name": "local"
36+
},
37+
"timeFormat": {
38+
"name": "24hour"
39+
},
40+
"timeZone": {{ shop.iana_timezone | json }}
41+
}
42+
},
43+
{
44+
"name": "Shipped",
45+
"type": "checkbox",
46+
"options": {
47+
"color": "greenBright",
48+
"icon": "check"
49+
}
50+
}
51+
]
52+
}
53+
}
54+
{% endaction %}
55+
56+
{% elsif event.topic == "mechanic/actions/perform" %}
57+
{% comment %}
58+
-- NOTE: check the "Preview events" tab in the task to see the preview data for each action result
59+
{% endcomment %}
60+
61+
{% unless action.run.ok and action.type == "airtable" %}
62+
{% break %}
63+
{% endunless %}
64+
65+
{% if action.run.result.status != 200 %}
66+
{% unless event.preview %}
67+
{%- capture error_message -%}
68+
Airtable API call returned an error.
69+
70+
Error type: {{ action.run.result.body.error.type }}
71+
Error message: {{ action.run.result.body.error.message }}
72+
{%- endcapture -%}
73+
74+
{% error error_message %}
75+
{% endunless %}
76+
{% endif %}
77+
78+
{% comment %}
79+
-- NOTE: Typically if a task performs multiple actions that need further processing, then the actions would pass along "meta" information to more easily distinguish between them. This was not done for this demo task to keep the action tags in the more common usage format.
80+
{% endcomment %}
81+
82+
{% if action.options.method == "POST" and action.options.url_path contains "/v0/meta/bases" %}
83+
{% assign airtable_table_id = action.run.result.body.id %}
84+
85+
{% if airtable_base_id == blank %}
86+
{% error "Airtable API did not return a table ID." %}
87+
{% endif %}
88+
89+
{% unless event.preview %}
90+
{%- capture log_message -%}
91+
Airtable generates an API doc specifically for your base, which can be viewed at this link: https://airtable.com/{{ airtable_base_id }}/api/docs
92+
{%- endcapture -%}
93+
94+
{% log log_message %}
95+
{% endunless %}
96+
97+
{% comment %}
98+
** Airtable API - Add data to newly created table **
99+
-- This action will add 2 rows to the newly created table in base of the connected Airtable account
100+
{% endcomment %}
101+
102+
{% action "airtable" %}
103+
{
104+
"account": {{ airtable_account | json }},
105+
"method": "POST",
106+
"url_path": "/v0/{{ airtable_base_id }}/{{ airtable_table_id }}",
107+
"headers": {
108+
"Content-Type": "application/json"
109+
},
110+
"body": {
111+
"records": [
112+
{
113+
"fields": {
114+
"Order Name": "#1234",
115+
"Order Date": "2025-10-01T12:00:00Z",
116+
"Shipped": true
117+
}
118+
},
119+
{
120+
"fields": {
121+
"Order Name": "#1357",
122+
"Order Date": "2025-10-05T12:00:00Z",
123+
"Shipped": false
124+
}
125+
}
126+
]
127+
}
128+
}
129+
{% endaction %}
130+
131+
{% elsif action.options.method == "POST" %}
132+
{% log records_added_to_table: action.run.result.body.records %}
133+
{% endif %}
134+
{% endif %}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Demonstration: Create sheets and list and create files in Google Drive
2+
3+
Tags: Demonstration, Google Drive, Google Sheets, Integration
4+
5+
# Demonstration: Create Google sheets, and list and create files in Google Drive
6+
7+
* View in the task library: [tasks.mechanic.dev/demonstration-create-sheets-and-list-and-create-files-in-google-drive](https://tasks.mechanic.dev/demonstration-create-sheets-and-list-and-create-files-in-google-drive)
8+
* Task JSON, for direct import: [task.json](../../tasks/demonstration-create-sheets-and-list-and-create-files-in-google-drive.json)
9+
* Preview task code: [script.liquid](./script.liquid)
10+
11+
## Default options
12+
13+
```json
14+
{
15+
"google_account__required": null,
16+
"create_google_sheet_demo__boolean": false,
17+
"create_google_drive_file_demo__boolean": false,
18+
"list_google_drive_files_demo__boolean": false
19+
}
20+
```
21+
22+
[Learn about task options in Mechanic](https://learn.mechanic.dev/core/tasks/options)
23+
24+
## Subscriptions
25+
26+
```liquid
27+
mechanic/user/trigger
28+
mechanic/actions/perform
29+
```
30+
31+
[Learn about event subscriptions in Mechanic](https://learn.mechanic.dev/core/tasks/subscriptions)
32+
33+
## Documentation
34+
35+
# Demonstration: Create Google sheets, and list and create files in Google Drive
36+
37+
This task posts a demonstration message in the Slack channel of your choice. Try it out to learn how the Google action works!
38+
39+
## Quick Start
40+
41+
1. Connect your Google account in Mechanic (Settings → Authentication)
42+
2. Set two task options:
43+
- Your Google account
44+
- Your choice of one or more of the Google action demos:
45+
- Create a new Google Sheet
46+
- List Google Drive files
47+
- Create Google Drive file
48+
3. Run the task
49+
50+
Look in your Google Drive for the example files if you ran one of the create demos. Otherwise, the list of Drive files will be output in the task run event log.
51+
52+
## Want to Learn More?
53+
54+
This task demonstrates how to:
55+
- Create a new Google Sheet in your Google Drive
56+
- With a dynamic file name
57+
- Setting a sheet tab title
58+
- Using a couple of common Sheet cell data types: string, boolean
59+
- Listing a few fields from the first 10 files found in the connected Google Drive folder
60+
- Alternate version which filters the search by files having "Mechanic" in the title
61+
- Creating a simple text file in the root Drive folder
62+
63+
Take a look at the task code to see exactly how it works, then use these examples in your own tasks.
64+
65+
The Google Drive API documentation is primarily geared towards developers familiar with the Google API ecosystem. If the references below seem daunting, then consider trying out the [Google Drive or Google Sheet actions](https://learn.mechanic.dev/platform/integrations/google-drive-and-google-sheets) in Mechanic instead. (Note: there are demonstration tasks in the Mechanic library for each of those actions as well.)
66+
67+
- https://developers.google.com/workspace/sheets/api/reference/rest/v4/spreadsheets
68+
- https://developers.google.com/workspace/drive/api/reference/rest/v3
69+
- https://developers.google.com/workspace/drive/api/reference/rest/v3/files
70+
71+
## Installing this task
72+
73+
Find this task [in the library at tasks.mechanic.dev](https://tasks.mechanic.dev/demonstration-create-sheets-and-list-and-create-files-in-google-drive), and use the "Try this task" button. Or, import [this task's JSON export](../../tasks/demonstration-create-sheets-and-list-and-create-files-in-google-drive.json) – see [Importing and exporting tasks](https://learn.mechanic.dev/core/tasks/import-and-export) to learn how imports work.
74+
75+
## Contributions
76+
77+
Found a bug? Got an improvement to add? Start here: [../../CONTRIBUTING.md](../../CONTRIBUTING.md).
78+
79+
## Task requests
80+
81+
Submit your [task requests](https://mechanic.canny.io/task-requests) for consideration by the Mechanic community, and they may be chosen for development and inclusion in the [task library](https://tasks.mechanic.dev/)!

0 commit comments

Comments
 (0)