You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+7-1Lines changed: 7 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,12 @@
1
1
# Changelog
2
2
All notable changes to this project will be documented in this file.
3
3
4
+
## [9.0.0] - revision 2024-02-15
5
+
6
+
### Changed
7
+
8
+
- OAuth support has been moved to GA, view the [building a new integration guide](https://developers.klaviyo.com/en/docs/build_your_integration) for more information.
9
+
4
10
## [8.0.0] - revision 2024-02-15
5
11
6
12
### Added:
@@ -276,4 +282,4 @@ In addition, you can [make client-side API calls](https://developers.klaviyo.com
276
282
- Packagename:klaviyo-sdk-beta → klaviyo-api
277
283
- Somefunctionshavechangedname
278
284
- Newresourcesandendpoints:
279
-
- See [APIChangelog](https://developers.klaviyo.com/en/docs/changelog_) for full details
285
+
- See [APIChangelog](https://developers.klaviyo.com/en/docs/changelog_) for full details
@@ -48,7 +48,7 @@ This SDK is organized into the following resources:
48
48
49
49
You can install this library using `npm`.
50
50
51
-
`npm install klaviyo-api@8.0.0`
51
+
`npm install klaviyo-api@9.0.0`
52
52
53
53
54
54
## source code
@@ -74,17 +74,6 @@ If you want to test out the repo but don't have a consuming app, you can run our
74
74
npm run sample --pk=<YOUR PRIVATE KEY HERE>
75
75
```
76
76
77
-
## OAuth Beta
78
-
79
-
To read about our OAuth beta for users who want to write multi-user integrations, check out this [help center article](https://help.klaviyo.com/hc/en-us/articles/18819413031067#h_01HACEKGF33GHFEH733YK2JKTT)
80
-
81
-
If you already are in the OAuth beta, read the documentation in the [`oauth-beta` branch](https://github.com/klaviyo/klaviyo-api-node/tree/oauth-beta) in this repo or check out the [example application](https://github.com/klaviyo-labs/node-integration-example).
82
-
83
-
Install the beta package with the following command:
84
-
```bash
85
-
npm i klaviyo-api@beta
86
-
```
87
-
88
77
# Usage Example
89
78
90
79
### To instantiate an API wrapper using an API Key
## Using OAuth to connect to multiple Klaviyo accounts.
211
+
212
+
For users creating integrations or managing multiple Klaviyo accounts, Klaviyo's OAuth authentication will make these tasks easier.
213
+
214
+
### Getting started with OAuth
215
+
216
+
First, configure an integration. If you haven't set up an integration, learn about it in this [guide](https://developers.klaviyo.com/en/v2024-02-15/docs/set_up_oauth)
217
+
218
+
### Making API Calls with OAuth
219
+
The `klaviyo-api` package can keep your `access token` up to date. If you have already developed a system for refreshing tokens or would like a more minimalist option, skip to [OAuthBasicSession](#oauthbasicsession)
220
+
221
+
#### TokenStorage
222
+
For the OAuthApi to be storage agnostic, this interface must be implemented for the `OAuthApi` to retrieve and save you `access` and `refresh` tokens.
223
+
Implement the `retrieve` and `save` functions outlined in the interface. If you need help getting started, check out the `storageHelpers.ts` in the [Klaviyo Example Typescript Integration](https://github.com/klaviyo-labs/node-integration-example)
tokeeptrackofwhichofyourintegrationusers' access information you are referencing, the `customerIdentifier` is a unique value to help with lookup later.
To make an API call, you need to create an `OAuthSession` instance. This session object is the OAuth equivalent of `ApiKeySession` and is used similarly.
257
+
258
+
It takes two properties
259
+
1. `customerIdentifier` - This is how the session is going to grab a user's authentication information and let your implementation of `TokenStorage` know where to save any update `accesstoken`
260
+
2. `oauthApi` - This is the instance of `OAuthApi` created above. It will dictate how the session `saves` and `retrieves` the `accesstokens`
261
+
3. `retryOptions` - OPTIONAL - the `RetryOptions` instance outlines your desired exponential backoff retry options, outlined in [Retry Options](#retry-options) above
Remember to check for `401` errors. A 401 means that your token is probably expired.
289
+
290
+
#### `KlaviyoTokenError`
291
+
292
+
If an error occurred during an API call, check the error type with `isKlaviyoTokenError`. The name property will reflect which step the error occurred, reflecting whether it happened during creating, refreshing, saving, or retrieving the `name` tokens. The `cause` property will hold the error object of whatever specific error occurred.
293
+
294
+
### Authorization Flow
295
+
296
+
Build The authorization flow in the same application as with the rest of your integrations business logic or separately.
297
+
There is no requirement that the authorization flow has to be backend and can be implemented entirely in a frontend application (in that case, you can ignore this section, as this repo shouldn't use this for frontend code)
298
+
299
+
To understand the authorization flow, there are two major resources to help:
If you implement your authorization flow on a node server, you can use these exposed helper functions.
304
+
305
+
#### OAuthApi
306
+
307
+
The OAuthApi class also exposes helpful Authorization flow utilities.
308
+
309
+
1. `generateAuthorizeUrl` - This helps correctly format the Klaviyo `/oauth/authorize` URL the application needs to redirect to so a user can approve your integration.
310
+
1. `state` - This is the only way to identify which user just authorized your application (or failed to). `state` is passed back via query parameter to your `redirectUrl`.
311
+
2. `scope` - The permissions the created `accesstokens` will have. The user will be displayed these scopes during the authorization flow. For these permissions to work, also add them to your app settings in Klaviyo [here](www.klaviyo.com/oauth/client)
312
+
3. `codeChallenge` - This is the value generated above by the `generateCode` function.
313
+
4. `redirectUrl` - This is the URL that Klaviyo will redirect the user to once Authorization is completed (even if it is denied or has an error).
314
+
Remember to whitelist this redirect URL in your integration's settings in Klaviyo.
state, // It's suggested to use your internal identifier for the Klaviyo account that is authorizing
321
+
scopes,
322
+
codeChallenge,
323
+
redirectUrl
324
+
)
325
+
```
326
+
2. `createTokens` - Uses Klaviyo `/oauth/token/` endpoint to create `access` and `refresh` tokens
327
+
1. `customerIdentifier` - This ID is NOT sent to Klaviyo's API. If the `/token` API call this method wraps is successful, the created tokens will be passed into your `save` method along with this `customerIdentifier` in your implementation of `TokenStorage`.
328
+
2. `codeVerifier` - The verifier code must match the challenge code in the authorized URL redirect.
329
+
3. `authorizationCode`- A User approving your integration creates this temporary authorization code. Your specified redirect URL receives this under a `code` query parameter.
330
+
4. `redirectUrl` - The endpoint set in `generateAuthorizeUrl`. Whitelist the URL in your application settings.
3. `OAuthCallbackQueryParams` For typescript users, this object is an interface representing the possible query parameters sent to your redirect endpoint
344
+
345
+
346
+
347
+
#### Proof Key of Code Exchange (PKCE)
348
+
349
+
All the PKCE helper functions live within the `Pkce` namespace. Read about PKCE [here](https://developers.klaviyo.com/en/v2024-02-15/docs/set_up_oauth#pkce-and-code-challenges)
350
+
351
+
```typescript
352
+
import { Pkce } from'klaviyo-api'
353
+
```
354
+
355
+
The `Pkce` namespace holds two different helper utilities
356
+
1. `generateCodes` - This method will create the `codeVerifier` and `codeChallenge` needed later in the authorization flow.
0 commit comments