AFAS integration

Status
Not open for further replies.

Daan L

Platinum Partner
Advanced Certified
Joined
Jul 24, 2020
Messages
25
Reaction score
1
A customer wants to integrate their AFAS solution with 3CX. The following URL is needed to send the phone number:

https://[ServerURL]?filterfieldids=Telefoonnr._werk&filtervalues=[Number]&operatortypes=1

Request code:
MessagePasses="0" RequestEncoding="UrlEncoded" RequestType="Get" ResponseType="Json"

The CRM template Generator crashes when I add the URL. Is there a solution?
 
Can you show the template you created so far? What do you mean by "The CRM template Generator crashes when I add the URL"? Can you share an screenshot of the error you're getting?
 
Weird. the CRM tool does not crash any more. I tested it for at least 10 times. It didn't like the "&" sign after "Telefoonnr._werk".

The only error I get now is the following while trying to connect (API key works in a test tool provided by AFAS):
Code:
System.Exception: Server returned a non successful status code - HTTPStatusCode=Unauthorized - Reason=Unauthorized - Content=
   bij CrmIntegration.ScenarioProcessorBase.<ProcessRequest>d__17.MoveNext()
--- Einde van stacktracering vanaf vorige locatie waar uitzondering is opgetreden ---
   bij System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   bij System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   bij CrmIntegration.ScenarioProcessorBase.<ProcessScenario>d__8.MoveNext()
--- Einde van stacktracering vanaf vorige locatie waar uitzondering is opgetreden ---
   bij System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   bij System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   bij CrmIntegration.ScenarioProcessorBase.<Execute>d__7.MoveNext()
--- Einde van stacktracering vanaf vorige locatie waar uitzondering is opgetreden ---
   bij System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   bij CrmIntegration.CrmProcessor.<GetContactInfoFromCrm>d__12.MoveNext()
 

Attachments

It didn't like the "&" sign after "Telefoonnr._werk".
The & needs to be escaped as &amp; in the XML.

The only error I get now is the following while trying to connect (API key works in a test tool provided by AFAS):
The error Unauthorized means that credentials are fine, but your user doesn't have permissions to access the resource you're trying to access...
 
  • Like
Reactions: Evolute IT
Is 3CX capable of authenticating as expected by AFAS?

The customer provided a token.

Required:
TLS 1.2 is required for all requests.


Code:
Example: token conversion

Token
<token><version>1</version><data>54740093832496081845474abcdefghijklmnopq740093832496081841234127</data></token>

Base64 string:
PHRva2VuPjx2ZXJzaW9uPjE8L3ZlcnNpb24+PGRhdGE+NTQ3NDAwOTM4MzI0OTYwODE4N
DU0NzRhYmNkZWZnaGlqa2xtbm9wcTc0MDA5MzgzMjQ5NjA4MTg0MTIzNDEyNzwvZGF0YT48L3Rva2VuPg==

Source:
https://help.afas.nl/help/EN/SE/App_Cnr_Rest_Api.htm#o106269
 
Requests are sent over HTTPS if you specify that protocol, and that will use TLS 1.2.

Regarding the token, where do you need to send it? As part of the query string? As a header? As POST data? You can use any of those approaches, you just need to understand how you need to send the request, and configure the template to do it that way.
 
I connect to a connector URL. The token is specifically for that URL:

https://xxxxx.rest.afas.online/Prof...amp;filtervalues=[Number]&amp;operatortypes=1

Header

The header is only used for authorisation.

Key: "Authorisation"

Value: "AfasToken PHRva2VuPjx2ZXJzaW9uPjE8L3ZlcnNpb24+PGRhdGE+NTQ3NDAwOTM4MzI0OTYwODE4NDU0Nz
RhYmNkZWZnaGlqa2xtbm9wcTc0MDA5MzgzMjQ5NjA4MTg0MTIzNDEyNzwvZGF0YT48L3Rva2VuPg=="

The value is the Base64 string of the token including XML tags. For this, the following applies AfasToken + space.
 
So, you need to send that value in the Authorisation header. Are you sure it's not Authorization?

This is how you can send the header in your request, currently you have:
XML:
<Request SkipIf="[IIf([FoundRecordCount]&gt;0,True,False)]" Url="[ApiServer]?filterfieldids=Telefoonnr._werk&filtervalues=[Number]&operatortypes=1" MessagePasses="0" RequestEncoding="UrlEncoded" RequestType="Get" ResponseType="Json" />

And you need to change it as follows:
XML:
<Request SkipIf="[IIf([FoundRecordCount]&gt;0,True,False)]" Url="[ApiServer]?filterfieldids=Telefoonnr._werk&filtervalues=[Number]&operatortypes=1" MessagePasses="0" RequestEncoding="UrlEncoded" RequestType="Get" ResponseType="Json" >
    <Headers>
        <Value Key="Authorization">AfasToken PHRva2VuPjx2ZXJzaW9uPjE8L3ZlcnNpb24+PGRhdGE+NTQ3NDAwOTM4MzI0OTYwODE4NDU0Nz
