EspoCRM and 3CX

Status
Not open for further replies.

vladimir.d

New User
Joined
Oct 20, 2021
Messages
8
Reaction score
0
Hi,

Could you please explain what's wrong with Create Contact Record request?

We get the following error on Test:

XML:
Request text: https://crm.espocrm.com/api/v1/Contact
Request message: {"phoneNumber":"12345678","firstName":"New","lastName":"3CX Contact 12345678"}
System.Exception: Server returned a non successful status code - HTTPStatusCode=BadRequest - Reason=Bad Request - Content=
   at CrmIntegration.ScenarioProcessorBase.ProcessRequest(ScenarioRequest request, IValueManager customManager, HttpClient client, CancellationToken token)
   at CrmIntegration.ScenarioProcessorBase.ProcessScenario(ProtocolScenario scenario, IValueManager customManager, CancellationToken token)
   at CrmIntegration.ScenarioProcessorBase.Execute(ProtocolScenario scenario, CancellationToken token)
   at CrmIntegration.CrmProcessor.CreateContactRecord(IValueManager customManager, String scenarioId, Func`2 filterResultsFunctor, CancellationToken token)

Template:

XML:
   <Scenario Id="CreateContactRecord" Type="REST">
      <Request SkipIf="[CreateContactEnabled]!=True||[IIf([CreateOnCallDirection]==Inbound,[CallDirection]!=Inbound,False)]==True" Url="https://crm.espocrm.com/api/v1/Contact" MessagePasses="0" RequestContentType="application/json" RequestEncoding="Json" RequestType="Post" ResponseType="Json">
        <PostValues Key="">
          <Value Key="phoneNumber" Passes="1" Type="String">[Number]</Value>
          <Value Key="firstName" Passes="2" Type="String">[CreateContactFirstName]</Value>
          <Value Key="lastName" Passes="2" Type="String">[CreateContactLastName]</Value>
        </PostValues>
      </Request>
      <Rules>
        <Rule Type="Any">id</Rule>
      </Rules>
      <Variables>
        <Variable Name="ContactID" Path="id">
          <Filter />
        </Variable>
        <Variable Name="FirstName" Path="firstName">
          <Filter />
        </Variable>
        <Variable Name="LastName" Path="lastName">
          <Filter />
        </Variable>
        <Variable Name="CompanyName" Path="accountName">
          <Filter />
        </Variable>
        <Variable Name="Email" Path="emailAddress">
          <Filter />
        </Variable>
        <Variable Name="PhoneBusiness" Path="phoneNumber">
          <Filter />
        </Variable>
      </Variables>

      <Outputs AllowEmpty="false">
        <Output Type="ContactID" Passes="0" Value="[ContactID]" />
        <Output Type="FirstName" Passes="0" Value="[FirstName]" />
        <Output Type="LastName" Passes="0" Value="[LastName]" />
        <Output Type="CompanyName" Passes="0" Value="[CompanyName]" />
        <Output Type="Email" Passes="0" Value="[Email]" />
        <Output Type="PhoneBusiness" Passes="0" Value="[PhoneBusiness]" />
        <Output Type="ContactUrl" Passes="0" Value="https://crm.espocrm.com/#Contact/view/[ContactID]" />
        <Output Type="EntityId" Passes="0" Value="[ContactID]" />
        <Output Type="EntityType" Passes="0" Value="Contacts" />
      </Outputs>
    </Scenario>

When we do a POST request in Postman sending {"phoneNumber":"12345678","firstName":"New","lastName":"3CX Contact 12345678"} as JSON to https://crm.espocrm.com/api/v1/Contact, the CRM successfully creates a new account.
 
Just made a test with CURL.

Curl POST request:
Code:
$ curl --user 3CXUSER:PASSWORD -X POST https://crm.espocrm.com/api/v1/Contact 
          -H 'Content-Type: application/json' 
          -d '{"phoneNumber":"12345678","firstName":"New","lastName":"3CX Contact 12345678"}'


CRM response:
Code:
{"id":"AXAXAXAXAX","name":"New 3CX Contact
 12345678","deleted":false,"salutationName":"","firstName":"New","lastName":"3CX Contact
12345678","phoneNumber":"12345678","doNotCall":false,"accountIsInactive":false,"opportunityRole":"",
"createdAt":"2021-10-21 14:20:02","modifiedAt":"2021-10-21 14:20:02",
"hasPortalUser":false,"targetListIsOptedOut":false,"propertyRole":"","keyContact":false,
"privacyConsent":"","block":false,"emailAddressIsOptedOut":false,"phoneNumberIsOptedOut":false,
"emailAddressData":[],"phoneNumberData":[{"phoneNumber":"12345678","type":"Mobile","primary":true,"optOut":false,"invalid":false}],
"accountsIds":[],"accountsNames":{},"accountsColumns":{},"createdById":"ASDFASDFF",
"createdByName":"3CX Service","teamsIds":[],"teamsNames":{},"technologiesIds":[],
"technologiesNames":{},"testimonialsIds":[],"testimonialsNames":{},
"documentsPhotoIDIds":[],"documentsPhotoIDNames":{},
"documentsProofOfAddressIds":[],"documentsProofOfAddressNames":{},
"documentCertificationsIds":[],"documentCertificationsNames":{},
"bankAccountsSignatoryIds":[],"bankAccountsSignatoryNames":{},
"chairpersonForIds":[],"chairpersonForNames":{},"directorForIds":[],
"directorForNames":{},"committeesIds":[],"committeesNames":{},
"companiesIds":[],"companiesNames":{},"controllerRegistrationsIds":[],
"controllerRegistrationsNames":{},"lettersToIds":[],"lettersToNames":{},
"contactReviewsIds":[],"contactReviewsNames":{},"lettersCopiedToIds":[],
"lettersCopiedToNames":{},"referencesIds":[],"referencesNames":{},
"referenceContactsIds":[],"referenceContactsNames":{},"isFollowed":false,
"followersIds":[],"followersNames":{},"documentsPhotoIDTypes":{},
"documentsProofOfAddressTypes":{},"referencesTypes":{}}

So it's certainly a problem with the request sent by 3CX.
 
Last edited:
Are you including the basic authentication headers in 3CX? You should get a different error if that's what's missing, but sometimes the server returns an error that doesn't really match what's really happening, so I would check that...
 
The Authentication section is specified in the template.

XML:
 <Authentication Type="Basic">
    <Value>[UserName]:[Password]</Value>
  </Authentication>

The Lookup by Phone request also uses Basic Authentication and it works well.
I hope the basic authentication header is also passed in the CreateContactRecord request.

I've attached the template for review.
 

Attachments

Thanks for sending the template.

First, please note that the scenario used to do the contact lookup by phone number should have an empty Id. You have this:
<Scenario Id="LookupByPhone" Type="REST">

But you should have:
<Scenario Id="" Type="REST">

The Authorization header is included in every request.

Can you make a Wireshark capture of the request made with Postman and from 3CX so we can compare them?
 
  • Like
Reactions: Evolute IT
OK, fixed the Scenario ID for the contact lookup, thank you.

I suspect 3CX sends some another content type instead of 'application/json'.
Will send a Wireshark capture in PM shortly.
 
Thanks for sending the capture. Unfortunately the connection is established over SSL, so we can't see anything.

Is it possible for you to share with me a user name and password to test this? If you can generate a temporary user, please send me the details in a private message, and I'll try to make some tests.
 
I've sent a temporary user details in PM.
 
After some research I found that 3CX passes 'Content-Type: application/json; charset=utf-8' header.
Curl and Postman sends 'Content-Type: application/json' header.

Is there a way to override the 'Content-type' header in 3CX?

As a workaround we have patched EspoCRM software to make 'Content-Type: application/json; charset=utf-8' headers working. It isn't a safe-upgrade solution and needs to be re-applied after EspoCRM upgrade.

Related thread on EspoCRM forum:
https://forum.espocrm.com/forum/bug-reports/76034-bad-request-on-post-to-api
 
Last edited:
Well, that header is valid, so this should be reported to EspoCRM so they make a proper fix for this...
 
  • Like
Reactions: Evolute IT
Are "Call Journaling" scenarios triggered as well for Internal calls between internal user extensions (two extensions /conference call)?
 
@edossantos Is it possible to have Call ID and Call Record URL posted in "Call Journaling" scenarios?
Or is there another way to obtain it?
 
Last edited:
Are "Call Journaling" scenarios triggered as well for Internal calls between internal user extensions (two extensions /conference call)?
No, only for calls from/to an external number.

@edossantos Is it possible to have Call ID and Call Record URL posted in "Call Journaling" scenarios?
Or is there another way to obtain it?
Unfortunately this is not available at the moment. But please check this as a possible workaround for the call recording URL:
https://www.3cx.com/community/threa...ble-in-crm-integration-xml.67599/#post-293258
 
Status
Not open for further replies.

Latest Posts

Forum statistics

Threads
112,323
Messages
591,896
Members
165,474
Latest member
costionofrei