Wix-forms.v2 – API not working?

Hello all,

I am starting this forum to see if anyone has any success with the new Wix Forms V2 API. Since the changes to Wix Forms, the data no longer goes to the content manager (CMS) and is accessible from the dashboard. The API documentation (here) lists a a query builder but it does not work, at least on my end. I am testing the API inside the Editor X editor and am curious if anyone has gotten it to work? Here’s an example of a call I am trying to do:

import { submissions } from 'wix-forms.v2';

export async function test() {
    const results = await submissions
    .querySubmissionsByNamespace()
    .descending('_id')
    .find();

    const returnedItems = results.items;

    if (returnedItems.length > 0) {
        console.log(returnedItems, 'check this item')
        return returnedItems;
    } else {
        // Handle if no matching items found
    }
}

I have tried the above in both a backend file and page code. Still no luck.

The errors I am getting are all revolved around the namespace. All I am able to view is the form name, in this case “Contact us”. I tried placing it as a parameter like below:

import { submissions } from 'wix-forms.v2';
  
 async function querySubmissionsByNamespace() {
   const { items } = submissions.querySubmissionsByNamespace()
   .namespace("wix.form_app.form") // where do I get the namespace ID???
   .find();
 }

as well as this:

const results = await submissions
    .querySubmissionsByNamespace('Contact us')
    .descending('_id')
    .find();

For starters, the IDE shows errors for the “.querySubmissionsByNamespace()” parameter as well as the “.namspace()” parameter. But if you ignore the errors, the code still renders but logs a console error regarding the namespace.

Below is the common error I am seeing:

So I guess this leaves me with a couple of questions:

  1. Has anyone gotten a query for the Wix Forms V2 API to work?
  2. Does anyone know where to locate the namespace?
  3. Does this only work in Studio (not Editor X or editor)?
  4. Is their documentation not up to date?

Yes, I am aware this API is in developer preview which makes me believe that it is not fully functional yet, is that the case?

After working through the the post above with the velo team, the code below worked for me. Be sure to include the elevate call or it will return a forbidden error code.

SOLUTION BELOW:

// this one works
export async function querySubmissionsByNamespace() {
    const elevatedSubmissions = wixAuth.elevate(submissions.querySubmissionsByNamespace)
    try {
        const items = await elevatedSubmissions().eq('namespace', 'wix.form_app.form').find()
        return items
    } catch (error) {
        console.error(error)
    }
}
1 Like