Catch form submission and run REST API

When a form is submitted, I want to catch form fields and values, and run code to execute POST request.

Both form submission and POST REST API work fine (also thanks to Divhunt team support!).

In other posts, you provided code to run the API.

Summary

How to Trigger API? - #3 by dejan

Code to run the API you provided in that post:

let input = {
    id: 90, // Your REST API Request ID (find it inside admin panel from URL section
    properties: [ // Properties that are configured inside Request. 
        {key: 'property-key1', value: 'property-value2'},
        {key: 'property-key2', value: 'property-value2'}
    ]
};

mdActions.ItemGet('REST').Fn('run', {}, input, (success) => 
{
    console.log(success); // Will return {success, message, data}
}, 
(error) => 
{
    console.log(error);  // Will return {success, message}
});

What I am missing is:

  1. how to catch form submission fields
  2. how to pass them as ‘property-key1’ and ‘property-value1’ etc as expected in the code

Should all this be done within one script or several ones?
Should it/they be triggered on form success?

I made attempts, but it does not work as expected :sweat_smile:

Summary
  • Not sure if I should choose trigger = On Form Submit
  • not sure if I should create each form field as a const to reuse them in the values, or if using data.form.field_id is fine
if (data.form.id === 265) {

    let input = {
    id: 95, // Your REST API Request ID (find it inside admin panel from URL section
    properties: [ // Properties that are configured inside Request. 
        {key: 'prenom', value: data.form.prenom},
        {key: 'nom', value: data.form.nom}
    ]
};

mdActions.ItemGet('REST').Fn('run', {}, input, (success) => 
{
    console.log(success); // Will return {success, message, data}
}, 
(error) => 
{
    console.log(error);  // Will return {success, message}
});
}

Your support is greatly appreciated. Learning curve for Divhunt is high, but I am convinced it is worth it !

@dejan Could you help a little bit on this?
I am sure I am getting close to the solution, but a little help from you would make me gain a lot of time :slightly_smiling_face: