tsgrp / OpenContent

TSG's Web Services for ECM Repositories
8 stars 4 forks source link

Send Email endpoint - entire endpoint should use a POST json payload #58

Closed mikeblum closed 9 years ago

mikeblum commented 9 years ago

Since the re-factor of SendEmail endpoints into 1.core, the /rest/sendEmail endpoint now expects a list of required request parameters as GET parameters in the url. To make this endpoint easier to use/one-touch json-payloaded call, rather then a very manual and hacky process in the front-end of converting what should be a json-ball of attributes into a url-encoded GET string. see thi snippet:

var params = {
                    'subject': this.psi.get('name') + ': submitted ' + Moment().format(),
                    'from': app.user.id,
                    'to': addresses,
                    'attachments': supportingDocIds,
                    'body': this.psi.get('name') + ' was submitted on ' + Moment().format()
                };
                //build url parameters list
                var paramsList = [];
                var url = app.serviceUrlRoot + '/email/sendEmail?';
                _.each(params, function(value, key){
                    if(value && _.isArray(value)){
                        if(value.length > 0){
                            value = value.join(',');
                            paramsList.push(key + '=' + encodeURIComponent(value));
                        }
                    }else{
                        if(value && value !== ''){
                            paramsList.push(key + '=' + encodeURIComponent(value));
                        }
                    }
                }, this);
                url += paramsList.join('&');
                $.ajax({
                    type: "POST",
                    url: url,
                    data: {},
                    dataType: 'json',
                    success: function(data){
                        deferred.resolve();
                    }
                });
mikeblum commented 9 years ago

working for submit timing emails. closing.