How do I convert a json body statement into a 3cx CRM template

Status
Not open for further replies.

abes45

Silver Partner
Joined
Jan 11, 2022
Messages
3
Reaction score
0
I am currently working on creating a custom CRM template, I have successfully crated a contact on the CRM with the following Json as body

[
{
"Attribute": "FirstName",
"Value": "New"
},
{
"Attribute": "LastName",
"Value": "3CX Lead"
},
{
"Attribute": "Phone",
"Value": "88888888888"
}
]


How do convert this to 3cx crm template generator format?
 
Thanks,

The issue is I want to make <Array>...</Array> as the root tag, This is what I embeded in the PostValue tag:
XML:
<Array>
    <Object>
        <Value Key="Attribute" Passes="1" Type="String">Phone</Value>
        <Value Key="Value" Passes="1" Type="String">[Number]</Value>  
    </Object>
       
    <Object>
        <Value Key="Attribute" Passes="2" Type="String">FirstName</Value>
        <Value Key="Value" Passes="2" Type="String">[[CreateContactFirstName]]</Value>  
    </Object>
       
    <Object>
        <Value Key="Attribute" Passes="2" Type="String">LastName</Value>
        <Value Key="Value" Passes="2" Type="String">[[CreateContactLastName]]</Value>  
    </Object>
</Array>

This is what I get as the JSON request:
JSON:
{"":[{"Attribute":"Phone","Value":"8888888888"},{"Attribute":"FirstName","Value":"New"},{"Attribute":"LastName","Value":"3cx Lead"}]}


This is throwing an error because the request is wrapped in <Object Key="" />({"":...}) instead of <Array />([...]])

How can I resolve this..
 
Using <PostValues> you will always wrap everything in an object. You should use the Message attribute in your request.
https://www.3cx.com/docs/server-side-crm-template-xml-description/#h.y9d8fvk49vst

For example:
<Request Url="https://YOUR_URL" Message="[{^^Attribute^^: ^^FirstName^^,^^Value^^: ^^New^^},{^^Attribute^^: ^^LastName^^,^^Value^^: ^^3CX Lead^^},{^^Attribute^^: ^^Phone^^,^^Value^^: ^^88888888888^^}]" RequestContentType="application/json" RequestType="Post" ResponseType="Json" />
 
Status
Not open for further replies.

Latest Posts

Forum statistics

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