@zapier/zapier-sdk 0.25.1 → 0.25.2
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.
- package/CHANGELOG.md +6 -0
- package/README.md +85 -16
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
## Table of Contents
|
|
4
4
|
|
|
5
|
+
- [Closed Beta](#closed-beta)
|
|
6
|
+
- [Documentation](#documentation)
|
|
5
7
|
- [Installation](#installation)
|
|
6
8
|
- [Quick Start](#quick-start)
|
|
7
9
|
- [Available Functions](#available-functions)
|
|
@@ -31,10 +33,26 @@
|
|
|
31
33
|
- [HTTP Requests](#http-requests)
|
|
32
34
|
- [`fetch`](#fetch)
|
|
33
35
|
|
|
36
|
+
## Closed Beta
|
|
37
|
+
|
|
38
|
+
At the time of publishing this package, the Zapier SDK requires an invite for most features. If you want to try it out, let us know at the following page!
|
|
39
|
+
|
|
40
|
+
https://sdk-beta.zapier.app/signup
|
|
41
|
+
|
|
42
|
+
## Documentation
|
|
43
|
+
|
|
44
|
+
The official documentation will soon be available at:
|
|
45
|
+
|
|
46
|
+
https://docs.zapier.com/sdk
|
|
47
|
+
|
|
48
|
+
While the dust settles, that documentation may be incomplete, and this README may have additional documentation.
|
|
49
|
+
|
|
50
|
+
Agents are sometimes blocked from viewing docs on npm, so you may want to provide them a link to the official docs or copy the docs here into a prompt.
|
|
51
|
+
|
|
34
52
|
## Installation
|
|
35
53
|
|
|
36
54
|
```bash
|
|
37
|
-
# If starting a new project:
|
|
55
|
+
# If you're starting a new project:
|
|
38
56
|
cd your-project-dir
|
|
39
57
|
npm init -y
|
|
40
58
|
npx tsc --init
|
|
@@ -46,20 +64,52 @@ npm install -D @zapier/zapier-sdk-cli @types/node typescript
|
|
|
46
64
|
|
|
47
65
|
## Quick Start
|
|
48
66
|
|
|
67
|
+
Assuming you've installed the CLI package into your project (see instructions above), you (or an agent) can start using it right away. This is useful for introspecting actions, authentications, etc. that you want to use in code, but you can also use it to directly use integrations.
|
|
68
|
+
|
|
49
69
|
```bash
|
|
50
|
-
#
|
|
70
|
+
# See all available commands
|
|
71
|
+
npx zapier-sdk --help
|
|
72
|
+
|
|
73
|
+
# Login to Zapier.
|
|
51
74
|
npx zapier-sdk login
|
|
52
75
|
|
|
53
|
-
#
|
|
54
|
-
npx zapier-sdk
|
|
76
|
+
# Search from thousands of supported apps.
|
|
77
|
+
npx zapier-sdk list-apps --search "gmail"
|
|
78
|
+
# The output will show you the valid keys next to the app title like this:
|
|
79
|
+
# 1. Gmail (GoogleMailV2CLIAPI, gmail)
|
|
80
|
+
|
|
81
|
+
# Run any action for the app, using one of the app keys.
|
|
82
|
+
npx zapier-sdk run-action gmail
|
|
83
|
+
# This will ask you for the type of action you want to run.
|
|
84
|
+
# `search` or `write` are typically great for testing.
|
|
85
|
+
# Note that you usually need an authentication (connection) to the app to run
|
|
86
|
+
# the action. If you don't already have one, you can create a new one at:
|
|
87
|
+
# https://zapier.com/app/assets/connections
|
|
88
|
+
|
|
89
|
+
# List authentications for an app.
|
|
90
|
+
npx zapier-sdk list-authentications gmail
|
|
91
|
+
# Or only list the ones you own.
|
|
92
|
+
npx zapier-sdk list-authentications gmail --owner me
|
|
93
|
+
# Or just grab the first one.
|
|
94
|
+
npx zapier-sdk find-first-authentication gmail --owner me
|
|
95
|
+
|
|
96
|
+
# Make any API request to an app using your authentication (connection).
|
|
97
|
+
npx zapier-sdk fetch "https://gmail.googleapis.com/gmail/v1/users/me/labels" --authentication-id 123
|
|
98
|
+
```
|
|
55
99
|
|
|
56
|
-
|
|
57
|
-
# you don't know the slug or key, just use `list-apps` search to find it.
|
|
58
|
-
zapier-sdk list-apps --search "google sheets"
|
|
100
|
+
The following is optional, but if you want to call our actions from code, it can be helpful to install TypeScript types for those actions. You can also just use `fetch` to make arbitrary API requests. In that case, you don't really need this, and instead you might need types or a good agent that will look up third party API docs.
|
|
59
101
|
|
|
102
|
+
```bash
|
|
103
|
+
# Search for apps that you want to use.
|
|
104
|
+
npx zapier-sdk list-apps --search "slack"
|
|
105
|
+
npx zapier-sdk list-apps --search "google sheets"
|
|
60
106
|
# The output will show you the valid keys next to the app title like this:
|
|
107
|
+
# 1. Slack (SlackCLIAPI, slack)
|
|
61
108
|
# 1. Google Sheets (GoogleSheetsV2CLIAPI, google-sheets, google_sheets)
|
|
62
109
|
|
|
110
|
+
# Generate TypeScript types for actions and fields of any apps you want to use.
|
|
111
|
+
npx zapier-sdk add slack google-sheets
|
|
112
|
+
|
|
63
113
|
# By default, types will be generated inside your `src` or `lib` folder if you
|
|
64
114
|
# have one or otherwise the root folder. Make sure your `tsconfig.json` file
|
|
65
115
|
# includes the generated type files.
|
|
@@ -68,20 +118,20 @@ zapier-sdk list-apps --search "google sheets"
|
|
|
68
118
|
npx zapier-sdk add slack google-sheets --types-output ./types
|
|
69
119
|
```
|
|
70
120
|
|
|
121
|
+
Now let's write some code!
|
|
122
|
+
|
|
71
123
|
```typescript
|
|
72
124
|
import { createZapierSdk } from "@zapier/zapier-sdk";
|
|
73
125
|
|
|
74
126
|
// ######## Initialize Zapier SDK ########
|
|
75
|
-
// Option 1: Running `zapier-sdk login` authenticates through your browser
|
|
76
|
-
//
|
|
127
|
+
// Option 1: Running `zapier-sdk login` authenticates through your browser and
|
|
128
|
+
// stores a token on your local machine. As long as you have the CLI package
|
|
129
|
+
// installed as a development dependency, the SDK will automatically use it.
|
|
77
130
|
const zapier = createZapierSdk();
|
|
78
131
|
|
|
79
|
-
// Option 2:
|
|
80
|
-
//
|
|
81
|
-
//
|
|
82
|
-
// });
|
|
83
|
-
|
|
84
|
-
// Option 3: Manually provide a client ID and client secret.
|
|
132
|
+
// Option 2: Provide a client ID and client secret.
|
|
133
|
+
// You can get these by running `zapier-sdk create-client-credentials`.
|
|
134
|
+
// This allows you to run the SDK in a server/serverless environment.
|
|
85
135
|
// const zapier = createZapierSdk({
|
|
86
136
|
// credentials: {
|
|
87
137
|
// clientId: "your_client_id_here", // or use ZAPIER_CREDENTIALS_CLIENT_ID env var
|
|
@@ -89,6 +139,12 @@ const zapier = createZapierSdk();
|
|
|
89
139
|
// },
|
|
90
140
|
// });
|
|
91
141
|
|
|
142
|
+
// Option 3: Provide a valid Zapier token.
|
|
143
|
+
// This is for partner OAuth or internal Zapier use.
|
|
144
|
+
// const zapier = createZapierSdk({
|
|
145
|
+
// credentials: "your_zapier_token_here", // or use ZAPIER_CREDENTIALS env var
|
|
146
|
+
// });
|
|
147
|
+
|
|
92
148
|
// ######## Access Apps ########
|
|
93
149
|
// List methods return a promise for a page with {data, nextCursor}.
|
|
94
150
|
const { data: firstPageApps, nextCursor } = await zapier.listApps();
|
|
@@ -165,7 +221,8 @@ console.log({
|
|
|
165
221
|
});
|
|
166
222
|
|
|
167
223
|
// Option 2: Access actions via the `apps` proxy
|
|
168
|
-
// If you've generated TS types for an app using `zapier-sdk add`, you can
|
|
224
|
+
// If you've generated TS types for an app using `zapier-sdk add`, you can
|
|
225
|
+
// access the app's actions like this:
|
|
169
226
|
|
|
170
227
|
// await zapier.apps.slack.read.channles({});
|
|
171
228
|
// await zapier.apps.slack.write.send_message({})
|
|
@@ -218,6 +275,18 @@ console.log({
|
|
|
218
275
|
// For example, either of the following are valid:
|
|
219
276
|
// zapier.apps["google-sheets"]
|
|
220
277
|
// zapier.apps.google_sheets
|
|
278
|
+
|
|
279
|
+
// We have tens of thousands of actions across thousands of apps, but you're
|
|
280
|
+
// still not limited to those. You can make any arbitrary API request to an app
|
|
281
|
+
// using the same authentications with `.fetch`! This returns a response just
|
|
282
|
+
// like a normal `fetch` call in JavaScript.
|
|
283
|
+
const emojiResponse = await zapier.fetch("https://slack.com/api/emoji.list", {
|
|
284
|
+
authenticationId: myAuths[0].id,
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
const emojiData = await emojiResponse.json();
|
|
288
|
+
|
|
289
|
+
console.log(emojiData.emoji);
|
|
221
290
|
```
|
|
222
291
|
|
|
223
292
|
## Available Functions
|
package/dist/index.cjs
CHANGED
package/dist/index.mjs
CHANGED