Contact.id not reported back in CDR

Status
Not open for further replies.

drenda

Forum User
Joined
May 3, 2020
Messages
30
Reaction score
10
Hi, I created some time ago a custom CRM template using 3CX template generator.
Here is the code:

Code:
<?xml version="1.0"?>
<Crm Country="IT" Name="Test" Version="1">
    <Number Prefix="AsIs" MaxLength="[MaxLength]"/>
    <Connection MaxConcurrentRequests="10"/>
    <Parameters>
        <Parameter Name="ReportCallEnabled" Type="Boolean" Editor="String" Title="Enable Call Journaling" Default="True"/>
        <Parameter Name="ApiKey" Type="String" Parent="General Configuration" Editor="String" Title="ApiKey" Default="{Token}"/>
        <Parameter Name="TestClient" Type="String" Parent="General Configuration" Editor="String" Title="Test client URL" Default="{TestClient}"/>
        <Parameter Name="TestServer" Type="String" Parent="General Configuration" Editor="String" Title="Test server url" Default="{TestServer}"/>
    </Parameters>
    <Authentication Type="No"/>
    <Scenarios>
        <Scenario Id="" Type="REST">
            <Request Url="[TestServer]/api/v1/integrations/3cx/contacts?phoneNumber=[Number]" MessagePasses="0" RequestEncoding="UrlEncoded"
                     RequestType="Get" ResponseType="Json">
                <Headers>
                    <Value Key="Authorization" Passes="0" Type="String">Bearer [APIkey]</Value>
                </Headers>
            </Request>
            <Rules>
                <Rule Type="Any">contact.id</Rule>
            </Rules>
            <Variables>
                <Variable Name="ContactID" Path="contact.id">
                    <Filter/>
                </Variable>
                <Variable Name="FirstName" Path="contact.firstName">
                    <Filter/>
                </Variable>
                <Variable Name="LastName" Path="contact.lastName">
                    <Filter/>
                </Variable>
                <Variable Name="CompanyName" Path="contact.companyName">
                    <Filter/>
                </Variable>
                <Variable Name="Email" Path="contact.email">
                    <Filter/>
                </Variable>
                <Variable Name="PhoneBusiness" Path="contact.landlinePhone">
                    <Filter/>
                </Variable>
                <Variable Name="PhoneMobile" Path="contact.mobilePhone">
                    <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="PhoneMobile" Passes="0" Value="[PhoneMobile]"/>
                <Output Type="ContactUrl" Passes="0" Value="[TestClient]/contacts/[ContactID]/dashboard"/>
            </Outputs>
        </Scenario>
        <Scenario Id="ReportCall" Type="REST">
            <Request SkipIf="[ReportCallEnabled]!=True" Url="[TestServer]/api/v1/integrations/3cx/cdr" MessagePasses="0"
                     RequestContentType="application/json" RequestEncoding="Json" RequestType="Post" ResponseType="Json">
                <Headers>
                    <Value Key="Authorization" Passes="0" Type="String">Bearer [APIkey]</Value>
                </Headers>
                <PostValues Key="">
                    <Value Key="from" Passes="1" Type="String">[Number]</Value>
                    <Value Key="to" Passes="1" Type="String">[Agent]</Value>
                    <Value Key="type" Passes="1" Type="String">[CallType]</Value>
                    <Value Key="startDate" Passes="1" Type="String">[[CallStartTimeUTC].ToString("yyyy-MM-dd")]T[[CallStartTimeUTC].ToString("HH:mm:ss")]Z</Value>
                    <Value Key="endDate" Passes="1" Type="String">[[CallEndTimeUTC].ToString("yyyy-MM-dd")]T[[CallEndTimeUTC].ToString("HH:mm:ss")]Z</Value>
                    <Value Key="contactId" Passes="1" Type="String">[Contact::ContactID]</Value>
                </PostValues>
            </Request>
        </Scenario>
    </Scenarios>
</Crm>

We get the http call with all details but contactId value. In the 3CX panel, inside CDR I see the name of the caller so I'm sure the contact is recognized as a CRM contact.
I'm using 3CX v18; is there a different syntax?

Thanks very much
 
In v18, the request flow has changed and the Contact:: variables are no longer available during ReportCall.

