Performing a second url request

Status
Not open for further replies.

THordijk

Forum User
Joined
Aug 5, 2019
Messages
27
Reaction score
6
I am trying to properly intergrate our 3CX system with our crm. I have been succesful in establishing a conection between the two an retrieving data.
The issue that I am facing is the fact that the crm does not store the companyname in the "people" database, here this is simply a number as an Id.
In order to retrieve the actual name of the company I would need to perform a second url request to a different database page. I have attempted to realize this by altering the working xml template that i have but unsuccesful. When I try using the xml template attached it finishes the first request and then throughs an error. I am not very familair with xml so most of what I am trying is simple guessing work.

Is it at all possible to perform a second url request before outputting the data? If so how would this be implemented?
 

Attachments

Hello @THordijk,

Yes, it's absolutely possible, and indeed we do this in some of the integrations we provide. The lookup scenario ends generating an output. But this output can also be configured to chain the execution with a seconds scenario. Please check this:
https://www.3cx.com/docs/server-side-crm-template-xml-description/#h.gygnghdx4oa3

In your XML you're putting 2 Request elements inside the same Scenario element. This is wrong. Each scenario needs 1 Request element. Then you configure the output of the first scenario as:
<Outputs Next="SecondScenario"/>

And then you define a second scenario with ID, and its own Request inside:
XML:
    <Scenario Id="SecondScenario" Type="REST">
      <Request Url="http://tickets.riwo.eu/api/v1/organizations/[CompanyId]" MessagePasses="0" RequestEncoding="UrlEncoded" RequestType="Get" ResponseType="Json" />
      <Rules>
        <Rule Type="Any">Id</Rule>
      </Rules>
      <Variables>
        <Variable Name="CompanyName" Path="name">
          <Filter />
        </Variable>
      </Variables>

      <Outputs AllowEmpty="false">
        <Output Type="Id" Passes="0" Value="[Id]" />
        <Output Type="FirstName" Passes="0" Value="[FirstName]" />
        <Output Type="LastName" Passes="0" Value="[LastName]" />
        <Output Type="CompanyId" passes="0" Value="[organization_id]" />
        <Output Type="CompanyName" Passes="0" Value="[CompanyName]" />
        <Output Type="PhoneBusiness" Passes="0" Value="[PhoneBusiness]" />
        <Output Type="PhoneMobile" Passes="0" Value="[PhoneMobile]" />
        <Output Type="ContactUrl" Passes="0" Value="http://tickets.riwo.eu/#user/profile/[Id]" />
      </Outputs>
    </Scenario>
 
Okay i edited the XML based on what you stated above. I also looked at the Zendesk xml template as a reference. I can confirm that the second url request is executed and the data is fetched correctly however after that an error is thrown: Value cannot be null. Parameter name: key; I don't have a parameter named key as far as i can see so this does not make sense to me. Could you have another look for me?
 

Attachments

The matching rule you have in your XML for the first scenario seems to have the wrong case. You have:
XML:
      <Rules>
        <Rule Type="Any">Id</Rule>
      </Rules>

But the response returns "id" with lower case, so it should be set to:
XML:
      <Rules>
        <Rule Type="Any">id</Rule>
      </Rules>

Also, the log doesn't seem to belong to the XML you sent, because it mentions a chained scenario with ID "GetCompanyName", but that scenario doesn't exist in your XML. You have a scenario with ID "SecondScenario". So ensure that you send the log and the XML for the same run.
 
But the response returns "id" with lower case, so it should be set to:
This has not been an issue before but i changed it to all lower case

Also, the log doesn't seem to belong to the XML you sent, because it mentions a chained scenario with ID "GetCompanyName", but that scenario doesn't exist in your XML. You have a scenario with ID "SecondScenario". So ensure that you send the log and the XML for the same run.
Okay, I am a 100% certain that it was the same template simply with a different name. I redid the test so everything would be the same this time, the error has not changed though. I will attach the corresponding files.
 

Attachments

What version of 3CX are you running? You can check this from the 3CX Console > Dashboard.
 
we are running Professional Perpetual 16.0.676, i guess
 
The problem is when you generate the Outputs:
XML:
      <Outputs AllowEmpty="true">
        <Output Type="Id" Passes="0" Value="[Id]" />
        <Output Type="FirstName" Passes="0" Value="[FirstName]" />
        <Output Type="LastName" Passes="0" Value="[LastName]" />
        <Output Type="CompanyName" Passes="0" Value="[CompanyName]" />
        <Output Name="CompanyId" Passes="0" Path="[CompanyId]" />
        <Output Type="PhoneBusiness" Passes="0" Value="[PhoneBusiness]" />
        <Output Type="PhoneMobile" Passes="0" Value="[PhoneMobile]" />
        <Output Type="ContactUrl" Passes="0" Value="http://tickets.riwo.eu/#user/profile/[Id]" />
      </Outputs>

The output for CompanyId doesn't have the proper attributes... It seems you copied and pasted it from a variable, and didn't change the attributes....
 
  • Like
Reactions: Evolute IT
I did copy it, my bad thought I had corrected everything. I changed it and checked but the behaviour has not changed. I am still getting the same error at the same point.
 
I just spotted what was going on. The "n" in name in front of CompanyName was lowercase, but needs to be uppercase, which is why the key: "CompanyName" was null i guess. It is working just fine right now.

Thank you for your help and patience!
 
  • Like
Reactions: edossantos
Status
Not open for further replies.

Latest Posts

Forum statistics

Threads
112,324
Messages
591,897
Members
165,475
Latest member
lastshadow