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

default discord avatar
christopher.nowlan
6 months 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',
                },
            
            }
        )
  • default discord avatar
    Jarrod
    6 months ago

    Yes that is possible

  • default discord avatar
    christopher.nowlan
    6 months ago

    @Jarrod Ive been getting a 403 error

  • default discord avatar
    Jarrod
    6 months ago

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

  • default discord avatar
    christopher.nowlan
    6 months 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?

  • default discord avatar
    Martin R
    6 months 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

  • default discord avatar
    Jarrod
    6 months ago

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

  • default discord avatar
    christopher.nowlan
    6 months ago

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

  • default discord avatar
    Jarrod
    6 months ago
Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.