How to Resolve "Authorization Failed" Error Due to Missing API Key in Convert Kit Custom API?

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

I’ve been using a custom API for Convert Kit. Here is the code.

import axios from "axios";

export default defineComponent({
  props: {
    convertkit: {
      type: "app",
      app: "convertkit",
    },
    subscriberId: {
      type: "string",
      label: "Subscriber ID",
      description: "The ID of the subscriber you want to update",
    },
    earningHigh: {
      type: "string",
      label: "Earning High",
    },
    earningLow: {
      type: "string",
      label: "Earning Low",
    },
    instagram: {
      type: "string",
      label: "Instagram",
    },
  },
  async run({ steps, $ }) {
    const url = `https://api.convertkit.com/v3/subscribers/${this.subscriberId}`;
    const params = {
      api_key: this.convertkit.$auth.api_key,
      api_secret: this.convertkit.$auth.api_secret,
      fields: {
        EARNING_HIGH: this.earningHigh,
        EARNING_LOW: this.earningLow,
        INSTAGRAM: this.instagram,
      },
    };

    return await axios($, {
      method: "PUT",
      url,
      params,
    });
  },
});

The code works BUT the URL is having an issue. When I use the API for CONVERT KIT I am getting an error.

https://api.convertkit.com/v3/subscribers/2651614298

The error I am getting is:

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

I do not see a field to plug in my API Key. Does this needed to be added to my code?

It looks like the issue is with how the API key is being passed in the request. In the ConvertKit API, the API key should be included in the query parameters, but it seems like there might be a formatting issue in your code. Here’s a revised version of your component code that should correctly pass the API key and other parameters: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { convertkit: { type: "app", app: "convertkit", }, subscriberId: { type: "string", label: "Subscriber ID", description: "The ID of the subscriber you want to update", }, earningHigh: { type: "string", label: "Earning High", }, earningLow: { type: "string", label: "Earning Low", }, instagram: { type: "string", label: "Instagram", }, }, async run({ steps, $ }) { const url = `https://api.convertkit.com/v3/subscribers/${this.subscriberId}`; const params = { api_key: this.convertkit.$auth.api_key, fields: { EARNING_HIGH: this.earningHigh, EARNING_LOW: this.earningLow, INSTAGRAM: this.instagram, }, }; return await axios($, { method: "PUT", url, params, }); }, }); ### Key Changes: 1. API Key in Params: Ensure the api_key is included in the params object. The api_secret is typically not required for this type of request, so it has been removed. 2. URL Formatting: Ensure the URL is correctly formatted without angle brackets. This should resolve the “API Key not present” error. If you continue to experience issues, please double-check that your API key is correctly set in the Pipedream app configuration for ConvertKit. If you need further assistance, you can visit Pipedream Support.

How can I output the URL to the screen?