I am trying to create a collection using the astrajs/collections. I am also using the netlify cli to test my application. So I proceeded to make a small post to check if my database is working. Using the following code. The expected behavior is to create a post like this:
- a post: { title: "My first post" }
I did check my credentials inside my .env file it seems fine. This was the full error
Request from ::ffff:127.0.0.1: GET /.netlify/functions/addData Error: Request Failed: [object Object] Stack Trace: Request failed with status code 401 at axiosRequest (D:\tiktokclone\node_modules\@astrajs\rest\src\rest.js:126:11) at processTicksAndRejections (internal/process/task_queues.js:93:5) at async AstraClient._request (D:\tiktokclone\node_modules\@astrajs\rest\src\rest.js:199:22) at async AstraClient.put (D:\tiktokclone\node_modules\@astrajs\rest\src\rest.js:263:12) at async AstraCollection._put (D:\tiktokclone\node_modules\@astrajs\collections\src\collections.js:69:22) at async Object.exports.handler (D:\tiktokclone\functions\addData.js:17:5)
Response with status 500 in 742 ms.
const astraClient = await createClient({ astraDatabaseId: process.env.ASTRA_DB_ID, astraDatabaseRegion: process.env.ASTRA_DB_REGION, applicationToken: process.env.ASTRA_DB_APPLICATION_TOKEN, }); const posts = astraClient .namespace(process.env.ASTRA_DB_KEYSPACE) .collection(collection); try { await posts.create("a post", { title: "my first post", }); return { statusCode: 200, }; } catch (e) { console.error(e); return { statusCode: 500, body: JSON.stringify(e), }; }