AnsweredAssumed Answered

Save multiple records through API REST

Question asked by Oscar Castro on Oct 24, 2016
Latest reply on Nov 3, 2016 by sidhu sidhu

Hi,

I have a custom module related to Accounts module (Account - one to many - custom module records), i need to save those records from a custom sidecar controller. The records are in a structure like this:

[{"id":"7974f951-4541-b8e8-6f23-57fbf6842696","fecha_pago_acordada":"2016-10-18","valor_pagar":1231},
{"id":"1434f671-4541-bf79-4523-fv5hf6858996","fecha_pago_acordada":"2016-11-18","valor_pagar":567}]

I used the api previously to fetch the same records, but the REST API using GET method.

'getCuotas' => array(
                'noLoginRequired' => true,
                // What type of HTTP request to match against, we support GET/PUT/POST/DELETE
                'reqType' => 'GET',
                // This is the path you are hoping to match, it also accepts wildcards of ? and <module>
                'path' => array('opal_Cuotas', 'get_cuotas', '?'),
                // These take elements from the path and use them to populate $args
                'pathVars' => array('', '', 'record'),
                // This is the method name in this class that the url maps to
                'method' => 'getCuotas',
                // The shortHelp is vital, without it you will not see your endpoint in the /help
                'shortHelp' => 'Lista las cuotas de una poliza',
                // The longHelp points to an HTML file and will be there on /help for people to expand and show
                'longHelp' => '',
            ),

With this js function:

App.api.call('GET', App.api.buildURL('opal_Cuotas/get_cuotas/'+this.model.get('id')), null, {
            success: function (data) {
                console.log(data);
            },
            error: function (e) {
            }
        }, this);

Now, I need to save this records, using the REST API also.

 

How can i do that?

Thanks for the help.

Outcomes