Digital Assistant and Mobile

Get Involved. Join the Conversation.

Topic

    Pallavi N
    Custom API - post Method
    Topic posted March 8, 2017 by Pallavi NBlue Ribbon: 750+ Points, last edited March 23, 2017 
    230 Views, 27 Comments
    Title:
    Custom API - post Method
    Summary:
    Custom API - post Method
    Content:

    Hi,

    I created a custom API which has an endpoint with POST method to call a connector API ( connects to EBS R12). Here is the code I am using

    service.post('/mobile/custom/ExpenseHeaderDetCust/HeaderDet', function (req, res) {

      console.log('getting ready to call POST /mobile/custom/ExpenseHeaderDetCust/HeaderDet');

      var sdk = req.oracleMobile;

      var optionList = {

      //uri: '/mobile/connector/ExpenseHeaderDetails'

      };

      var jsnObj = {

      Body: {

      "ExpenseCount": {

      "@xmlns": "http://vis1225.dpebs-server.com:8000/webservices/rest/ExpenseCount/get_smart_exp_cnt_dtls_f",

      "RESTHeader": {

      "xmlns": "http://vis1225.dpebs-server.com:8000/webservices/rest/ExpenseCount/header",

      "Responsibility": "SYSTEM_ADMINISTRATOR",

      "RespApplication": "SYSADMIN",

      "SecurityGroup": "STANDARD",

      "NLSLanguage": "AMERICAN",

      "Org_Id": "204"

      },

      "InputParameters": {

      "P_REPORT_HEADER_ID": "37345"

      }

      }

      }

      };

      optionList.body = JSON.stringify(jsnObj);

      optionList.headers = {'Content-Type': 'application/json;charset=UTF-8'};

      optionList.headers = {'oracle-mobile-backend-id': 'd838ab82-9755-4f54-bca1-38270afac134'};

      optionList.headers = {'Authorization': 'SU5BTEdBUllUTVRSSUFMX0RFVkVMT1BNRU5UMV9NT0JJTEVfQU5PTllNT1VTX0FQUElEOkFyZzJlanZfc3oxcW1h'};

      sdk.connectors.post('ExpenseHeaderDetails',optionList, function (error, response, body) {

      if (error) {

      res.send(response, error.message);

      } else {

      res.setHeader({'Content-Type': 'application/json;charset=UTF-8'});

      res.send(200, body);

      }

      });

      });

    };

    And I get this error when I test the custom API with status code 500

    {

      "message": "Custom Code Problem in callback: [object Object]"

    }

    Can anyone help to figure out, what might be wrong?

    Comment

    • Chris Muir

      Hi Pallavi

      Here's the MCS User Guide chapter for calling a connector which shows  POST example:

      https://docs.oracle.com/en/cloud/paas/mobile-cloud/mcsua/calling-mcs-apis-custom-code1.html#GUID-26DC731F-7C65-4209-95B2…

      Here's one of the examples with some additions from myself to provide more information *** your use case:

      
      

      service.get('/mobile/custom/incidentreport/weather/:city', function (req, res) {

        var body = {

          Header: {

            myHeader1: 'myValue1',

            myHeader2: 'myValue2'

          },

          Body: {

            GetWeather: {

            CityName: req.params.city,

            CountryName: 'Spain'

            }

          }

        };

        var optionList = {inType: 'json', versionToInvoke: '1.0'};

        req.oracleMobile.connectors.post('globalweather', 'GetWeather', body, optionList).then(

          function (result) {

            console.info("result is: " + result.statusCode);

            res.send(result.statusCode, result.result);

          },

          function (error) {

            console.info("error is: " + error.statusCode); 

            res.send(500, error.error);

          }

        );

      });

      For this version of the code as it dynamically defines the connector name as a parameter 'globalWeather', has to pass in as part of the optionList the version of the connector to invoke version (versionToInvoke: '1.0').

      The alternative is to refer to the connector name inline, which requires you to define the connector and its version as a dependency in the package.json file:

      
      

      service.get('/mobile/custom/incidentreport/weather/:city', function (req, res) {

        var body = {

          Header: {

            myHeader1: 'myValue1',

            myHeader2: 'myValue2'

          },

          Body: {

            GetWeather: {

              CityName: req.params.city,

              CountryName: 'Spain'

            }

          }

        };

        var optionList = {inType: 'json'};

        req.oracleMobile.connectors.globalWeather.post('GetWeather', body, optionList).then(

          function (result) {

            res.send(result.statusCode, result.result);

          },

          function (error) {

            res.send(500, error.error);

          }

        );

      });

      Hope this gives you a spark of inspiration for how to write the code.

      Regards,


      CM.

    • Upworkrinni

      Hi Chris,

      I have tried the same but getting the error- 500 with response-   {}.

      The payload is null in request.

      Here is the code-

      service.post('/mobile/custom/ExpenseHeaderDetCust/HeaderDet', function (req, res) {

              var sdk = req.oracleMobile;


              var body = {

                  Header: {

                      'Accept': 'application/json',

                      'Content-Type': 'application/json',

                      'Authorization': 'Basic c3lzYWRtaW46b3JhY2xlMTI=',

                      'oracle-mobile-backend-id': 'd838ab82-9755-4f54-bca1-38270afac134',

                      'oracle-mobile-uitooling-backend-name': 'Test',

                      'oracle-mobile-uitooling-backend-version': '1.0'

                  },

                  Body: {

                      'ExpenseCount': {

                          '@xmlns': 'http://vis1225.dpebs-server.com:8000/webservices/rest/ExpenseCount/get_smart_exp_cnt_dtls_f',

                          'RESTHeader': {

                              'xmlns': 'http://vis1225.dpebs-server.com:8000/webservices/rest/ExpenseCount/header',

                              'Responsibility': 'SYSTEM_ADMINISTRATOR',

                              'RespApplication': 'SYSADMIN',

                              'SecurityGroup': 'STANDARD',

                              'NLSLanguage': 'AMERICAN',

                              'Org_Id': '204'

                          },

                          'InputParameters': {

                              'P_REPORT_HEADER_ID': '37345'

                          }

                      }

                  }

              };

              var optionList = {

                  inType: 'json'

              };

              sdk.connectors.ExpenseHeaderDetails.post('ExpenseCount', body, optionList).then(

                  function (result) {

                      res.send(result.statusCode, result.result);

                  },

                  function (error) {

                      res.send(500, error.error);

                  }

              );

          });

    • Upworkrinni

      Hi Chris,

      I have tried the same but getting the error- 500 with response-   {}.

      The payload is null in request.

      Here is the code-

      service.post('/mobile/custom/ExpenseHeaderDetCust/HeaderDet', function (req, res) {

              var sdk = req.oracleMobile;

              var body = {

                  Header: {

                      'Accept': 'application/json',

                      'Content-Type': 'application/json',

                      'Authorization': 'Basic c3lzYWRtaW46b3JhY2xlMTI=',

                      'oracle-mobile-backend-id': 'd838ab82-9755-4f54-bca1-38270afac134',

                      'oracle-mobile-uitooling-backend-name': 'Test',

                      'oracle-mobile-uitooling-backend-version': '1.0'

                  },

                  Body: {

                      'ExpenseCount': {

                          '@xmlns': 'http://vis1225.dpebs-server.com:8000/webservices/rest/ExpenseCount/get_smart_exp_cnt_dtls_f',

                          'RESTHeader': {

                              'xmlns': 'http://vis1225.dpebs-server.com:8000/webservices/rest/ExpenseCount/header',

                              'Responsibility': 'SYSTEM_ADMINISTRATOR',

                              'RespApplication': 'SYSADMIN',

                              'SecurityGroup': 'STANDARD',

                              'NLSLanguage': 'AMERICAN',

                              'Org_Id': '204'

                          },

                          'InputParameters': {

                              'P_REPORT_HEADER_ID': '37345'

                          }

                      }

                  }

              };

              var optionList = {

                  inType: 'json'

              };

              sdk.connectors.ExpenseHeaderDetails.post('ExpenseCount', body, optionList).then(

                  function (result) {

                      res.send(result.statusCode, result.result);

                  },

                  function (error) {

                      res.send(500, error.error);

                  }

              );

          });

    • Pallavi N

      Hi Chris,

      I have tried the same but getting the error- 500 with response-   {}.

      The response is null.

      Here is the code-

      service.post('/mobile/custom/ExpenseHeaderDetCust/HeaderDet', function (req, res) {

              var sdk = req.oracleMobile;

              var body = {

                  Header: {

                      'Accept': 'application/json',

                      'Content-Type': 'application/json',

                      'Authorization': 'Basic c3lzYWRtaW46b3JhY2xlMTI=',

                      'oracle-mobile-backend-id': 'd838ab82-9755-4f54-bca1-38270afac134',

                      'oracle-mobile-uitooling-backend-name': 'Test',

                      'oracle-mobile-uitooling-backend-version': '1.0'

                  },

                  Body: {

                      'ExpenseCount': {

                          '@xmlns': 'http://vis1225.dpebs-server.com:8000/webservices/rest/ExpenseCount/get_smart_exp_cnt_dtls_f',

                          'RESTHeader': {

                              'xmlns': 'http://vis1225.dpebs-server.com:8000/webservices/rest/ExpenseCount/header',

                              'Responsibility': 'SYSTEM_ADMINISTRATOR',

                              'RespApplication': 'SYSADMIN',

                              'SecurityGroup': 'STANDARD',

                              'NLSLanguage': 'AMERICAN',

                              'Org_Id': '204'

                          },

                          'InputParameters': {

                              'P_REPORT_HEADER_ID': '37345'

                          }

                      }

                  }

              };

              var optionList = {

                  inType: 'json'

              };

              sdk.connectors.ExpenseHeaderDetails.post('ExpenseCount', body, optionList).then(

                  function (result) {

                      res.send(result.statusCode, result.result);

                  },

                  function (error) {

                      res.send(500, error.error);

                  }

              );

          });

    • Pallavi N

      Hi Chris,

      here is the screenshot of log.

      mcs_500_log.png

    • Chris Muir

      Can you look through the logs and see what is being recorded for the 500 error please?


      CM.

    • Chris Muir

      Hmm, this doesn't reveal much.  Do any of the relating logs show a stack trace or similar?

      CM.

    • Pallavi N

      Hi Chris,

      I don't see any useful information to trace out this issue from the logs.

      Thanks,

      Pallavi.

    • Chris Muir

      Hi Pallavi, unfortunately we don't have enough information here to debug the problem, all we have is an error code.  I've reverted an email to Joe to find out if your a paid customer whereupon we can get an SR lodged for you, or a trial customer.

      CM.

    • Pallavi N

      Hi Chris,

      We are on the Trial Version of MCS.Can we raise an SR?

      Thanks,

      Pallavi

    • Chris Muir

      This is what I'm asking Joe.

      CM.

    • Pallavi N

      Hi Chris,

      I still couldn't trace out the issue.And didn't hear back from joe.

      The connector is working fine. The problem is in calling the connector from custom API for POST Method. Could you please give me any inputs to resolve this issue.

      Thanks,

      Pallavi.

    • Chris Muir

      We're trying to find a development resource who can give you sometime.  Please be patient.


      CM.

    • Pallavi N

      Thank you, Chris!

    • Tom Ware

      What is your MCS identity domain?