Skip to main content
Question

Type error when Setting a customer's attributes.

  • May 11, 2025
  • 1 reply
  • 12 views

Forum|alt.badge.img+2



export const setAttributes = async(

  req: Request,

  res: Response,

  next: NextFunction

) => {

  try {

  const {customer_id} = req.params;

  const attributeUrl = `https://api.revenuecat.com/v2/projects/${project_id}/customers/${customer_id}/attributes`;

  const url = new URL(attributeUrl);

  const attributes = [

    {

      name: "jhon"

    }

  ];

  const response = await fetch(url.toString(), {

    method: "POST",

    headers: {

      Authorization: `Bearer ${process.env.REVENUE_CAT_API_KEY}`,

      "Content-Type": "application/json",

    },

    body: JSON.stringify(attributes),

  });

  if (!response.ok) {

    const errorData = await response.json();

    const status = response.status;

    console.error(`Error from RevenueCat: ${status}`, errorData);

    switch (status) {

      case 401:

        return res.status(401).json({ error: "Invalid API key" });

      case 403:

        return res.status(403).json({ error: "Access denied. Insufficient permissions" });

      case 429:

        const retryAfter = response.headers.get("Retry-After");

        return res.status(429).json({

          error: "Rate limit exceeded",

          retryAfter: retryAfter,

        });

      default:

        return res.status(status).json(errorData);

    }

  }

  const data = await response.json();

  console.log("Successfully set attributes for customer", customer_id, data);

  res.status(200).json(data);

  } catch (error) {

    console.error("Error setting attributes:", error);

    next(error);

  }

};







when i call this function i am getting an error .  



Error from RevenueCat: 400 {

  doc_url: 'https://errors.rev.cat/parameter-error',

  message: "[{'name': 'jhon'}] is not of type 'object'",

  object: 'error',

  retryable: false,

  type: 'parameter_error'

}





if anyone knows the solution please help . 

This post has been closed for comments

1 reply

kaitlin
RevenueCat Staff
Forum|alt.badge.img+6
  • RevenueCat Staff
  • 404 replies
  • May 14, 2025

Hey ​@redain-28c3e6,

I believe we’re already communicating in a support ticket regarding this but for visibility, where the documentation refers to name and value, these are referring to the attributes name itself - such as $email, $displayName, or a custom attribute you’d like to send, then the value param will contain the value you’d like this attribute to be set as. For example, 

“$displayName”: “jhon”


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings