<p>Please see the Sprout Forms <a href="https://sprout.barrelstrengthdesign.com/docs/forms/element-api.html" rel="nofollow noreferrer">Element API</a> documentation page. If it doesn't address your answer, please update your question and I can clarify further.</p>

<p>Here's the example from the docs of both a Form and Form Entries being retrieved from the Element API:</p>

<pre class="lang-php prettyprint-override"><code>&lt;?php

use barrelstrength\sproutforms\elements\Form;
use barrelstrength\sproutforms\elements\Entry;

return [
    'endpoints' =&gt; [
        'api/sproutforms/&lt;formId:\d+&gt;.json' =&gt; function($formId) {
            return [
                'elementType' =&gt; Form::class,
                'criteria' =&gt; ['id' =&gt; $formId],
                'one' =&gt; true,
                'transformer' =&gt; function(Form $form) {
                    foreach ($form-&gt;getFieldLayout()-&gt;getTabs() as $tab) {
                        foreach ($tab-&gt;getFields() as $field) {
                            $fields[] = [
                                'field' =&gt; $field,
                                'folder' =&gt; $field-&gt;getFieldInputFolder()
                            ];
                        }

                        $tabs[] = [
                            'title' =&gt; $tab-&gt;name,
                            'fields' =&gt; $fields
                        ];
                    }

                    return [
                        'handle' =&gt; $form-&gt;handle,
                        'tabs' =&gt; $tabs
                    ];
                },
            ];
        },
        'api/sproutforms/&lt;formId:\d+&gt;/entries.json' =&gt; function($formId) {
            return [
                'elementType' =&gt; Entry::class,
                'criteria' =&gt; [
                    'formId' =&gt; $formId,
                    'status' =&gt; 'unread'
                ],
                'paginate' =&gt; true,
                'transformer' =&gt; function(Entry $entry) {
                    return [
                        'id' =&gt; $entry-&gt;id,
                        'dateCreated' =&gt; $entry-&gt;dateCreated,
                        'title' =&gt; $entry-&gt;title,
                        'customField' =&gt; $entry-&gt;customField,
                    ];
                },
            ];
        }
    ]
];
</code></pre>

CC BY-SA 4.0
2020-04-27T21:59:22.437Z
2020-04-27T21:59:22.437Z
Ben Parizek
<p>The goal is to have an endpoint that takes starting id and limit parameters and returns a filtered list of Sprout Form submissions as JSON without the JSON Feed v1 metadata bits.</p>

<p>I've tried to set up an endpoint with Element API, but haven't gotten that working yet. I suspect my elementType is off. I know that there are integration options available in Sprout Forms but from the documentation it looks like it's only pushing the submissions as they come in, not as requested. I've got the endpoint set up on a single PHP page with it's own db table now as a proof of concept.</p>

<p>Is the best way forward to:
a) Complete configuring the element API endpoint.
b) Build a native Sprout Forms data integration.
c) Use custom PHP to get the data and return the JSON.
d) Or something else?</p>

<plugin-sproutforms><json>
How to export Sprout Form submissions with a JSON API endpoint?
# How to export Sprout Form submissions with a JSON API endpoint?

(Asked by: username_0 on 2020-04-22)

The goal is to have an endpoint that takes starting id and limit parameters and returns a filtered list of Sprout Form submissions as JSON without the JSON Feed v1 metadata bits.

I've tried to set up an endpoint with Element API, but haven't gotten that working yet. I suspect my elementType is off. I know that there are integration options available in Sprout Forms but from the documentation it looks like it's only pushing the submissions as they come in, not as requested. I've got the endpoint set up on a single PHP page with it's own db table now as a proof of concept.

Is the best way forward to:
a) Complete configuring the element API endpoint.
b) Build a native Sprout Forms data integration.
c) Use custom PHP to get the data and return the JSON.
d) Or something else?

**Tags:** plugin-sproutforms, json

---

## 1 answers

### Answer by username_1 on 2020-04-27. Score: 2 | Accepted answer

Please see the Sprout Forms Element API documentation page. If it doesn't address your answer, please update your question and I can clarify further.
Here's the example from the docs of both a Form and Form Entries being retrieved from the Element API:
 [
        'api/sproutforms/.json' => function($formId) {
            return [
                'elementType' => Form::class,
                'criteria' => ['id' => $formId],
                'one' => true,
                'transformer' => function(Form $form) {
                    foreach ($form->getFieldLayout()->getTabs() as $tab) {
                        foreach ($tab->getFields() as $field) {
                            $fields[] = [
                                'field' => $field,
                                'folder' => $field->getFieldInputFolder()
                            ];
                        }

                        $tabs[] = [
                            'title' => $tab->name,
                            'fields' => $fields
                        ];
                    }

                    return [
                        'handle' => $form->handle,
                        'tabs' => $tabs
                    ];
                },
            ];
        },
        'api/sproutforms//entries.json' => function($formId) {
            return [
                'elementType' => Entry::class,
                'criteria' => [
                    'formId' => $formId,
                    'status' => 'unread'
                ],
                'paginate' => true,
                'transformer' => function(Entry $entry) {
                    return [
                        'id' => $entry->id,
                        'dateCreated' => $entry->dateCreated,
                        'title' => $entry->title,
                        'customField' => $entry->customField,
                    ];
                },
            ];
        }
    ]
];


---

