Problem with webhook to import

Troubleshooting an import into Wix collection from Google sheet using Zapier with wix-http-functions webhook.

  • The webhook error in Zapier is: “The app returned ‘Not Found’” 404 error.

I hope someone can easily point out the cause of this error.

  • Wix Backend js file for the import is named pgTypeA.js

  • Webhook address in Zapier: https://[accountName].wixsite.com/[siteName]/_functions/pgTypeA
    Question: Is this the correct form for the webhook URL?

I have repeatedly reviewed the Wix collection field keys (text and case-sensitive) and field types as matching the source data and the setup of the webhook data in Zapier.

  • Webhook action event in Zapier is set as “post”.

  • The payload type set for the webhook in Zapier is: json And set to “unflatten”.

  • The permissions for the collection in Wix (also named pgTypeA) are set as “custom” with inserts and updates enabled for “anyone.”
    Here is the test script in the pgTypeA.js file in the backend (editor did not flag any grammatical errors), which was derived from prototype posted by Andreas Kviby a couple years ago:

import wixData from 'wix-data';
import {ok, response} from 'wix-http-functions';

export function post_pgTypeA(request) {

 return request.body.json()
        .then(body => {

 let recordInsert = {
 "title": body.Title,
 "description": body.Description,
 "imageUrl": body.imageUrl,
 "linkButtonText": body.linkButtonText,
 "linkButtonUrl": body.linkButtonUrl,
 "authorName": body.authorName,
 "authorEmail": body.authorEmail
        };

 return wixData.insert('pgTypeA', recordInsert)
            .then(result => ok({body: JSON.stringify(result)}))
            .catch(err => response({status: 500, body: err}));
        }
    );
}

Frankly, with the webhook running between Wix and Zapier, I don’t know where the “catch” for the error can be reviewed for any more detail.

I hope someone may see an obvious error in these configurations.

Thank you very much for any assistance!

(P.S.: I would rather import directly into the Wix collection from the Google sheet, but that appears to require much more complex coding than using Zapier. )

Hi :raised_hand_with_fingers_splayed:

I don’t know why you typed it this way, but I think it’s what causing the problem

"imageUrl": body.imageUrl,request,

You have what appears to be value without a key, add some console.error to the module (I believe you’re running it on the backend) to make sure you don’t have any errors returned.

Hope this helps~!
Ahmad

Ahmad,
Thank you very much for looking so closely at my post and code. Unfortunately, I had spotted that mistake (which occurred through the auto complete function of the editor) earlier and had edited it out. But somehow the correction did not save. I have made the correction again, published the site, and closed/opened the editor a couple of times to be sure the save was completed. (Also corrected my original post of the code.)

I’ve also removed all the data fields in the Zapier webhook except the first (“title”), which of course is also the primary field in the collection.

But the 404 error still occurs🤔. So it does not appear to be a problem with mapping of the data fields in the webhook and the collection.

Is the webhook URL form correct as shown in my original post?

Any other suggestions are more than welcome!

Thanks again.

I think you’re NOT returning the JSON

 return wixData.insert('pgTypeA', recordInsert).then((result_ => {
         return ok({body: JSON.stringify(result)}))
 }.catch(err => response({status: 500, body: err}));

Notice the orange return above, in your code, you’re not returning the request status (ok).

Let’s just hope that solves the problem :pensive:

Ahmed,
Thank you again for taking time to review.

Doesn’t the first return (immediately following the export function) return JSON?

Anyway, I tried substituting your code, but got an “unexpected token” error in the editor for the orange ending parenthesis shown below. If I delete it, then the period in front of “catch” shows the same unexpected token error:

 return wixData.insert('pgTypeA', recordInsert).then((result_ => {
 return ok({body: JSON.stringify(result)}))
 }.catch(err => response({status: 500, body: err}));

So I revised you code as follows, which gave no errors in the editor, but may be incorrect for the purpose (apologize for my js illiteracy).


 return wixData.insert('pgTypeA', recordInsert).then(result => {
 return ok({body: JSON.stringify(result)})})
         .catch(err => response({status: 500, body: err}));

After publishing the site with this code change, the 404 error still occurred for the Zapier webhook.

Doug

I think I need to take a deeper look at the code, if you’re interested, send me a message on my profile.

Ahmad,
Thank you again for taking time to look at the basic webhook code. Since you do not note anything that is obviously incorrect, I will need to do more checking into Wix http-functions, unless someone else happens to spot a problem.
Doug