You need to return EntityId and EntityType which can then be used in ReportCall to get the ID and type of contact (when a CRM has leads, orgs and contacts, for example.) Those are stored in the phonebook entry alongside the other outputs of the Lookup scenario.

This is expected to probably change again in the next update as big changes to the integration are coming.

You can refer to the docs or simply look at any other supported CRM templates to see how it is being used.
 
Thanks for your quick reply. I changed the file in this way:

XML:
<?xml version="1.0"?>
<Crm Country="IT" Name="Test" Version="1">
    <Number Prefix="AsIs" MaxLength="[MaxLength]"/>
    <Connection MaxConcurrentRequests="10"/>
    <Parameters>
        <Parameter Name="ReportCallEnabled" Type="Boolean" Editor="String" Title="Enable Call Journaling" Default="True"/>
        <Parameter Name="ApiKey" Type="String" Parent="General Configuration" Editor="String" Title="ApiKey" Default="{Token}"/>
        <Parameter Name="TestClient" Type="String" Parent="General Configuration" Editor="String" Title="Test client URL" Default="{TestClient}"/>
        <Parameter Name="TestServer" Type="String" Parent="General Configuration" Editor="String" Title="Test server url" Default="{TestServer}"/>
    </Parameters>
    <Authentication Type="No"/>
    <Scenarios>
        <Scenario Id="" Type="REST">
            <Request Url="[TestServer]/api/v1/integrations/3cx/contacts?phoneNumber=[Number]" MessagePasses="0" RequestEncoding="UrlEncoded"
                     RequestType="Get" ResponseType="Json">
                <Headers>
                    <Value Key="Authorization" Passes="0" Type="String">Bearer [APIkey]</Value>
                </Headers>
            </Request>
            <Rules>
                <Rule Type="Any">contact.id</Rule>
            </Rules>
            <Variables>
                <Variable Name="ContactID" Path="contact.id">
                    <Filter/>
                </Variable>
                <Variable Name="FirstName" Path="contact.firstName">
                    <Filter/>
                </Variable>
                <Variable Name="LastName" Path="contact.lastName">
                    <Filter/>
                </Variable>
                <Variable Name="CompanyName" Path="contact.companyName">
                    <Filter/>
                </Variable>
                <Variable Name="Email" Path="contact.email">
                    <Filter/>
                </Variable>
                <Variable Name="PhoneBusiness" Path="contact.landlinePhone">
                    <Filter/>
                </Variable>
                <Variable Name="PhoneMobile" Path="contact.mobilePhone">
                    <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="PhoneMobile" Passes="0" Value="[PhoneMobile]"/>
                <Output Type="ContactUrl" Passes="0" Value="[TestClient]/contacts/[ContactID]/dashboard"/>
            </Outputs>
        </Scenario>
        <Scenario Id="ReportCall" Type="REST">
            <Request SkipIf="[ReportCallEnabled]!=True" Url="[TestServer]/api/v1/integrations/3cx/cdr" MessagePasses="0"
                     RequestContentType="application/json" RequestEncoding="Json" RequestType="Post" ResponseType="Json">
                <Headers>
                    <Value Key="Authorization" Passes="0" Type="String">Bearer [APIkey]</Value>
                </Headers>
                <PostValues Key="">
                    <Value Key="from" Passes="1" Type="String">[Number]</Value>
                    <Value Key="to" Passes="1" Type="String">[Agent]</Value>
                    <Value Key="type" Passes="1" Type="String">[CallType]</Value>
                    <Value Key="startDate" Passes="1" Type="String">[[CallStartTimeUTC].ToString("yyyy-MM-dd")]T[[CallStartTimeUTC].ToString("HH:mm:ss")]Z</Value>
                    <Value Key="endDate" Passes="1" Type="String">[[CallEndTimeUTC].ToString("yyyy-MM-dd")]T[[CallEndTimeUTC].ToString("HH:mm:ss")]Z</Value>
                    <Value Key="contactId" Passes="1" Type="String">[EntityId]</Value>
                </PostValues>
            </Request>
        </Scenario>
    </Scenarios>
</Crm>

But I still don't receive the contactId value (it's null) even if I'm sure when the CRM contact was created the id was set (in fact the contact url is opened when the call is arriving).
Could you link a complete xml example so I can investigate further to see if I'm doing something wrong?

Thanks
 
