Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

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

default discord avatar
christopher.nowlan2 years ago
8

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',
                },
            
            }
        )
  • discord user avatar
    jarrod_not_jared
    2 years ago

    Yes that is possible

  • default discord avatar
    christopher.nowlan2 years ago
    @281120856527077378

    Ive been getting a 403 error

  • discord user avatar
    jarrod_not_jared
    2 years ago

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

  • default discord avatar
    christopher.nowlan2 years 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
    Deleted User2 years 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

  • discord user avatar
    jarrod_not_jared
    2 years ago

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

  • default discord avatar
    christopher.nowlan2 years ago

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

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.