Should I Use POST Instead of PUT for Storing Data in Convert Kit's Custom Field in Pipedream?

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

In Pipedream, I am attempting to use the Convert Kit / Build Any Convert Kit Request action.

I am trying to store into the custom field. I am testing the request which is not giving me any errors. However, I can see that the fields are empty.

I am using PUT. Should I be using POST.

To determine whether you should use PUT or POST for your Convert Kit request, it’s important to understand the difference between these HTTP methods: - POST is generally used to create a new resource. If you’re adding new data to a custom field, POST might be appropriate. - PUT is typically used to update an existing resource. If you’re updating an existing custom field with new data, PUT would be the correct choice. If your intention is to update an existing custom field in Convert Kit, then using PUT is appropriate. However, if you’re trying to add new data to a custom field, you might want to try using POST instead. If you’re still experiencing issues after adjusting the HTTP method, I recommend checking the following: 1. Ensure that the endpoint URL is correct for the action you’re trying to perform. 2. Verify that the payload you’re sending matches the expected format for the API. 3. Double-check any authentication details to ensure they’re correct. If the issue persists, you can reach out to Pipedream support for further assistance by visiting Support - Pipedream.

This is what was returned:

httpRequest
auth
{6}
app
{3}
authType:
keys
id:
app_XGehja
nameSlug:
convertkit
integratedAuth
{2}
ap
{3}
mask
{4}
password:
************
token:
type:
integrated_auth
username:
************
body
{4}
contentType:
application/json
fields
[3]
0
{2}
name:
earning_high
value:
high
1
{2}
name:
earning_low
value:
low
2
{2}
name:
instagram
value:
ig handle
mode:
fields
type:
fields
headers
[1]
method:
PUT
params
[1]
0
{3}
disabled:
true
name:
value:
tab:
Body
url:
https://api.convertkit.com/v3/subscribers/2651614298

As you can see the values are going thru. I’m not getting any errors. But nothing is storing on the ConvertKit side.

It seems like you’re trying to update a subscriber on ConvertKit using a PUT request, but the data isn’t being stored as expected. Here are a few things you can check to troubleshoot this issue: 1. API Endpoint: Ensure that the URL you’re using is correct and matches the ConvertKit API documentation for updating subscribers. The URL should be in the format https://api.convertkit.com/v3/subscribers/{subscriber_id}. 2. HTTP Method: Verify that the HTTP method is correct. For updating resources, PUT is typically used, but double-check the ConvertKit API documentation to confirm. 3. Authentication: Make sure that your API key and secret are correctly included in the request. ConvertKit requires these for authentication. They should be passed as query parameters or in the headers, as specified in the ConvertKit API documentation. 4. Request Body: Ensure that the request body is correctly formatted as JSON and includes all required fields. The fields should match the expected parameters for updating a subscriber in ConvertKit. 5. Response Handling: Check the response from the API call. Even if there are no errors, the response might contain information about why the update isn’t being applied. Look for any status codes or messages that could indicate an issue. 6. Permissions: Ensure that your API key has the necessary permissions to update subscriber data. If you’ve verified all of the above and the issue persists, consider reaching out to ConvertKit support or visiting their documentation for further assistance. Additionally, you can visit Pipedream Support for more support options. If you need further help with the code or configuration, feel free to provide more details, and I’ll do my best to assist you!

Would the data I am attempting to store go under HEADER or BODY?

To determine whether the data you are attempting to store should go under the HEADER or BODY, you need to consider the context of your request: 1. HEADER: This is typically used for metadata about the request. Common examples include authentication tokens, content types, and other configuration settings that the server needs to process the request correctly. If your data is related to these aspects, it should go in the HEADER. 2. BODY: This is where the main content of your request goes. If you are sending data that needs to be processed, stored, or manipulated by the server (like JSON payloads, form data, etc.), it should go in the BODY. If you can provide more details about the type of data you’re working with, I can give more specific guidance.

I am just storing text.

How can I get a human that works at Pipedream to look at this?

I’m sorry to hear you’re having trouble. To get in touch with a human at Pipedream, you can visit their support page at Support - Pipedream and submit a support ticket. They will be able to assist you with your issue.

Under RESULTS, there is EXPORTS I see all of the fields:

{"subscriber":{"id":2651614298,"first_name":"Steven","email_address":"[meatyyumsteve@gmail.com](mailto:meatyyumsteve@gmail.com)","state":"active","created_at":"2024-04-11T19:04:06.000Z","fields":{"earning_high":null,"earning_low":null,"instagram":null,"last_name":null,"phone_number":null,"rh_isref":null,"rh_partner":null,"rh_partner_name":null,"rh_source":null,"rh_subid":null,"role":null,"shipping_id":null}}}

It’s clear that Pipedream is able to see all of the custom fields from Convert Kit.

The question is why aren’t the values I’m sending it storing to Convert Kit?

Under the INPUTS tab, under PARAM and BODY, I see the values I’m trying to send.

It seems like you’re experiencing an issue with sending data to ConvertKit via Pipedream, where the values aren’t being stored as expected. Here are a few steps you can take to troubleshoot and resolve this issue: 1. Verify API Request: Ensure that the API request being made to ConvertKit is correctly formatted and includes all necessary fields. Double-check the endpoint URL, HTTP method, headers, and body parameters. 2. Check API Response: Look at the response from ConvertKit in the Pipedream workflow to see if there are any error messages or status codes that could indicate why the data isn’t being stored. A successful request should typically return a 200 status code. 3. Field Mapping: Make sure that the fields in your request body match the expected field names in ConvertKit. Any mismatch in field names could result in the data not being stored correctly. 4. Authentication: Confirm that the authentication credentials (API key or OAuth token) are correct and have the necessary permissions to perform the action you’re attempting. 5. Logs and Debugging: Use Pipedream’s logging features to output the request and response data for further inspection. This can help identify any discrepancies or issues in the data being sent. 6. ConvertKit Documentation: Review the ConvertKit API documentation to ensure that you’re using the correct API endpoints and parameters for the action you’re trying to perform. If you’ve checked all of the above and are still experiencing issues, you might consider reaching out to Pipedream support for further assistance. You can visit Support - Pipedream for more support options.

