Solved ServiceM8 - 3CX error on contact creation

Status
Not open for further replies.

richiewhite

Platinum Partner
Advanced Certified
Joined
Jun 19, 2019
Messages
81
Reaction score
87
Hi team, I've been tearing my hair out with this. I'm working on an integration with ServiceM8 which is mostly working, but I've run into a hurdle with contact creation.

I've ended up running a local service to try and deal with some limitations in the ServiceM8 API in this case, mainly that you need to create a "client" that a contact is then assigned to, so I have set this microservice to:
- Search for the name of the Company entered in the contact creation form in the Client endpoint
- Record the ID if found, otherwise create a new Client with that name and record the ID returned
- Attach the ID to a new request to the contact endpoint and create it

Where it got a bit messy is that ServiceM8 responds to POST with the UUID of the new entity in the header rather than body, but the microservice handles this as well.

I'm getting 3CX sending back an error to the user whenever this workflow is used, however I can't find anything in the logs to indicate why. My microservice is returning JSON as below:
{
"id": "a12b1bba-d427-4923-b0e9-24024e23dc2b",
"firstname": "Test",
"lastname": "User",
"phone": "+6421000006",
"email": "",
"company": "testing",
"company_id": "7dc833ea-8c01-456a-b443-23fc782fa48b"
}

and the scenario is as below:
<Scenario Id="CreateContactRecordFromClient" Type="REST" EntityId="" EntityOrder="">
<Request SkipIf="[CreateContactEnabled]!=True" Url="http://127.0.0.1:8080/contacts" MessagePasses="0" RequestEncoding="Json" RequestType="Post" ResponseType="Json">
<Headers>
<Value Key="X-API-Key">[APIKey]</Value>
</Headers>
<PostValues>
<Value Key="firstname" SkipIf="" Passes="0" Type="String">[FirstName]</Value>
<Value Key="lastname" SkipIf="" Passes="0" Type="String">[LastName]</Value>
<Value Key="email" If="!=&quot;&quot;" SkipIf="" Passes="1" Type="String">[Email]</Value>
<Value Key="phone" If="[Number]!=&quot;&quot;" SkipIf="" Passes="1" Type="String">[Number]</Value>
<Value Key="company" SkipIf="" Passes="0" Type="String">[Company]</Value>
</PostValues>
</Request>
<Rules>
<Rule Type="Any">id</Rule>
</Rules>
<Variables>
<Variable Name="Id" LookupValue="" Path="id"><Filter /></Variable>
</Variables>
<Outputs AllowEmpty="false">
<Output Type="ContactUrl" Passes="0" Value="https://app.servicem8.com/clients/[Id]" />
<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="[Number]" />
<Output Type="EntityId" Passes="0" Value="[Id]" />
<Output Type="EntityType" Passes="0" Value="Contacts" />
</Outputs>
</Scenario>
Hopefully someone can see what I'm missing?
 
Last edited:
I'd check the logs. This looks good to me, there must be something weird somewhere.

3CXManagementConsole.log --> for contact creation and search.
3cxSystemService.log --> for lookups and call/chat journaling
 
  • Like
Reactions: richiewhite
I would try adding an output with the CompanyName, just in case 3CX is expecting this to match with what it was requested....
<Output Type="CompanyName" Passes="0" Value="[Company]" />
 
Might I suggest you give this a go: https://www.3cx.com/blog/docs/crm-xml-templates/

...and if things do not work 100% at the first run, feed the log errors back into the AI Agent and get it to fix things. Its quite interesting to see how far you can go with it!
 
I managed to sort this, the logs show that 3CX wasn't matching anything from the response. My microservice was returning a response with flat json, when I tweaked it to return an array and then changed the rule to <Rule Type="Any">contact.id</Rule> it managed to work. Teach me for trying to be too clever!
 
Status
Not open for further replies.