Canva Connect API — Install & Auth
Overview
Set up a Canva Connect API integration with OAuth 2.0 Authorization Code flow with PKCE (SHA-256). The Canva Connect API is a REST API at https://api.canva.com/rest/v1/* — there is no SDK package. All calls use fetch or axios with Bearer tokens.
Prerequisites
- Node.js 18+ (for native
crypto.subtle and fetch)
- A Canva account at canva.com
- An integration registered at canva.dev
Instructions
Step 1: Register Your Integration
- Go to Settings > Integrations at canva.com/developers
- Create a new integration — note your Client ID and Client Secret
- Add redirect URI(s): e.g.
http://localhost:3000/auth/canva/callback
- Enable required scopes under Permissions
Step 2: Store Credentials
# .env (NEVER commit — add to .gitignore)
CANVA_CLIENT_ID=OCAxxxxxxxxxxxxxxxx
CANVA_CLIENT_SECRET=xxxxxxxxxxxxxxxx
CANVA_REDIRECT_URI=http://localhost:3000/auth/canva/callback
echo '.env' >> .gitignore
echo '.env.local' >> .gitignore
Step 3: Implement OAuth 2.0 PKCE Flow
// src/canva/auth.ts
import crypto from 'crypto';
// 1. Generate PKCE code verifier and challenge
export function generatePKCE(): { verifier: string; challenge: string } {
const verifier = crypto.randomBytes(64).toString('base64url'); // 43-128 chars
const challenge = crypto
.createHash('sha256')
.update(verifier)
.digest('base64url');
return { verifier, challenge };
}
// 2. Build the authorization URL
export function getAuthorizationUrl(opts: {
clientId: string;
redirectUri: string;
scopes: string[];
codeChallenge: string;
state: string;
}): string {
const params = new URLSearchParams({
response_type: 'code',
client_id: opts.clientId,
redirect_uri: opts.redirectUri,
scope: opts.scopes.join(' '),
code_challenge: opts.codeChallenge,
code_challenge_method: 'S256',
state: opts.state,
});
return `https://www.canva.com/api/oauth/authorize?${params}`;
}
// 3. Exchange authorization code for access token
export async function exchangeCodeForToken(opts: {
code: string;
codeVerifier: string;
clientId: string;
clientSecret: string;
redirectUri: string;
}): Promise<{ access_token: string; refresh_token: string; expires_in: number }> {
const basicAuth = Buffer.from(
`${opts.clientId}:${opts.clientSecret}`
).toString('base64');
const res = await fetch('https://api.canva.com/rest/v1/oauth/token', {
method: 'POST',
headers: {
'Authorization': `Basic ${basicAuth}`,
'Content-Type': 'application/x-www-form-urlencoded',
},
body: new URLSearchParams({
grant_type: 'authorization_code',
code: opts.code,
code_verifier: opts.codeVerifier,
redirect_uri: opts.redirectUri,
}),
});
if (!res.ok) {
const err = await res.json();
throw new Error(`Token exchange failed: ${err.error} — ${err.error_description}`);
}
return res.json();
}
// 4. Refresh an expired access token (access tokens expire in ~4 hours)
export async function refreshAccessToken(opts: {
refreshToken: string;
clientId: string;
clientSecret: string;
}): Promise<{ access_token: string; refresh_token: string; expires_in: number }> {
const basicAuth = Buffer.from(
`${opts.clientId}:${opts.clientSecret}`
).toString('base64');
const res = await fetch('https://api.canva.com/rest/v1/oauth/token', {
method: 'POST',
headers: {
'Authorization': `Basic ${basicAuth}`,
'Content-Type': 'application/x-www-form-urlencoded',
},
body: new URLSearchParams({
grant_type: 'refresh_token',
refresh_token: opts.refreshToken,
}),
});
if (!res.ok) throw new Error('Token refresh failed');
return res.json();
}
Step 4: Verify Connection
// Verify token works by calling GET /v1/users/me (no scopes required)
async function verifyConnection(accessToken: string): Promise<void> {
const res = await fetch('https://api.canva.com/rest/v1/users/me', {
headers: { 'Authorization': `Bearer ${accessToken}` },
});
if (!res.ok) throw new Error(`Verification failed: ${res.status}`);
const { team_user } = await res.json();
console.log(`Connected — user_id: ${team_user.user_id}, team_id: ${team_user.team_id}`);
}
Available OAuth Scopes
| Scope |
Description |
design:content:read |
Read design contents, export designs |
design:content:write |
Create designs, autofill brand templates |
design:meta:read |
List designs, get design metadata |
asset:read |
View uploaded asset metadata |
asset:write |
Upload, update, delete assets |
brandtemplate:content:read |
Read brand template content |
brandtemplate:meta:read |
List and view brand template metadata |
folder:read |
View folder contents |
folder:write |
Create, update, delete folders |
folder:permission:write |
Manage folder permissions |
comment:read |
Read design comments |
comment:write |
Create comments and replies |
collaboration:event |
Receive webhook notifications |
profile:read |
Read user profile information |
Error Handling
| Error |
Cause |
Solution |
invalid_client |
Wrong client_id or secret |
Verify credentials in Canva dashboard |
invalid_grant |
Expired or reused auth code |
Restart OAuth flow — codes are single-use |
invalid_scope |
Scope not enabled |
Enable scope in integration settings |
access_denied |
User rejected consent |
Prompt user again |
| Token expired (401) |
Access token > 4 hours old |
Call refresh token endpoint |
Resources
Next Steps
After successful auth, proceed to canva-hello-world for your first API call.
1---
2name: canva-install-auth
3description: |
4 Set up Canva Connect API OAuth 2.0 PKCE authentication and project scaffolding.
5 Use when creating a new Canva integration, setting up OAuth credentials,
6 or initializing a Canva Connect API project.
7 Trigger with phrases like "install canva", "setup canva",
8 "canva auth", "configure canva API", "canva OAuth".
9allowed-tools: Read, Write, Edit, Bash(npm:*), Bash(pnpm:*), Bash(npx:*), Grep
10version: 1.0.0
11license: MIT
12author: Jeremy Longshore <jeremy@intentsolutions.io>
13tags: [saas, design, canva]
14compatible-with: claude-code
15metadata:
16 source: https://skillmd.com/skills/aibot88/canva-install-auth
17---
18
19# Canva Connect API — Install & Auth
20
21## Overview
22
23Set up a Canva Connect API integration with OAuth 2.0 Authorization Code flow with PKCE (SHA-256). The Canva Connect API is a REST API at `https://api.canva.com/rest/v1/*` — there is no SDK package. All calls use `fetch` or `axios` with Bearer tokens.
24
25## Prerequisites
26
27- Node.js 18+ (for native `crypto.subtle` and `fetch`)
28- A Canva account at [canva.com](https://www.canva.com)
29- An integration registered at [canva.dev](https://www.canva.dev/docs/connect/creating-integrations/)
30
31## Instructions
32
33### Step 1: Register Your Integration
34
351. Go to **Settings > Integrations** at [canva.com/developers](https://www.canva.com/developers)
362. Create a new integration — note your **Client ID** and **Client Secret**
373. Add redirect URI(s): e.g. `http://localhost:3000/auth/canva/callback`
384. Enable required scopes under **Permissions**
39
40### Step 2: Store Credentials
41
42```bash
43# .env (NEVER commit — add to .gitignore)
44CANVA_CLIENT_ID=OCAxxxxxxxxxxxxxxxx
45CANVA_CLIENT_SECRET=xxxxxxxxxxxxxxxx
46CANVA_REDIRECT_URI=http://localhost:3000/auth/canva/callback
47```
48
49```bash
50echo '.env' >> .gitignore
51echo '.env.local' >> .gitignore
52```
53
54### Step 3: Implement OAuth 2.0 PKCE Flow
55
56```typescript
57// src/canva/auth.ts
58import crypto from 'crypto';
59
60// 1. Generate PKCE code verifier and challenge
61export function generatePKCE(): { verifier: string; challenge: string } {
62 const verifier = crypto.randomBytes(64).toString('base64url'); // 43-128 chars
63 const challenge = crypto
64 .createHash('sha256')
65 .update(verifier)
66 .digest('base64url');
67 return { verifier, challenge };
68}
69
70// 2. Build the authorization URL
71export function getAuthorizationUrl(opts: {
72 clientId: string;
73 redirectUri: string;
74 scopes: string[];
75 codeChallenge: string;
76 state: string;
77}): string {
78 const params = new URLSearchParams({
79 response_type: 'code',
80 client_id: opts.clientId,
81 redirect_uri: opts.redirectUri,
82 scope: opts.scopes.join(' '),
83 code_challenge: opts.codeChallenge,
84 code_challenge_method: 'S256',
85 state: opts.state,
86 });
87 return `https://www.canva.com/api/oauth/authorize?${params}`;
88}
89
90// 3. Exchange authorization code for access token
91export async function exchangeCodeForToken(opts: {
92 code: string;
93 codeVerifier: string;
94 clientId: string;
95 clientSecret: string;
96 redirectUri: string;
97}): Promise<{ access_token: string; refresh_token: string; expires_in: number }> {
98 const basicAuth = Buffer.from(
99 `${opts.clientId}:${opts.clientSecret}`
100 ).toString('base64');
101
102 const res = await fetch('https://api.canva.com/rest/v1/oauth/token', {
103 method: 'POST',
104 headers: {
105 'Authorization': `Basic ${basicAuth}`,
106 'Content-Type': 'application/x-www-form-urlencoded',
107 },
108 body: new URLSearchParams({
109 grant_type: 'authorization_code',
110 code: opts.code,
111 code_verifier: opts.codeVerifier,
112 redirect_uri: opts.redirectUri,
113 }),
114 });
115
116 if (!res.ok) {
117 const err = await res.json();
118 throw new Error(`Token exchange failed: ${err.error} — ${err.error_description}`);
119 }
120 return res.json();
121}
122
123// 4. Refresh an expired access token (access tokens expire in ~4 hours)
124export async function refreshAccessToken(opts: {
125 refreshToken: string;
126 clientId: string;
127 clientSecret: string;
128}): Promise<{ access_token: string; refresh_token: string; expires_in: number }> {
129 const basicAuth = Buffer.from(
130 `${opts.clientId}:${opts.clientSecret}`
131 ).toString('base64');
132
133 const res = await fetch('https://api.canva.com/rest/v1/oauth/token', {
134 method: 'POST',
135 headers: {
136 'Authorization': `Basic ${basicAuth}`,
137 'Content-Type': 'application/x-www-form-urlencoded',
138 },
139 body: new URLSearchParams({
140 grant_type: 'refresh_token',
141 refresh_token: opts.refreshToken,
142 }),
143 });
144
145 if (!res.ok) throw new Error('Token refresh failed');
146 return res.json();
147}
148```
149
150### Step 4: Verify Connection
151
152```typescript
153// Verify token works by calling GET /v1/users/me (no scopes required)
154async function verifyConnection(accessToken: string): Promise<void> {
155 const res = await fetch('https://api.canva.com/rest/v1/users/me', {
156 headers: { 'Authorization': `Bearer ${accessToken}` },
157 });
158
159 if (!res.ok) throw new Error(`Verification failed: ${res.status}`);
160
161 const { team_user } = await res.json();
162 console.log(`Connected — user_id: ${team_user.user_id}, team_id: ${team_user.team_id}`);
163}
164```
165
166## Available OAuth Scopes
167
168| Scope | Description |
169|-------|-------------|
170| `design:content:read` | Read design contents, export designs |
171| `design:content:write` | Create designs, autofill brand templates |
172| `design:meta:read` | List designs, get design metadata |
173| `asset:read` | View uploaded asset metadata |
174| `asset:write` | Upload, update, delete assets |
175| `brandtemplate:content:read` | Read brand template content |
176| `brandtemplate:meta:read` | List and view brand template metadata |
177| `folder:read` | View folder contents |
178| `folder:write` | Create, update, delete folders |
179| `folder:permission:write` | Manage folder permissions |
180| `comment:read` | Read design comments |
181| `comment:write` | Create comments and replies |
182| `collaboration:event` | Receive webhook notifications |
183| `profile:read` | Read user profile information |
184
185## Error Handling
186
187| Error | Cause | Solution |
188|-------|-------|----------|
189| `invalid_client` | Wrong client_id or secret | Verify credentials in Canva dashboard |
190| `invalid_grant` | Expired or reused auth code | Restart OAuth flow — codes are single-use |
191| `invalid_scope` | Scope not enabled | Enable scope in integration settings |
192| `access_denied` | User rejected consent | Prompt user again |
193| Token expired (401) | Access token > 4 hours old | Call refresh token endpoint |
194
195## Resources
196
197- [Canva Connect API Docs](https://www.canva.dev/docs/connect/)
198- [Authentication Guide](https://www.canva.dev/docs/connect/authentication/)
199- [Scopes Reference](https://www.canva.dev/docs/connect/appendix/scopes/)
200- [OpenAPI Spec](https://www.canva.dev/sources/connect/api/latest/api.yml)
201
202## Next Steps
203
204After successful auth, proceed to `canva-hello-world` for your first API call.