When I call the PUT URL,
https://api.convertkit.com/v3/subscribers/2651614298

I get:

{
  "error": "Authorization Failed",
  "message": "API Key not present"
}

It seems like the error you’re encountering is due to the absence of the API key in your request to the ConvertKit API. To resolve this, you need to ensure that your API key is included in the request parameters. Here’s an example of how you can make a PUT request to the ConvertKit API using Pipedream, ensuring that the API key is included: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { convertkit: { type: "app", app: "convertkit", }, }, async run({ steps, $ }) { const subscriberId = "2651614298"; // Replace with your subscriber ID const url = `https://api.convertkit.com/v3/subscribers/${subscriberId}`; return await axios($, { method: "PUT", url, params: { api_key: `${this.convertkit.$auth.api_key}`, api_secret: `${this.convertkit.$auth.api_secret}`, }, data: { // Include any data you need to update the subscriber }, }); }, }); ### Key Points: - Ensure you replace "2651614298" with the actual subscriber ID you want to update. - Add any additional data you need to send in the data object. - Make sure your ConvertKit API key and secret are correctly set up in the Pipedream app configuration. If you continue to experience issues, please verify that your API key and secret are correct and that they have the necessary permissions to perform the requested action. If you need further assistance, you can visit Pipedream Support for more help.

Can you add the additional variables and value to the code:

earning_high
14000

To add an additional variable and value to your code, you can define a new variable named earning_high and assign it the value 14000. Here’s a simple example of how you might do this in a JavaScript context: ```
// Define the variable and assign the value const earning_high = 14000; // You can now use earning_high in your code console.log(The earning high is set to: ${earning_high});

I figured it out:

import { axios } from "@pipedream/platform";

export default defineComponent({
  props: {
    convertkit: {
      type: "app",
      app: "convertkit",
    },
  },
  async run({ steps, $ }) {
    const subscriberId = "xxxxxxxxx";
    const url = `https://api.convertkit.com/v3/subscribers/${subscriberId}`;

    // Extract values from steps
    const earningHigh = steps.get_high.$return_value[0][0];
    const earningLow = steps.get_low.$return_value[0][0];
    const instagram = steps.trigger.event.body["fields[ig_name][value]"];

    return await axios($, {
      method: "PUT",
      url,
      params: {
        api_secret: "xxxxxxxxx",
      },
      data: {
        fields: {
          earning_high: earningHigh,
          earning_low: earningLow,
          instagram: instagram
        }
      },
      headers: {
        "Content-Type": "application/json",
        "User-Agent": "pipedream/1"
      }
    });
  },
});

Your code for updating a subscriber’s information in ConvertKit looks mostly correct. However, there are a few improvements and corrections you can make: 1. Remove Angle Brackets from URL: Ensure the URL does not include angle brackets (< >). 2. Use this.convertkit.$auth.api_secret: Instead of hardcoding the api_secret, use the this.convertkit.$auth.api_secret to access the API secret securely. Here’s the revised code: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { convertkit: { type: "app", app: "convertkit", }, }, async run({ steps, $ }) { const subscriberId = "xxxxxxxxx"; const url = `https://api.convertkit.com/v3/subscribers/${subscriberId}`; // Extract values from steps const earningHigh = steps.get_high.$return_value[0][0]; const earningLow = steps.get_low.$return_value[0][0]; const instagram = steps.trigger.event.body["fields[ig_name][value]"]; return await axios($, { method: "PUT", url, params: { api_secret: this.convertkit.$auth.api_secret, }, data: { fields: { earning_high: earningHigh, earning_low: earningLow, instagram: instagram, }, }, headers: { "Content-Type": "application/json", "User-Agent": "pipedream/1", }, }); }, }); ### Key Points: - URL: Ensure the URL is correctly formatted without angle brackets. - API Secret: Use this.convertkit.$auth.api_secret to securely access the API secret. - Headers: The headers are correctly set for a JSON request. This should help you update the subscriber’s information in ConvertKit using the Pipedream component. If you encounter any issues, please ensure your API credentials are correct and that the subscriber ID is valid.

I got the following error.

Timestamp
4/17/2025, 9:53:18 AMDuration
521ms
Code Error
Unterminated string constant (1:22)

I’m going to go back to my code.

The error message “Unterminated string constant (1:22)” indicates that there is a syntax error in your code, specifically related to a string that hasn’t been properly closed. This usually happens when you start a string with a quotation mark (either single ' or double "), but forget to close it with the matching quotation mark. Here’s what you can do to fix this error: 1. Check your strings: Go through your code and ensure that every string starts and ends with the same type of quotation mark. For example, "This is a string" or 'This is another string'. 2. Look for missing quotes: If you have a long line of code, it’s easy to miss a closing quotation mark. Carefully check each string to ensure it’s properly closed. 3. Review the error location: The error message indicates the location of the error as (1:22), which means line 1, character 22. Check this specific location in your code to find the unterminated string. 4. Use syntax highlighting: If you’re using a code editor with syntax highlighting, it can help you visually identify strings that aren’t properly closed, as they may appear in a different color. If you continue to experience issues or need further assistance, you can visit Pipedream Support for more help.