1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-18 14:38:01 +00:00

Compare commits

...

3 Commits

Author SHA1 Message Date
nick-w-nick
165049a865 Merge 295fe153ad into 17d7f0933b 2024-10-23 20:41:15 -04:00
jbranchaud
17d7f0933b Add Add Subscriber To Kit Form Via API as a Workflow TIL 2024-10-23 19:12:52 -05:00
nick-w-nick
295fe153ad added mention of ES6 compatibility
Hello, I've added a small blockquote below the description to indicate that this method of accessing an indefinite number of function arguments has been superseded by the use of the spread operator via rest parameters for ES6+ compatibility.
2022-01-06 11:39:04 -05:00
3 changed files with 68 additions and 1 deletions

View File

@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
_1480 TILs and counting..._
_1481 TILs and counting..._
---
@@ -1706,6 +1706,7 @@ _1480 TILs and counting..._
### Workflow
- [Add Hotkeys For Specific Raycast Extensions](workflow/add-hotkeys-for-specific-raycast-extensions.md)
- [Add Subscriber To Kit Form Via API](workflow/add-subscriber-to-kit-form-via-api.md)
- [Add Subtitles To Existing Mux Video Asset](workflow/add-subtitles-to-existing-mux-video-asset.md)
- [Access 1Password Credential From CLI](workflow/access-1password-credential-from-cli.md)
- [Change Window Name In iTerm](workflow/change-window-name-in-iterm.md)

View File

@@ -5,6 +5,8 @@ an array-like object with all of the arguments to the function. Even if not
all of the arguments are referenced in the function signature, they can
still be accessed via the `arguments` object.
> For ES6+ compatibility, the `spread` operator used via [rest parameters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters) is preferred over the `arugments` object when accessing an abritrary number of function arguments.
```javascript
function argTest(one) {
console.log(one);

View File

@@ -0,0 +1,64 @@
# Add Subscriber To Kit Form Via API
Because the Kit API is a bit sparse in words, I found it difficult to figure
out exactly what I needed to do to add a subscriber via a custom form. After
some experimenting and reading through [Course
Builder](https://github.com/badass-courses/course-builder/blob/main/packages/core/src/providers/convertkit.ts)
code, I was able to figure out that with the Kit v4 API there are two separate
calls that need to be made.
First, you need to create an `inactive` subscriber with the user's email (and
first name if given) via the [Create a subscriber
endpoint](https://developers.kit.com/v4#create-a-subscriber).
```typescript
async function createSubscriber(
data: SubscriberData,
apiKey: string,
): Promise<Response> {
return fetch('https://api.convertkit.com/v4/subscribers', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Kit-Api-Key': apiKey,
},
body: JSON.stringify({
email_address: data.email,
first_name: data.name,
state: 'inactive',
}),
})
}
```
Since this subscriber is `inactive`, they won't show up in the Kit dashboard,
but a subscriber record of them has been created.
Second, you need to add the subscriber to something, like a form or a sequence.
In my case, I had already created a form via the Kit dashboard, so I grab that
_Form ID_ and stick it in my `.env`. That way I am able to [add the subscriber
to the form by email
address](https://developers.kit.com/v4#add-subscriber-to-form-by-email-address).
```typescript
async function addSubscriberToForm(
email: string,
apiKey: string,
formId: string,
): Promise<Response> {
const url = `https://api.convertkit.com/v4/forms/${formId}/subscribers`
return fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Kit-Api-Key': apiKey,
},
body: JSON.stringify({ email_address: email }),
})
}
```
This will send a confirmation email to the email address. Once the person has
opened the email and hit 'Confirm', their corresponding `subscriber` record
will be marked as `active` and they will be added to the list of subscribers
for that form.