Like what we’re doing? Star us on GitHub!

Is there way to read form submission data from the Form Builder plugin?

christopher.nowlan
2 weeks ago
9

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',
                },
            
            }
        )
  • Jarrod
    Payload Team
    2 weeks ago

    Yes that is possible

  • christopher.nowlan
    2 weeks ago

    @Jarrod Ive been getting a 403 error

  • Jarrod
    Payload Team
    2 weeks ago

    By default, read access on this collection is locked down to logged in users

  • christopher.nowlan
    2 weeks ago

    I would assume I could change access to read but that would be opening it up to the public to read all submission data?

  • Martin R
    2 weeks ago

    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

  • Jarrod
    Payload Team
    2 weeks ago

    Or you can log in via the api, and then send “credentials”: “include” in your request 🙂

  • christopher.nowlan
    2 weeks ago

    Is there an example of this or could you point me in the direction of the docs for this.

  • Jarrod
    Payload Team
    2 weeks ago
Open the post
Continue the discussion in Discord
Can't find what you're looking for?
Get help straight from the Payload team with an Enterprise License.Learn More