RhYmNkZWZnaGlqa2xtbm9wcTc0MDA5MzgzMjQ5NjA4MTg0MTIzNDEyNzwvZGF0YT48L3Rva2VuPg==</Value>
    </Headers>
</Request>
 
It works. Thank you!
 
How do I map the fields? All the data is there, but the template isn't mapping any data.
Code:
Response text: { "skip" : 0,
  "take" : 1,
  "rows" : [{"ID":3,"Voornaam":null,"Voorvoegsel":null,"Achternaam":null,"Naam":"Name of the Company","E-mail_werk":"[email protected]","Mobiel_werk":null,"Telefoonnr._werk":"0123-123456","Verkooprelatie":"1000","Inkooprelatie":"2000","Org.per.":"V"}]}


The mapping:
Code:
      <Rules>
        <Rule Type="Any">1</Rule>
      </Rules>
      <Variables>
        <Variable Name="ContactID" Path="Verkooprelatie"><Filter /></Variable>
        <Variable Name="FirstName" Path="Naam"><Filter /></Variable>
        <Variable Name="CompanyName" Path="Naam"><Filter /></Variable>
        <Variable Name="PhoneBusiness" Path="Telefoonnr._werk"><Filter /></Variable>
        <Variable Name="PhoneMobile" Path="Mobiel_werk"><Filter /></Variable>
      </Variables>
      <Outputs AllowEmpty="true">
        <Output Type="ContactID" Passes="0" Value="[ContactID]" />
        <Output Type="FirstName" Passes="0" Value="[FirstName]" />
        <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="https://[AfasServer][ContactID]" />
      </Outputs>


3CX test response:
Code:
Variable ContactID set to
Variable FirstName set to
Variable CompanyName set to
Variable PhoneBusiness set to
Variable PhoneMobile set to
 
Last edited:
You're specifying wrong rules and variable paths.

First, for the rule you need to specify a path to distinguish records. So, from your JSON it seems it should be:
<Rule Type="Any">rows.ID</Rule>

The same for variables, for example:
<Variable Name="ContactID" Path="rows.Verkooprelatie"></Variable>
 
It works now for the most part. There is still one issue.

When doing a lookup, only the last 6 digits are send to the CRM since some numbers contain a "-".

+31612345678 > 345678

The CRM sends back: 0612-345678

Also the customer details are send back. So there is a match.

But when testing the CRM connection 3CX shows an error:
Code:
CRM Integration is working OK but contact number does not exist. Check log for more info or try a different number.

How can I solve this?
 
If you need to send the full number, or even more than 6 digits, you can control this from the 3CX Console > Advanced > Contacts > Options.

Regarding the issue, you need to check the Log tab when you do a test lookup, there you should be able to see what's going on.
 
The issue is I cannot find the log file.

Logging is set to medium.
 
When you test this from the 3CX Console > Settings > CRM Integration > Test button, you will see a Log tab which will give you the details of the interaction with the CRM. Do you see it?
 
The gray area gives no usefull information. It only states that the phone number in the response isn't mapped to the BusinessPhone field.
 

Attachments

  • 3CX_no_log.png
    3CX_no_log.png
    30.9 KB · Views: 16
It's important that the caller number is matched to a number from the returned JSON data. Otherwise the returned record will be skipped.
 
The test:
1. Incoming number: 0123-123456
2. Sending last 6 digits to CRM.
3. CRM returns 0123-123456
4. According to 3CX no match.

In my opinion it is a perfect match.

In the future the incoming number will be +31123123456. In the CRM the telephone numbers have a different formatting. Will this work? Rewriting +31 to 0 is possible.
 
The test:
1. Incoming number: 0123-123456
2. Sending last 6 digits to CRM.
3. CRM returns 0123-123456
4. According to 3CX no match.

In my opinion it is a perfect match.
I would like to see the log details. Can you send them to me in a private message?

In the future the incoming number will be +31123123456. In the CRM the telephone numbers have a different formatting. Will this work? Rewriting +31 to 0 is possible.
This will depend on your configuration. If you use "exact match" in the 3CX Console > Advanced > Contacts > Options, then it will not be considered a match if any digit differs. However, if you compare the last 6 digits as you're doing now, it will be a match.

Please note however that we're investigating an issue in the latest version of 3CX v16 Update 6, which causes that the matched contact is not shown in the web client if there is no exact match. This should be fixed soon, but if you test that case now with the latest version you will have issues.
 
  • Like
Reactions: Evolute IT
Status
Not open for further replies.

Latest Posts

Forum statistics

Threads
112,324
Messages
591,897
Members
165,476
Latest member
awan05