Missing EntityID in POST variable - V18

Status
Not open for further replies.

AdamTR

Free User
Joined
Mar 24, 2022
Messages
16
Reaction score
1
Hi All,

I'm having issues with seeing certain variables in the POST to our API since upgrading to V18.

I am aware that V18 does not support [Contact: XXXXXX] variables anymore, and therefore we need to use EntityID. So I've updated the XML to use EntityID instead, in both the Variables and outputs, however in the POST sent to our API the EntityID variable is just an empty string. Is there something I'm missing in order for this to pull through?


XML:
<Variables>
        <Variable Name="EntityId" Path="customer.Details.ID">
          <Filter />
        </Variable>
        <Variable Name="FirstName" Path="customer.Details.Name">
          <Filter />
        </Variable>
        <Variable Name="LastName" Path="customer.Details.Surname">
          <Filter />
        </Variable>
        <Variable Name="Email" Path="customer.Details.Email">
          <Filter />
        </Variable>
        <Variable Name="PhoneMobile" Path="customer.Telephone">
          <Filter />
        </Variable>

XML:
 <Outputs AllowEmpty="false">
        <Output Type="FirstName" Passes="0" Value="[FirstName]" />
        <Output Type="LastName" Passes="0" Value="[LastName]" />
        <Output Type="Email" Passes="0" Value="[Email]" />
        <Output Type="PhoneMobile" Passes="0" Value="[PhoneMobile]" />
        <Output Type="ContactUrl" Passes="0" Value="https://xxxxxx.co.uk/crm/customer/[EntityId]" />
        <Output Type="EntityId" Passes="0" Value="[EntityId]" />
      </Outputs>


XML:
<Outputs AllowEmpty="false">
        <Output Type="EntityId" Passes="0" Value="[EntityId]" />
        <Output Type="FirstName" Passes="0" Value="[FirstName]" />
        <Output Type="LastName" Passes="0" Value="[LastName]" />
        <Output Type="Email" Passes="0" Value="[Email]" />
        <Output Type="PhoneMobile" Passes="0" Value="[PhoneMobile]" />
        <Output Type="ContactUrl" Passes="0" Value="https://xxxxxx.co.uk/crm/customer/[EntityId]" />
      </Outputs>
    </Scenario>
    <Scenario Id="ReportCall" Type="REST">
      <Request SkipIf="[ReportCallEnabled]!=True||[CallType]!=Inbound" Url="https://xxxxxx.co.uk/api/events/new-event/?type=5" MessagePasses="0" RequestContentType="application/json" RequestEncoding="Json" RequestType="Post" ResponseType="Json">
        <PostValues Key="">
          <Value Key="duration" Passes="1" Type="String">[Duration]</Value>
          <Value Key="phone" Passes="1" Type="String">[Number]</Value>
          <Value Key="agent" Passes="1" Type="String">[Agent]</Value>
          <Value Key="callType" Passes="1" Type="String">[CallType]</Value>
          <Value Key="DateTime" Passes="1" Type="String">[DateTime]</Value>
          <Value Key="CustomerID" Passes="1" Type="String">[EntityId]</Value>
          <Value Key="EntityId" Passes="1" Type="String">[EntityId]</Value>
          <Value Key="CallStart" Passes="1" Type="String">[CallStartTimeUTC]</Value>
          <Value Key="CallEnd" Passes="1" Type="String">[CallEndTimeUTC]</Value>
        </PostValues>
      </Request>




However, when I use the Test CRM Integration functionality the EntityID field is populated with the customerID that I'm hoping to receive in our API. So i'm not sure what I'm missing for the POST to populate it in the same way.

JSON:
{"duration":"06:24","phone":"***********","agent":"1217","callType":"Inbound","DateTime":"24/03/2022 09:39","CustomerID":"","EntityId":"","CallStart":"24/03/2022 09:39:56","CallEnd":"24/03/2022 09:46:21"}


Any help would be greatly appreciated :)
 
