ldap2json w/ Active Directory

Status
Not open for further replies.

BayAC

Customer
Joined
Jan 8, 2020
Messages
17
Reaction score
8
I'm attempting to get the 3CX JSON integration to work with the ldap2json python module so that incoming CID can be looked up against AD to display caller name. I was able to get the web service set up and I can query my AD and get a JSON return, but I can't for the life of me figure out how to use the XML template wizard to validate a config before I try to upload it to the PBX.

The response tree for my query shows 2 nodes, [0] which contains the DN of the AD object, and [1] which has all the attributes. The tree shows, under [1], mobile = 'xxxxxxxxxx', but the tool won't show it as bold, so I don't think it's matching when I do a contact lookup. If I look at the raw JSON response, the path looks like it should be [1].mobile.[0] because mobile contains a single element array but that doesn't seem to work either.

Any chance someone can offer some guidance on how to get the matching rules to work so this thing can read the values I'm pulling? I tried to paste the output of my query into jsonpath.com but to get the mobile number in that tool I have to use $.0.1.mobile.0
 
Can you please share the XML template you have so far? And a full sample of the JSON response you're getting from the web service?
 
XML Template
<?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="ldap2json" Version="1">
<Number Prefix="AsIs" MaxLength="[MaxLength]" />
<Connection MaxConcurrentRequests="2" />
<Parameters />
<Authentication Type="No" />
<Scenarios>
<Scenario Id="" Type="REST">
<Request SkipIf="" Url="http://10.2.1.10:8080/ldap?|(telephoneNumber=[Number])(mobile=[Number])" MessagePasses="0" RequestEncoding="UrlEncoded" RequestType="Get" ResponseType="Json" />
<Rules>
<Rule Type="Any">[1].mobile</Rule>
</Rules>
<Variables>
<Variable Name="ContactID" Path="cn.[:1]">
<Filter />
</Variable>
<Variable Name="FirstName" Path="givenName">
<Filter />
</Variable>
<Variable Name="LastName" Path="sn">
<Filter />
</Variable>
<Variable Name="CompanyName" Path="company">
<Filter />
</Variable>
<Variable Name="Email" Path="mail">
<Filter />
</Variable>
<Variable Name="PhoneBusiness" Path="telephoneNumber">
<Filter />
</Variable>
<Variable Name="PhoneMobile" Path="[1].mobile.[0]">
<Filter />
</Variable>
<Variable Name="PhoneMobile2" Path="otherMobile">
<Filter />
</Variable>
<Variable Name="ContactUrl" Path="http://10.2.1.10:8080/ldap?cn=[ContactID]">
<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="" />
<Output Type="PhoneBusiness" Passes="0" Value="[PhoneBusiness]" />
<Output Type="PhoneMobile" Passes="0" Value="[PhoneMobile]" />
<Output Type="PhoneMobile2" Passes="0" Value="[PhoneMobile2]" />
<Output Type="ContactUrl" Passes="0" Value="[ContactUrl]" />
</Outputs>
</Scenario>
</Scenarios>
</Crm>
[/QUOTE]
 
JSON response
[
[
"CN=Tyler Durden,OU=Users,DC=contoso,DC=net",
{
"primaryGroupID": [
"513"
],
"cn": [
"Tyler Durden"
],
"countryCode": [
"0"
],
"objectClass": [
"top",
"person",
"organizationalPerson",
"user"
],
"userPrincipalName": [
"[email protected]"
],
"instanceType": [
"4"
],
"distinguishedName": [
"CN=Tyler Durden,OU=Users,DC=contoso,DC=net"
],
"dSCorePropagationData": [
"16010101000000.0Z"
],
"objectSid": [
"\u0001\u0005\u0000\u0000\u0000\u0000\u0000\u0005\u0015\u0000\u0000\u0000\u00c8\u00c4\u00e0Hn\u0099\u00e8w\u00adtd\u0092\u0010\u0012\u0000\u0000"
],
"whenCreated": [
"20200922193620.0Z"
],
"uSNCreated": [
"3626021"
],
"pwdLastSet": [
"0"
],
"sAMAccountName": [
"tylerd"
],
"objectCategory": [
"CN=Person,CN=Schema,CN=Configuration,DC=contoso,DC=net"
],
"objectGUID": [
"`\u00c5\u009cu\u00f3\u00f6\u00efI\u00b6\u00f6x1\u00d8\u000b\u00a6\u00f8"
],
"whenChanged": [
"20200922193644.0Z"
],
"accountExpires": [
"9223372036854775807"
],
"displayName": [
"Tyler Durden"
],
"name": [
"Tyler Durden"
],
"mobile": [
"1234567890"
],
"codePage": [
"0"
],
"userAccountControl": [
"512"
],
"sAMAccountType": [
"805306368"
],
"uSNChanged": [
"3626036"
],
"sn": [
"Durden"
],
"givenName": [
"Tyler"
]
}
]
]
 
