WDE0027: The current user does not have permissions to insert on the collection

Question:
I am trying to insert data into a table in the CMS

Permissions and Privicy on the table are Set to view and add for everyone

My API key is correct

my Data being sent is …

Data to be sent to Wix CMS: {
“dataCollectionId”: “Affiliates”,
“dataItem”: {
“id”: “nywh46x”,
“data”: {
“contactName”: “Rodney Allen”,
“contactEmail”: “rakess70@gmail.com”,
“referralCode”: “nywh46x”
}
}
}

My header is:

Headers for Wix CMS request: {
“Authorization”: “Bearer [MYCORRECT KEY IS HERE]”,
“Content-Type”: “application/json”
}

This is my Function in my APP

// Function to insert user data into Wix CMS
async function insertAffiliateData(name: string, email: string, referralCode: string) {
try {
const data = {
dataCollectionId: ‘Affiliates’,
dataItem: {
id: referralCode,
data: {
contactName: name,
contactEmail: email,
referralCode: referralCode,
},
},
};

const headers = {
  Authorization: `Bearer ${process.env.WIX_API_KEY}`,
  'Content-Type': 'application/json',
};

console.log("Data to be sent to Wix CMS:", JSON.stringify(data, null, 2));
console.log("Headers for Wix CMS request:", JSON.stringify(headers, null, 2));

const response = await axios.post(
  'https://www.wixapis.com/wix-data/v2/items',
  data,
  { headers }
);

console.log("Wix CMS Response:", response.data);

} catch (error: any) {
// Type guard to check if error is an Axios error
if (error.response && error.config) {
console.error(“Error inserting data item:”, error.message);
console.error(“Axios Error Details:”, error.response.data || error.toJSON());
} else {
console.error(“Unknown error inserting data item:”, error);
}
}
}

Product:
Wix Data

What are you trying to achieve:
I am simply trying to add a record to my Wix CMS via a Next JS APP

What have you already tried:
I have tried to use the documentation and Search feature to answer this

Additional information:
This is the first time I am trying to interface with a wix system so any help would be greatly welcomed

Have you changed the permissions of the CMS which user can be updated or add item in the CMS collection?

yes

I don’t know much about integrating cms to the external site but I think you will get an answer by checking this Wix data SDK

Or use help of Wix AI assistant.

I used both. That is how I got the code. I need someone who can trobleshoot why it is not authenticating. Every information says all I need is the API for authentication but that seems to say the user (which should be everyone) does not authority.