Invalid Parameter : Custom Endpoint

I am new to sugarCRM
I had created a custom module(source IP) called order and its working fine. And I had created a custom API for the order module and I exposed that endpoint to different application in different server. The API was tested using Postman and was working fine. Whenever application (destination ip) hits order API in sugarCRM.,SugarCRM is throwing invalid parameter(error code 422) .
Below is the response
{"error":"invalid_parameter","error_message":"A parameter in your request was invalid." }
Version used is 10.3 (Enterprise)

How to solve this problem ?

  • Can you share the content of method registerApiRest for that custom api? Also you can share the url external api is calling?

    Regards

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • If your call works in Postman but not from your other server I would check whether you are passing authentication correctly.

    Are you using curl and passing your OAuth token as a parameter instead of adding it to the header?

    Fullscreen
    1
    curl_setopt($curl_request, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "oauth-token: {$oauthtoken}"))
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • Hi André Lopes,

    Thank you for your reply.
    Below is my url and registerApiRest method

    URL :  http://{{URL}}/sugarcrm/rest/v10/Ord_Orders/UpdateOrderMethod

    Method :

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    public function registerApiRest()
    {
    return array(
    'MyGetEndpoint' => array(
    //request type
    'reqType' => 'PUT',
    //set authentication
    'noLoginRequired' => false,
    //endpoint path
    'path' => array('Ord_Orders','UpdateOrderMethod'),
    //endpoint variables
    'pathVars' => array('', ''),
    //method to call
    'method' => 'UpdateOrderMethod',
    //short help string to be displayed in the help documentation
    'shortHelp' => 'updating an order in SugarCRM',
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • Hi Francesca Shiekh,

    Thank you for the reply.

    Curl isn't used to call API. Javascript is used to call API in the other server. Below is the procedure used to call the API 
    All the sugarCRM inbuilt stock API's are working properly. with the other server. Only custom module's API is not working.

    Once the access token is generated from below url :  
    http://{​​​​​​​​{​​​​​​​​URL}​​​​​​​​}​​​​​​​​/sugarcrm/rest/v10/oauth2/token   (token is generated from this url)


    will be passed in the headers as Bearer token to update orderAPI
    http://{​​​​​​​​{​​​​​​​​URL}​​​​​​​​}​​​​​​​​/sugarcrm/rest/v10/Ord_Orders/UpdateOrderMethod


    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    <propertyMap>
    <property>
    <name>Request-Line</name>
    <value>PUT /sugarcrm/rest/v10/Ord_Orders/UpdateOrderMethod HTTP/1.1</value>
    </property>
    <property>
    <name>Cookie</name>
    <value>PHPSESSID=6b1c70d0-6571-4969-b613-6697b2a2311a; download_token_custom=d6794d5a-e532-44f8-b655-15efcb2b893e</value>
    </property>
    <property>
    <name>Cookie</name>
    <value>PHPSESSID=lncpj8nrnjqdutfuh205vao8rr; path=/</value>
    </property>
    <property>
    <name>Authorization</name>
    <value>Bearer 6b1c70d0-6571-4969-b613-6697b2a2311a</value>
    </property>
    <property>
    <name>Accept</name>
    <value>*/*</value>
    </property>
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • Sorry ,

    I can't see what the problem is other that v10 being superseded by rest v11 in more recent versions, but I don't see why that would break it. Maybe André will have more insight for you.

  • So, I may be totally off base, but I looked at some API documentation, if I read it right Bearer Token support was added in v11

    https://sugarclub.sugarcrm.com/dev-club/b/dev-blog/posts/the-sugar-rest-api-adds-support-for-oauth-2-0-bearer-tokens-in-fall-18

    which would mean that, assuming you are not many years behind on your version, if you just change your http from

    http://{​​​​​​​​{​​​​​​​​URL}​​​​​​​​}​​​​​​​​/sugarcrm/rest/v10/Ord_Orders/UpdateOrderMethod

    to 

    http://{​​​​​​​​{​​​​​​​​URL}​​​​​​​​}​​​​​​​​/sugarcrm/rest/v11/Ord_Orders/UpdateOrderMethod

    It might work?

    I admit I don't have a full understanding of the API Authentication processes... so again, I'll defer to someone else.

    sugarclub.sugarcrm.com/.../api-authentication-primer

  •   
    We had changed the v10 to v11 in the API : http://{​​​​​​​​{​​​​​​​​URL}​​​​​​​​}​​​​​​​​/sugarcrm/rest/v11/Ord_Orders/UpdateOrderMethod but still we are getting the same error.

    Is there any way that we can debug here before it hit the entrypoint . Either  the request and headers are proper.
    http://{​​​​​​​​{​​​​​​​​URL}​​​​​​​​}​​​​​​​​/sugarcrm/rest/v10/Ord_Orders/UpdateOrderMethod

  • Sorry, it's really hard to immagine what might be going on, since you say it works through Postman.

    I would start by looking at all the logs: php, sugar, console to see if you can see anything.



  • We had debugged one more thing ie., the headers are hitting sugarCRM has XML but the request parameters are passing as JSON for same API.

    There is no logs inside php, mysql, apache and sugarCRM. 


  • Hi Rajinikanth,

    From the whole thread It seems that you will feed all the API parameters like URL, headers, cookies etc  in XML format to your external application and the application will parse the XML and call the API Endpoint. 
     
    If so,

    The issue may because of your external application is failing to call POST API requests. Can you once try calling the Sugar's stock API for creating an Accounts "POST /Accounts" with some request body. 

    You can use the below link as reference 
    https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_11.0/Integration/Web_Services/REST_API/Endpoints/module_POST/


    By this you may get some clue about the issue.

1 2