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 .