You need to set the EntityId and EntityType in the Output of the lookup scenario. Right now it would be empty as it's still ContactId that's returned.
 
Thanks for the reply,
do I need to set the EntityType even if I don't need it in the CRM?
I did these changes but still I don't receive the Id:

XML:
<?xml version="1.0"?>
<Crm Country="IT" Name="Test" Version="1">
    <Number Prefix="AsIs" MaxLength="[MaxLength]"/>
    <Connection MaxConcurrentRequests="10"/>
    <Parameters>
        <Parameter Name="ReportCallEnabled" Type="Boolean" Editor="String" Title="Enable Call Journaling" Default="True"/>
        <Parameter Name="ApiKey" Type="String" Parent="General Configuration" Editor="String" Title="ApiKey" Default="{Token}"/>
        <Parameter Name="TestClient" Type="String" Parent="General Configuration" Editor="String" Title="Test client URL" Default="{TestClient}"/>
        <Parameter Name="TestServer" Type="String" Parent="General Configuration" Editor="String" Title="Test server url" Default="{TestServer}"/>
    </Parameters>
    <Authentication Type="No"/>
    <Scenarios>
        <Scenario Id="" Type="REST">
            <Request Url="[TestServer]/api/v1/integrations/3cx/contacts?phoneNumber=[Number]" MessagePasses="0" RequestEncoding="UrlEncoded"
                     RequestType="Get" ResponseType="Json">
                <Headers>
                    <Value Key="Authorization" Passes="0" Type="String">Bearer [APIkey]</Value>
                </Headers>
            </Request>
            <Rules>
                <Rule Type="Any">contact.id</Rule>
            </Rules>
            <Variables>
                <Variable Name="ContactID" Path="contact.id">
                    <Filter/>
                </Variable>
                <Variable Name="FirstName" Path="contact.firstName">
                    <Filter/>
                </Variable>
                <Variable Name="LastName" Path="contact.lastName">
                    <Filter/>
                </Variable>
                <Variable Name="CompanyName" Path="contact.companyName">
                    <Filter/>
                </Variable>
                <Variable Name="Email" Path="contact.email">
                    <Filter/>
                </Variable>
                <Variable Name="PhoneBusiness" Path="contact.landlinePhone">
                    <Filter/>
                </Variable>
                <Variable Name="PhoneMobile" Path="contact.mobilePhone">
                    <Filter/>
                </Variable>
            </Variables>
            <Outputs AllowEmpty="false">
                <Output Type="ContactID" Passes="0" Value="[EntityId]"/>
                <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="PhoneMobile" Passes="0" Value="[PhoneMobile]"/>
                <Output Type="ContactUrl" Passes="0" Value="[TestClient]/contacts/[ContactID]/dashboard"/>
            </Outputs>
        </Scenario>
        <Scenario Id="ReportCall" Type="REST">
            <Request SkipIf="[ReportCallEnabled]!=True" Url="[TestServer]/api/v1/integrations/3cx/cdr" MessagePasses="0"
                     RequestContentType="application/json" RequestEncoding="Json" RequestType="Post" ResponseType="Json">
                <Headers>
                    <Value Key="Authorization" Passes="0" Type="String">Bearer [APIkey]</Value>
                </Headers>
                <PostValues Key="">
                    <Value Key="from" Passes="1" Type="String">[Number]</Value>
                    <Value Key="to" Passes="1" Type="String">[Agent]</Value>
                    <Value Key="type" Passes="1" Type="String">[CallType]</Value>
                    <Value Key="startDate" Passes="1" Type="String">[[CallStartTimeUTC].ToString("yyyy-MM-dd")]T[[CallStartTimeUTC].ToString("HH:mm:ss")]Z</Value>
                    <Value Key="endDate" Passes="1" Type="String">[[CallEndTimeUTC].ToString("yyyy-MM-dd")]T[[CallEndTimeUTC].ToString("HH:mm:ss")]Z</Value>
                    <Value Key="contactId" Passes="1" Type="String">[EntityId]</Value>
                </PostValues>
            </Request>
        </Scenario>
    </Scenarios>
</Crm>

Could you link a complete working example so I can study it?

Thanks
 
Status
Not open for further replies.

Latest Posts

Forum statistics

Threads
112,323
Messages
591,896
Members
165,473
Latest member
NathanMitchell