I've been doing some tests with this JSON and XML template, and there are problems because the first item in the array is just a string, and the second is an object. When I remove the first item, having only this JSON:
JSON:
[
   [
      {
         "primaryGroupID":[
            "513"
         ],
         "cn":[
            "Tyler Durden"
         ],
         "countryCode":[
            "0"
         ],
         "objectClass":[
            "top",
            "person",
            "organizationalPerson",
            "user"
         ],
         "userPrincipalName":[
            "[email protected]"
         ],
         "instanceType":[
            "4"
         ],
         "distinguishedName":[
            "CN=Tyler Durden,OU=Users,DC=contoso,DC=net"
         ],
         "dSCorePropagationData":[
            "16010101000000.0Z"
         ],
         "objectSid":[
            "\u0001\u0005\u0000\u0000\u0000\u0000\u0000\u0005\u0015\u0000\u0000\u0000\u00c8\u00c4\u00e0Hn\u0099\u00e8w\u00adtd\u0092\u0010\u0012\u0000\u0000"
         ],
         "whenCreated":[
            "20200922193620.0Z"
         ],
         "uSNCreated":[
            "3626021"
         ],
         "pwdLastSet":[
            "0"
         ],
         "sAMAccountName":[
            "tylerd"
         ],
         "objectCategory":[
            "CN=Person,CN=Schema,CN=Configuration,DC=contoso,DC=net"
         ],
         "objectGUID":[
            "`\u00c5\u009cu\u00f3\u00f6\u00efI\u00b6\u00f6x1\u00d8\u000b\u00a6\u00f8"
         ],
         "whenChanged":[
            "20200922193644.0Z"
         ],
         "accountExpires":[
            "9223372036854775807"
         ],
         "displayName":[
            "Tyler Durden"
         ],
         "name":[
            "Tyler Durden"
         ],
         "mobile":[
            "1234567890"
         ],
         "codePage":[
            "0"
         ],
         "userAccountControl":[
            "512"
         ],
         "sAMAccountType":[
            "805306368"
         ],
         "uSNChanged":[
            "3626036"
         ],
         "sn":[
            "Durden"
         ],
         "givenName":[
            "Tyler"
         ]
      }
   ]
]

And then adjusting the XML template as follows:
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="ldap2json" Version="1">
  <Number Prefix="AsIs" MaxLength="[MaxLength]" />
  <Connection MaxConcurrentRequests="2" />
  <Parameters />
  <Authentication Type="No" />
  <Scenarios>
    <Scenario Id="" Type="REST">
      <Request SkipIf="" Url="http://localhost:8080/queuemetrics/response.json" MessagePasses="0" RequestEncoding="UrlEncoded" RequestType="Get" ResponseType="Json" />
      <Rules>
        <Rule Type="Any">mobile</Rule>
      </Rules>
      <Variables>
        <Variable Name="ContactID" Path="primaryGroupID">
          <Filter />
        </Variable>
        <Variable Name="FirstName" Path="givenName">
          <Filter />
        </Variable>
        <Variable Name="LastName" Path="sn">
          <Filter />
        </Variable>
        <Variable Name="CompanyName" Path="company">
          <Filter />
        </Variable>
        <Variable Name="Email" Path="userPrincipalName">
          <Filter />
        </Variable>
        <Variable Name="PhoneMobile" Path="mobile">
          <Filter />
        </Variable>
        <Variable Name="ContactUrl" Path="http://10.2.1.10:8080/ldap?cn=[ContactID]">
          <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="PhoneMobile" Passes="0" Value="[PhoneMobile]" />
        <Output Type="ContactUrl" Passes="0" Value="[ContactUrl]" />
      </Outputs>
    </Scenario>
  </Scenarios>
</Crm>

I can get it working and reading the values from the JSON response:
1600875437210.png

Is it possible for you to adjust the JSON returned?
 
  • Like
Reactions: Evolute IT
I'd use the Web service to manipulate the JSON instead of relying on 3CX to understand a weird structure.

JSON APIs work so much better lol
 
Thanks for that, I'll see if I can get the script to change what it's doing on the output side.
 
I ended up getting this working thanks to your help. I'll post back here with a link once I've got it fully tested and cleaned up.
 
Status
Not open for further replies.

Latest Posts

Forum statistics

Threads
112,325
Messages
591,898
Members
165,477
Latest member
Mueller