How is a POST API created and called?

8345.HelloWorldAPIv2.zip

I have attached a functioning GET and POST API, but I don't know how to view the json arguments sent to the API.

Example:the 'value': 'something to test' string. How do I get to that value in the API?.

        app.api.call('POST'app.api.buildURL('Hello/World/1'), {'value':'something to test'},
        {
            success: function(data){
                if(this.disposed){
                    return;
                }
                console.log(data);
                self.message = data;
                _.extend(selfself.message);
                self.render();
            },
            error: function (e) {
                console.log('error');
                console.log(e);
           }
        });
Parents
  • The result I get from the following is 'Hello World'.  I don't get anything from  value.

    Am I missing something?

    I am using the following API:

    <?php
    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

    class HelloWorldPOSTAPI extends SugarApi
    {
        public function registerApiRest()
        {
            return array(
                'HelloWorldPOSTAPI' => array(
                    //request type
                    'reqType' => array('GET','POST'),

                    //set authentication
                    'noLoginRequired' => false,

                    //endpoint path will equal Hello/WorldPOST
                    'path' => array('Hello'),

                    //endpoint variables. 
                    //'pathVars' => array('', ''),

                    //Json parameters to the end point
                    'jsonParams' => array('filter'),

                    //method to call
                    'method' => 'CallHelloWorldPOST',

                    //short help string to be displayed in the help documentation
                    'shortHelp' => '',

                    //long help to be displayed in the help documentation
                    'longHelp' => '',

                ),

            );
        }

        /**
         * Method to be used for Hello/World/ endpoint
         */
        public function CallHelloWorldPOST($api, $args)
        {
            return 'Hello World ' . $args['value'];
        }


    }
    and the following json, but it is not displaying the value.
    ({
        plugins: ['Dashlet'],
        render: function() {
            console.log(this);
            this.loadData();
            //console.log(this.model.get('contract_status')); //If in contract record this works
            this._super("render");
        },

    /**
         * @inheritdoc
     */
        initialize: function(options) {
            // call the parent's (View's) initialize function
            // passing options as an array
            this._super('initialize', [options]);
            this.loadData();



        },

        loadData: function(options){
            if (_.isUndefined(this.model)){
                return;
            }
            var self = this;
        
            app.api.call('POST'app.api.buildURL('Hello'), {'value':'something to test'},
            {
                success: function(data){
                    if(this.disposed){
                        return;
                    }
                    console.log(data);
                    self.message = data;
                    _.extend(selfself.message);
                    self.render();
                },
                error: function (e) {
                    console.log('error');
                    console.log(e);
               }
            });
        }

    })
Reply
  • The result I get from the following is 'Hello World'.  I don't get anything from  value.

    Am I missing something?

    I am using the following API:

    <?php
    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

    class HelloWorldPOSTAPI extends SugarApi
    {
        public function registerApiRest()
        {
            return array(
                'HelloWorldPOSTAPI' => array(
                    //request type
                    'reqType' => array('GET','POST'),

                    //set authentication
                    'noLoginRequired' => false,

                    //endpoint path will equal Hello/WorldPOST
                    'path' => array('Hello'),

                    //endpoint variables. 
                    //'pathVars' => array('', ''),

                    //Json parameters to the end point
                    'jsonParams' => array('filter'),

                    //method to call
                    'method' => 'CallHelloWorldPOST',

                    //short help string to be displayed in the help documentation
                    'shortHelp' => '',

                    //long help to be displayed in the help documentation
                    'longHelp' => '',

                ),

            );
        }

        /**
         * Method to be used for Hello/World/ endpoint
         */
        public function CallHelloWorldPOST($api, $args)
        {
            return 'Hello World ' . $args['value'];
        }


    }
    and the following json, but it is not displaying the value.
    ({
        plugins: ['Dashlet'],
        render: function() {
            console.log(this);
            this.loadData();
            //console.log(this.model.get('contract_status')); //If in contract record this works
            this._super("render");
        },

    /**
         * @inheritdoc
     */
        initialize: function(options) {
            // call the parent's (View's) initialize function
            // passing options as an array
            this._super('initialize', [options]);
            this.loadData();



        },

        loadData: function(options){
            if (_.isUndefined(this.model)){
                return;
            }
            var self = this;
        
            app.api.call('POST'app.api.buildURL('Hello'), {'value':'something to test'},
            {
                success: function(data){
                    if(this.disposed){
                        return;
                    }
                    console.log(data);
                    self.message = data;
                    _.extend(selfself.message);
                    self.render();
                },
                error: function (e) {
                    console.log('error');
                    console.log(e);
               }
            });
        }

    })
Children