Just wanting to know if its possible to read form submission data using a get method like
const response = await fetch(
`${process.env.NEXT_PUBLIC_CMS_URL}/api/form-submissions/${resultsId}`,
{
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
}
)
Yes that is possible
@Jarrod Ive been getting a 403 error
By default, read access on this collection is locked down to logged in users
I would assume I could change access to read but that would be opening it up to the public to read all submission data?
Enable API key in your users collection.
auth: {
useAPIKey: true,
},
Then add the API-Key to you header.
const response = fetch(
`${process.env.NEXT_PUBLIC_CMS_URL}/api/form-submissions/${resultsId}`,
{
headers: {
Authorization: `users API-Key <your api key>`,
},
}
).then<Meta>((res) => res.json());
Remember only to use the fetch with server render, or else you expose your API-Key
Or you can log in via the api, and then send “credentials”: “include” in your request 🙂
Is there an example of this or could you point me in the direction of the docs for this.
Yep! Check out this section:
https://payloadcms.com/docs/authentication/overview#http-only-cookiesStar
Discord
online
Get help straight from the Payload team with an Enterprise License.