Question:
I have Data Hooks firing only on some insertions into a collection, not on others. Specifically, I can only get the datahook to fire when data is added to this database manually via the wix editor or I manually call on a page the sendRequest function (in which case the hook is not firing, so basically the hook does not work when the website itself inserts the data)
Product:
In Wix Editor I set up a simple data hook that makes an API request to some dummy 3rd party endpoint, in a function in another jsw I call sendRequest (using the Velo Dev Tools). Here is my data.js
import { sendRequest } from 'backend/sendData.jsw';
export function Forms$contact02_afterInsert(item, context) {
// This function will be triggered after a new item is updated into your Quote Request Form collection.
console.log('Data Hook Triggered:', item);
sendRequest(item);
return Promise.resolve(item);
}
This actually does trigger and send out fetches for my API requests if I go into the backend and manually input something into the form. I have confirmed getting fetch requests from wix when I do this, which is why I didn’t bother to clutter this question with that code.
However, when I try to use the form on the website (which is a Wix App Collections Forms collection), the form will actually append data to the (same) collection but will not make any API requests. In case I somehow was stuck with a legacy form I also tried changing this to After Update but the same issues still persisted (updating in the wix editor triggered the endpoint but submitting the form did not).
What are you trying to achieve:
I am trying to just make a form which is used to submit data fire off and forward the data to a 3rd party api. For now just getting that communicate with the endpoint upon form submission would be reward enough.
What have you already tried:
I looked at some other forum posts here such as
That one gave me the idea of adding the Promise, but even without it I had identical performance.
And none seem to really hit the same base. The trigger works, but it only works when I’m not using the website. I have tried pushing many new revisions since I made this change as well. I did temporarily start manually sending requests embedded on clicking a submit button on the home page when you click a button and that also did hit the API, but this wont work because credential info is needed and production will ultimately involve authenticated endpoints so I can’t just embed that info into the frontend.
Additional information:
This is for now just pinging some dummy api I have set up to see all requests, mangled or not, so if there was anything coming I would know. I know the requests are successful when called which is why I just provided the simplified sendRequest(…) stuff. This is also actually exactly how the data.js file is coded so there isn’t any stripping down of the code.