How to Create a ConvertKit API in Node.js for Storing Google Form Responses?

This topic was automatically generated from Slack. You can find the original thread here.

I have a trigger which is collecting an email address from a Google Form.

From here, I need to store the data in ConvertKit.

The TRIGGER goes to CONVERTKIT > ADD SUBSCRIBER TO A FORM.

Once the email address is stored, we need to store the CUSTOM FIELDS which were collected.

I need you to create a CONVERTKIT API in NODE.JS. This API will have the following 5 fields:

EARNING HIGH (this.earningHigh)
EARNING LOW (this.earningLow)
INSTAGRAM (this.instagram)
SUBSCRIBER ID (subscriberID)
API SECRET (api_secret)

To achieve your goal of storing data from a Google Form in ConvertKit, you can create a Pipedream component using Node.js. This component will use the ConvertKit API to add a subscriber to a form and update custom fields. Below is a sample code for the Pipedream component: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { convertkit: { type: "app", app: "convertkit", }, subscriberID: { type: "string", label: "Subscriber ID", }, earningHigh: { type: "string", label: "Earning High", }, earningLow: { type: "string", label: "Earning Low", }, instagram: { type: "string", label: "Instagram", }, }, async run({ steps, $ }) { const apiUrl = `https://api.convertkit.com/v3/subscribers/${this.subscriberID}`; const response = await axios($, { method: "PUT", url: apiUrl, params: { api_secret: this.convertkit.$auth.api_secret, }, data: { fields: { earning_high: this.earningHigh, earning_low: this.earningLow, instagram: this.instagram, }, }, }); return response; }, }); ### Explanation: 1. Props: The component defines several props for the ConvertKit app, subscriber ID, and custom fields (earningHigh, earningLow, instagram). 2. API Request: The component makes a PUT request to the ConvertKit API to update the subscriber’s custom fields. 3. Authorization: The API request includes the api_secret from the ConvertKit app authentication. 4. Custom Fields: The custom fields are sent in the request body to update the subscriber’s information. You can use this component in a Pipedream workflow to automate the process of adding and updating subscribers in ConvertKit based on data collected from a Google Form. Make sure to replace the placeholder values with actual data from your workflow.

This code work HOWEVER it’s not passing the API SECRET. Can you please add a FIELD to request the API SECRET?

To pass an API secret in your request, you can add a field for the API secret in the headers of your HTTP request. Here’s how you can modify your code to include the API secret: import axios from "axios"; export default defineComponent({ props: { apiSecret: { type: "string", label: "API Secret", description: "Your API secret key", }, }, async run({ steps, $ }) { const resp = await axios({ method: "POST", url: `https://jsonplaceholder.typicode.com/posts`, headers: { "Content-Type": "application/json", "X-API-Key": this.apiSecret, // Use the API secret from the props }, data: { name: "Luke", }, }); return resp; }, }); ### Explanation: 1. Props: I’ve added a props object with an apiSecret field. This allows you to input your API secret key when configuring the component in the Pipedream UI. 2. Headers: The X-API-Key header now uses this.apiSecret to pass the API secret key from the props. This setup ensures that your API secret is securely passed in the request headers. If you have any further questions or need more assistance, feel free to ask!