EspoCRM and 3CX

Status
Not open for further replies.

mbrands

New Customer
Joined
Feb 11, 2021
Messages
7
Reaction score
0
Hi everyone,

i have tried the Template Generator to create integration with 3CX.
When uploaded and tested in 3CX i got the following error:

Code:
Started scenario with empty id
System.Exception: Unknown expression: 0. Part: 0.
   at TcxLexicalParser.ValueManager.GetByPath(String[] path)
   at TcxLexicalParser.LexEvaluator.ProcessInt(CodeElement codeElement, IValueManager valueManager)
   at TcxLexicalParser.LexEvaluator.Process(Element element, IValueManager valueManager, Boolean isFunctionArgument)
   at TcxLexicalParser.LexEvaluator.ProcessInt(ConcatElement concatElement, IValueManager valueManager, Boolean isFunctionArgument)
   at TcxLexicalParser.LexEvaluator.Process(Element element, IValueManager valueManager, Boolean isFunctionArgument)
   at TcxLexicalParser.ExpressionEvaluator.ParseExpression(String expression, Boolean asExpression, IValueManager customManager)
   at CrmIntegration.EscapedExpressionEvaluator.ParseExpression(String expression, Boolean asExpression, IValueManager customManager)
   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.GetContactInfoFromCrm(String contactNumber, String destinationEmail, Boolean createIfNotFound, CancellationToken token)

I suspect this error comes from the API url that i have to use to search by numer. It uses [x] brackets and thats probebly the 0 in the error that it encounters frst.
My XML is as following:

XML:
<?xml version="1.0"?>
<Crm xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Country="NL" Name="WRS" Version="1">
  <Number Prefix="Off" MaxLength="[MaxLength]" />
  <Connection MaxConcurrentRequests="2" />
  <Parameters>
    <Parameter Name="APIkey" Type="String" Parent="General Configuration" Editor="String" Title="API Key:" />
  </Parameters>
  <Authentication Type="Basic">
    <Value>[APIkey]:X</Value>
  </Authentication>
  <Scenarios>
    <Scenario Id="" Type="REST">
      <Request Url="https://domainhere.net/api/v1/Contact?where[0][type]=startsWith&amp;where[0][attribute]=phoneNumber&amp;where[0][value]=[Number]" MessagePasses="0" RequestEncoding="UrlEncoded" RequestType="Get" ResponseType="Json" />
      <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://domainhere.net/#Contact/view/[ContactID]" />
      </Outputs>
    </Scenario>
  </Scenarios>
</Crm>

Can anyone offer some insight?

Best regards.
 
Your URL contains [ ] which is considered as variables. That's why. You should probably encode them.
 
  • Like
Reactions: edossantos
As described here, you need to escape brackets:
  • The opening square bracket [ which needs to be replaced by {{.
  • The closing square bracket ] which needs to be replaced by }}.
  • The quotation mark " which needs to be replaced by ^^.
 
After some fiddling around i have it connecting with the CRM (as i can see from access logs) but i get:
Code:
Server returned a non successful status code - HTTPStatusCode=NotFound - Reaso=Not Found - Content=

If i open the link
Code:
https://domainhere.net/api/v1/Contact?where[0][type]=startsWith&where[0][field]=phoneNumber&where[0][value]=numberhere
i get a JSON result.

In my XML the Request Url is
Code:
<Request Url="https://domainhere.net/api/v1/Contact^^where{ {0} }{ {type} }=startsWith&amp;where{ {0} }{ {field} }=phoneNumber&amp;where{ {0} }{ {value} }=[Number]" MessagePasses="0" RequestEncoding="UrlEncoded" RequestType="Get" ResponseType="Json" />

Also the phonenumber in the "Test CRM integration" seems to be stripped down to the last 6 digits.

Question 1: What could be wrong with the request Url?
Question 2: Why is the number in the rerquest being stripped down to the last 6 digits?
 
Q1: check the URL called in the logs, try it directly in your browser?

Q2: Console-> Advanced -> Contacts -> Options -> "Match X number of digits".
 
