agilecrm / nodejs

82 stars 81 forks source link

HTTP400 on function getDealByContactId #6

Closed tilman closed 5 years ago

tilman commented 7 years ago

if i call the function getDealByContactId, the function respond with following error:

Status Code = 400
SyntaxError: Unexpected token < in JSON at position 0
    at Object.parse (native)
    at IncomingMessage.<anonymous> (/Users/Tilman/Documents/Programme/NodeJS/async_test/node_modules/agile_crm/agilecrm.js:477:48)
    at emitNone (events.js:91:20)
    at IncomingMessage.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:926:12)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)

Status code 400 and following body (got it with debuging features) idicate, the API is calling the wrong api endpoint.

<html><head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>400 Unable to extract parameter from http request: javax.ws.rs.PathParam("contact-id") value is '5137069722566656deals' for public com.agilecrm.contact.Contact com.agilecrm.core.api.contacts.ContactsAPI.getContact(java.lang.Long) throws com.agilecrm.user.access.exception.AccessDeniedException</title>
</head>
<body text=#000000 bgcolor=#ffffff>
<h1>Error: Unable to extract parameter from http request: javax.ws.rs.PathParam("contact-id") value is '5137069722566656deals' for public com.agilecrm.contact.Contact com.agilecrm.core.api.contacts.ContactsAPI.getContact(java.lang.Long) throws com.agilecrm.user.access.exception.AccessDeniedException</h1>
</body></html>
rammohan-agile commented 5 years ago

hi @tilman please add try catch block to below i.e. while parsing the response

var opportunity = JSON.parse(body); success(opportunity);

this to

             try {
                       var opportunity = JSON.parse(body);
                        success(opportunity);
                    } catch (ex) {
                            return body;
                    }

This will resolve your problem, In case you need more information regarding Agile CRM REST API please check below main reference :

https://github.com/agilecrm/rest-api

Thanks, Agile crm support team.