I think you need to return the EntityType as well since those two are in the same field.

Also, in v18, the ReportCall can be executed even without an EntityId. Therefore, it's a good idea to add that to the SkipIf of the ReportCall. Checkout the built-in templates to see how they do.
 
  • Like
Reactions: edossantos
Thanks for the quick response.

After adding the EntityType, I still don't see the EntityID in the POST to our API, it's still just an empty string despite me seeing it in the Test when using the Test functionality in the CRM Provider Configuration panel.
Example:

JSON:
{
    "UnparsedOutputs": {
      "FirstName": "Harold",
      "LastName": "Gunderson",
      "Email": "xxxxxx",
      "PhoneMobile": "*******",
      "ContactUrl": "https://xxxxx.co.uk/crm/customer/",
      "EntityId": "126570",
      "EntityType": "Contacts"
    }

However the JSON from the POST sent to our API still shows the same empty strings (customerID & entityID).


I'm sure I'm missing something but can't figure out what? Full XML below:

XML:
<?xml version="1.0"?>
<Crm xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Country="US" Name="TestTemplate" Version="1" SupportsEmojis="false">
  <Number Prefix="Zeros" MaxLength="[MaxLength]" />
  <Connection MaxConcurrentRequests="2" />
  <Parameters>
    <Parameter Name="APIkey" Type="String" Parent="General Configuration" Editor="String" Title="API Key:" />
    <Parameter Name="CreateContactEnabled" Type="Boolean" Editor="String" Title="Enable Contact Creation" Default="False" />
    <Parameter Name="CreateContactFirstName" Type="String" Parent="CreateContactEnabled" Editor="String" Title="New Contact First Name:" Default="New" />
    <Parameter Name="CreateContactLastName" Type="String" Parent="CreateContactEnabled" Editor="String" Title="New Contact Last Name:" Default="3CX Contact [Number]" />
    <Parameter Name="ReportCallEnabled" Type="Boolean" Editor="String" Title="Enable Call Journaling" Default="False" />
    <Parameter Name="Subject" Type="String" Parent="ReportCallEnabled" Editor="String" Title="Call Subject:" Default="3CX PhoneSystem Call" />
    <Parameter Name="InboundCallText" Type="String" Parent="ReportCallEnabled" Editor="String" Title="Answered Inbound Call:" Default="[DateTime]: Answered incoming call from [Number] to [Agent] ([Duration])" />
    <Parameter Name="MissedCallText" Type="String" Parent="ReportCallEnabled" Editor="String" Title="Missed Call:" Default="[DateTime]: Missed call from [Number] to [Agent]" />
    <Parameter Name="OutboundCallText" Type="String" Parent="ReportCallEnabled" Editor="String" Title="Answered Outbound Call:" Default="[DateTime]: Answered outgoing call from [Agent] to [Number] ([Duration])" />
    <Parameter Name="NotAnsweredOutboundCallText" Type="String" Parent="ReportCallEnabled" Editor="String" Title="Unanswered Outbound Call:" Default="[DateTime]: Unanswered outgoing call from [Agent] to [Number]" />
  </Parameters>
  <Authentication Type="Basic">
    <Value>[APIkey]:X</Value>
  </Authentication>
  <Scenarios>
    <Scenario Id="" Type="REST">
      <Request Url="https://xxxxxx.co.uk/api/phone/search/?number=[Number]" MessagePasses="0" RequestEncoding="UrlEncoded" RequestType="Get" ResponseType="Json" />
      <Rules>
        <Rule Type="Any">customer.CustomerID</Rule>
      </Rules>
      <Variables>
        <Variable Name="CustomerID" Path="customer.Details.ID">
          <Filter />
        </Variable>
        <Variable Name="FirstName" Path="customer.Details.Name">
          <Filter />
        </Variable>
        <Variable Name="LastName" Path="customer.Details.Surname">
          <Filter />
        </Variable>
        <Variable Name="Email" Path="customer.Details.Email">
          <Filter />
        </Variable>
        <Variable Name="PhoneMobile" Path="customer.Telephone">
          <Filter />
        </Variable>
      </Variables>
      <Outputs AllowEmpty="false">
        <Output Type="FirstName" Passes="0" Value="[FirstName]" />
        <Output Type="LastName" Passes="0" Value="[LastName]" />
        <Output Type="Email" Passes="0" Value="[Email]" />
        <Output Type="PhoneMobile" Passes="0" Value="[PhoneMobile]" />
        <Output Type="ContactUrl" Passes="0" Value="https://xxxxxx.co.uk/crm/customer/[EntityId]" />
        <Output Type="EntityId" Passes="0" Value="[CustomerID]" />
        <Output Type="EntityType" Passes="0" Value="Contacts" />
      </Outputs>
    </Scenario>
    <Scenario Id="CreateContactRecord" Type="REST">
      <Request SkipIf="[CreateContactEnabled]!=True" Url="https://xxxxxx.co.uk/api/events/new-event/?type=4" MessagePasses="0" RequestContentType="application/json" RequestEncoding="Json" RequestType="Post" ResponseType="Json">
        <PostValues Key="">
          <Value Key="firstname" Passes="1" Type="String">Customer</Value>
          <Value Key="phone" Passes="1" Type="String">[Number]</Value>
        </PostValues>
      </Request>
      <Rules>
        <Rule Type="Any">customer.CustomerID</Rule>
      </Rules>
      <Variables>
        <Variable Name="FirstName" Path="customer.Details.Name">
          <Filter />
        </Variable>
        <Variable Name="LastName" Path="customer.Details.Surname">
          <Filter />
        </Variable>
        <Variable Name="Email" Path="customer.Details.Email">
          <Filter />
        </Variable>
        <Variable Name="PhoneMobile" Path="customer.Telephone">
          <Filter />
        </Variable>
      </Variables>
      <Outputs AllowEmpty="false">
        <Output Type="FirstName" Passes="0" Value="[FirstName]" />
        <Output Type="LastName" Passes="0" Value="[LastName]" />
        <Output Type="Email" Passes="0" Value="[Email]" />
        <Output Type="PhoneMobile" Passes="0" Value="[PhoneMobile]" />
        <Output Type="ContactUrl" Passes="0" Value="https://xxxxxx.co.uk/crm/customer/[EntityId]" />
      </Outputs>
    </Scenario>
    <Scenario Id="ReportCall" Type="REST">
      <Request SkipIf="[ReportCallEnabled]!=True||[CallType]!=Inbound" Url="https://xxxxxx.co.uk/api/events/new-event/?type=5" MessagePasses="0" RequestContentType="application/json" RequestEncoding="Json" RequestType="Post" ResponseType="Json">
        <PostValues Key="">
          <Value Key="duration" Passes="1" Type="String">[Duration]</Value>
          <Value Key="phone" Passes="1" Type="String">[Number]</Value>
          <Value Key="agent" Passes="1" Type="String">[Agent]</Value>
          <Value Key="callType" Passes="1" Type="String">[CallType]</Value>
          <Value Key="DateTime" Passes="1" Type="String">[DateTime]</Value>
          <Value Key="CustomerID" Passes="1" Type="String">[EntityId]</Value>
          <Value Key="CallStart" Passes="1" Type="String">[CallStartTimeUTC]</Value>
          <Value Key="CallEnd" Passes="1" Type="String">[CallEndTimeUTC]</Value>
        </PostValues>
      </Request>
      <Variables />
      <Outputs Next="ReportCallMissed" AllowEmpty="true" />
    </Scenario>
    <Scenario Id="ReportCallMissed" Type="REST">
      <Request SkipIf="[ReportCallEnabled]!=True||[CallType]!=Missed" Url="https://xxxxxx.co.uk/api/events/new-event/?type=5" MessagePasses="0" RequestContentType="application/json" RequestEncoding="Json" RequestType="Post" ResponseType="Json">
        <PostValues Key="">
          <Value Key="duration" Passes="1" Type="String">[Duration]</Value>
          <Value Key="phone" Passes="1" Type="String">[Number]</Value>
          <Value Key="agent" Passes="1" Type="String">[Agent]</Value>
          <Value Key="callType" Passes="1" Type="String">[CallType]</Value>
          <Value Key="DateTime" Passes="1" Type="String">[DateTime]</Value>
          <Value Key="CustomerID" Passes="1" Type="String">[EntityId]</Value>
          <Value Key="CallStart" Passes="1" Type="String">[CallStartTimeUTC]</Value>
          <Value Key="CallEnd" Passes="1" Type="String">[CallEndTimeUTC]</Value>
        </PostValues>
      </Request>
      <Variables />
      <Outputs Next="ReportCallOutbound" AllowEmpty="true" />
    </Scenario>
    <Scenario Id="ReportCallOutbound" Type="REST">
      <Request SkipIf="[ReportCallEnabled]!=True||[CallType]!=Outbound" Url="https://xxxxxx.co.uk/api/events/new-event/?type=5" MessagePasses="0" RequestContentType="application/json" RequestEncoding="Json" RequestType="Post" ResponseType="Json">
        <PostValues Key="">
          <Value Key="duration" Passes="1" Type="String">[Duration]</Value>
          <Value Key="phone" Passes="1" Type="String">[Number]</Value>
          <Value Key="agent" Passes="1" Type="String">[Agent]</Value>
          <Value Key="callType" Passes="1" Type="String">[CallType]</Value>
          <Value Key="DateTime" Passes="1" Type="String">[DateTime]</Value>
          <Value Key="CustomerID" Passes="1" Type="String">[EntityId]</Value>
          <Value Key="CallStart" Passes="1" Type="String">[CallStartTimeUTC]</Value>
          <Value Key="CallEnd" Passes="1" Type="String">[CallEndTimeUTC]</Value>
        </PostValues>
      </Request>
      <Variables />
      <Outputs Next="ReportCallNotanswered" AllowEmpty="true" />
    </Scenario>
    <Scenario Id="ReportCallNotanswered" Type="REST">
      <Request SkipIf="[ReportCallEnabled]!=True||[CallType]!=Notanswered" Url="https://xxxxxx/api/events/new-event/?type=5" MessagePasses="0" RequestContentType="application/json" RequestEncoding="Json" RequestType="Post" ResponseType="Json">
        <PostValues Key="">
          <Value Key="duration" Passes="1" Type="String">[Duration]</Value>
          <Value Key="phone" Passes="1" Type="String">[Number]</Value>
          <Value Key="agent" Passes="1" Type="String">[Agent]</Value>
          <Value Key="callType" Passes="1" Type="String">[CallType]</Value>
          <Value Key="DateTime" Passes="1" Type="String">[DateTime]</Value>
          <Value Key="CustomerID" Passes="1" Type="String">[EntityId]</Value>
          <Value Key="CallStart" Passes="1" Type="String">[CallStartTimeUTC]</Value>
          <Value Key="CallEnd" Passes="1" Type="String">[CallEndTimeUTC]</Value>
        </PostValues>
      </Request>
      <Variables />
      <Outputs AllowEmpty="false" />
    </Scenario>
  </Scenarios>
</Crm>
 
XML:
<Rules>
   <Rule Type="Any">customer.CustomerID</Rule>
</Rules>
<Variables>
   <Variable Name="CustomerID" Path="customer.Details.ID">
       <Filter />
   </Variable>
    ...

Why is the rule different from the EntityId path? That could be why.

Also, make sure you clear CRM contacts in the console to prevent issues during your testing. (Advanced > Contacts > Delete > Delete CRM Contacts)
 
  • Like
Reactions: edossantos
Thanks again for the quick response.

After changing the rule to the same path as CustomerID (and therefore EntityID path) i'm still not receiving EntityID or CustomerID in the JSON object being received.

Seems like it's just not pulling through at all, even though it's visible during testing,
 
Thanks again for the quick response.

After changing the rule to the same path as CustomerID (and therefore EntityID path) i'm still not receiving EntityID or CustomerID in the JSON object being received.

Seems like it's just not pulling through at all, even though it's visible during testing,
I would be curious to check a few things. Might sound stupid but make sure you're on U3 Hotfix 1. A couple bugs were fixed in U3.

Can you send me (via DM) an example of JSON data returned by your API?

Then, also attach the full XML file.

I'll see if I can figure why it doesn't populate.
 
  • Like
Reactions: edossantos
We're running version 18.0 (Build 461).

Thanks for your help, have DM'd you with the requested information! :)
 
Something else to check, I see that the CreateContactRecord scenario is not returning the EntityId or EntityType. If the contact is not found, and the template ends up creating a new contact, you will not have the information.
 
Thanks for that - I did actually add that in shortly after my post on here at 12:42, however no luck.

What is strange is that I am now receiving the CustomerID (EntityID) in around 5% of the POSTs to our API. It's really infrequent but is working rarely. I have no idea what I'm missing but getting SOME results through is a positive step.
 
Ensure that you delete all the CRM contacts from the 3CX Console > Advanced > Contacts > Bulk Delete. Otherwise 3CX could be matching the calls with old entries, which don't have this information. That is probably the case if you get the ID in some calls, but not all....
 
  • Like
Reactions: Evolute IT
Thanks for that! Tried deleting all CRM contacts and hasn't improved things at all. Still getting infrequent IDs coming through but for the most part it's an empty string.
 
Thanks for that! Tried deleting all CRM contacts and hasn't improved things at all. Still getting infrequent IDs coming through but for the most part it's an empty string.
The logs will tell you where the issue is....
 
  • Like
Reactions: Evolute IT
What logs, sorry? When I look at the CRM > Test > Logs, all appears to be normal. It's just the POST received in our API that is missing the ID 95% of the time
 
What logs, sorry?
You need to verbose logs from the 3CX Console > Dashboard > Activity Log > Settings. Then make a test call where you reproduce the issue, and check the 3csSystemService.log file that you can download from the 3CX Console > Dashboard > Activity Log > Logs button > Instance folder.
 
Thanks for that - I can't see anything in the log that would point out to me why we're not receiving the customerID in the POST request to our API.

I'm happy to send you the logs if that would help but I can't see anything that is pointing me in the right direction, sadly.
 
Please generate the support information package as described here, and send me the ZIP in a private message.
 
How long are your phone numbers? I recently had an issue with numbers longer than a certain length , worked ok for shorter numbers.

Set that in your contact lookup
 
HI Greychain,

The issue happens regardless of phone number length, predominantly the numbers are 11 characters long.
 
Hello @AdamTR,

Thanks for sending the support information package.

I can see that you have the issue described by @greychain, you need to return contacts having a unique Contact URL, then the output you have:
<Output Type="ContactUrl" Passes="0" Value="https://XXXXXXXXXXX.co.uk/crm/customer/[EntityId]" />

Should become (please note the case):
<Output Type="ContactUrl" Passes="0" Value="https://XXXXXXXXXXX.co.uk/crm/customer/[EntityID]" />

This is because you're defining a variable named EntityID, which is different from the Output EntityId. The case is important here, but also please note that you can't use output values in other outputs, you can only use static text or variables to create an output.

This change will cause that contacts are properly added to 3CX contacts (currently all the calls are overriding the values for a unique contact), then when the call ends, depending on the number of simultaneous calls, the contact was already edited, and the number can't be found in 3CX Contacts. So this will definitely fix the issue you're having. This also explains why it works in a few cases (when the call ends before another call starts).
 
Status
Not open for further replies.

Latest Posts

Forum statistics

Threads
112,323
Messages
591,891
Members
165,470
Latest member
Robert Lee