Your request looks wrong. You have:
<Request Url="https://domainhere.net/api/v1/Contact^^where{ {0} }{ {type} }=startsWith&amp;where{ {0} }{ {field} }=phoneNumber&amp;where{ {0} }{ {value} }=[Number]" MessagePasses="0" RequestEncoding="UrlEncoded" RequestType="Get" ResponseType="Json" />

But it should be:
<Request Url="https://domainhere.net/api/v1/Contact?where{{0}}{{type}}=startsWith&amp;where{{0}}{{field}}=phoneNumber&amp;where{{0}}{{value}}=[Number]" MessagePasses="0" RequestEncoding="UrlEncoded" RequestType="Get" ResponseType="Json" />
 
Code:
https://domainhere.net/api/v1/Contact%22where%7B%20%7B0%7D%20%7D%7B%20%7Btype%7D%20%7D=startsWith&where%7B%20%7B0%7D%20%7D%7B%20%7Bfield%7D%20%7D=phoneNumber&where%7B%20%7B0%7D%20%7D%7B%20%7Bvalue%7D%20%7D=numberhere

It still seems to mess up the whole link.
 
Your request looks wrong. You have:
<Request Url="https://domainhere.net/api/v1/Contact^^where{ {0} }{ {type} }=startsWith&amp;where{ {0} }{ {field} }=phoneNumber&amp;where{ {0} }{ {value} }=[Number]" MessagePasses="0" RequestEncoding="UrlEncoded" RequestType="Get" ResponseType="Json" />

But it should be:
<Request Url="https://domainhere.net/api/v1/Contact?where{{0}}{{type}}=startsWith&amp;where{{0}}{{field}}=phoneNumber&amp;where{{0}}{{value}}=[Number]" MessagePasses="0" RequestEncoding="UrlEncoded" RequestType="Get" ResponseType="Json" />
? had to be replaced by ^^ acording to the link shared by @edossantos ?
 
  • Like
Reactions: Evolute IT
Also the spaces you added are breaking the sequence. You must not add a space between braces. It's "{{" and not "{ {".
 
  • Like
Reactions: Evolute IT
I didnt, I put in the URL in the generator without the spaces, but the XML it generated had the spaces added. So I presumed it was ok. Apologies if I misunderstood your instructions. I will test with the corrected URL.
 
I got the request working but unfortunatlyi run into the next problem. It doesnt have a hit even though the responds text shows the contact. crm.png
 
Looks like you're not properly specifying how to identify each record. Your rule is defined as:
XML:
<Rule Type="Any">id</Rule>

But according to the response, it looks like you should use:
XML:
<Rule Type="Any">list.id</Rule>
 
  • Like
Reactions: mbrands
Thank you so much for your insight @edossantos .
Should i also add that in front of all my variables aswell? Or is this already controlled by the rule type variable?

example:
XML:
      <Variables>
        <Variable Name="ContactID" Path="list.id">
          <Filter />
        </Variable>
        <Variable Name="FirstName" Path="list.firstName">
          <Filter />
        </Variable>
        <Variable Name="LastName" Path="list.lastName">
          <Filter />
        </Variable>
        <Variable Name="CompanyName" Path="list.accountName">
          <Filter />
        </Variable>
        <Variable Name="Email" Path="list.emailAddress">
          <Filter />
        </Variable>
        <Variable Name="PhoneBusiness" Path="list.phoneNumber">
          <Filter />
        </Variable>
      </Variables>
 
Thank you so much for your insight @edossantos .
Should i also add that in front of all my variables aswell? Or is this already controlled by the rule type variable?

example:
XML:
      <Variables>
        <Variable Name="ContactID" Path="list.id">
          <Filter />
        </Variable>
        <Variable Name="FirstName" Path="list.firstName">
          <Filter />
        </Variable>
        <Variable Name="LastName" Path="list.lastName">
          <Filter />
        </Variable>
        <Variable Name="CompanyName" Path="list.accountName">
          <Filter />
        </Variable>
        <Variable Name="Email" Path="list.emailAddress">
          <Filter />
        </Variable>
        <Variable Name="PhoneBusiness" Path="list.phoneNumber">
          <Filter />
        </Variable>
      </Variables>
Yes, you need to correct all the mappings.
 
Status
Not open for further replies.

Latest Posts

Forum statistics

Threads
112,324
Messages
591,897
Members
165,475
Latest member
lastshadow