Advanced Rules Based Integration with Catalina API for SL

Catalina’s API for Dynamics SL can be used for many things. We can retrieve all types of data from SL. We can also save transactions to SL. In this demo I did for several folks, I am taking sensor data and pushing it through an advanced rules based engine to create Service Calls in Dynamics SL.

While this demo highlights Dynamics SL, we could just as easily use these same types of rules based development to integrate with other systems like CRM, helpdesk, field service, etc. We can monitor all types of things like temperature, barometric pressure, vibrations (helpful if you an HVAC company and need to monitor your customer’s properties for problems), humidity, ambient light, flooding, and more.


Sending Information to Catalina Support

There are times that you might have questions or problems when developing using an API. You contact support and they will ask you to send you the “payload” you are using when communicating with the Catalina API for Dynamics SL. The easiest way to do this, if you are using Postman as your testing environment, is to export the code. This is done in these simple steps

Step 1:
Got to your postman tab you are making the API call from and click on the “Code” link on the right of the screen

Step 2:
On the popup, click on cURL and then copy the text provided, paste it into an email, and send to Support.


Custom Properties in SLQuickCollect

SLQuickCollect is Catalina’s solution that allows you to email or SMS message out a simple link to your customer as a request for payment.

Custom properties are a way to personalize the emails that go out to the customer. As well as the payment page and receipts they see. You can have an unlimited number of parameters with whatever text you want to send to the customer. And you can place it anywhere you want on the email and page templates.

Here is a quick demo on how you can do this via a RESTful API. And how to modify the templates to display the parameters.

Below is an example of a payload that you would send to the SLQuickCollect API.

{
    "parameters": [
        {
            "name": "CpnyID",
            "value": "0060"
        },
        {
            "name": "CustID",
            "value": "C300"
        },
        {
            "name": "Amount",
            "value": "10.23"
        },
        {
            "name": "PaymentEmailList",
            "value": "[email protected]"
        },
        {
            "name": "Properties",
            "value": "<nameValuePairs><key name=\"ORDNBR\" value=\"123456\"/><key name=\"COMMENTS\" value=\"Hi Ted, I appreciate your business.\"/></nameValuePairs>"
        }
    ]
}

There are several Parameters that are sent:

  • CpnyID: Your company ID in your SL system.
  • CustID: The Customer ID of the customer you are sending the payment request to.
  • Amount: The amount you want to collect
  • PaymentEmailList: A delimited list of emails that the request is going to go to.
  • Properties: This is a list of properties as Name/Value pairs. You can create as many of these properties as you want. And then you can display them in the email, payment page, receipt email, and receipt page templates any way you want.

When you want to display a custom property on a template page, you use this ASP.NET format:

<%=getProperty(“PropertyName“)%>

So, if the property name is “COMMENTS”, you would use this:

<%=getProperty(“COMMENTS“)%>


Call Stored Procedures Using Catalina’s API for Dynamics SL and Postman

It is simple to call a stored procedure through a RESTful API call if you have Catalina’s API for Dynamics SL. You can call any stored procedure and pass parameters and retrieve data.

This is a demo on how to call a stored procedure using Postman and Catalina’s API for Dynamics SL.

First, to do this demo, you need to download and install Postman. Postman is a developer tool that allows you to interact with API’s easily so that you can test API calls to see how you call them and what data is returned. You can get Postman here: https://www.postman.com/

In the demo, we are going to call the stored procedure SOHeader_all. This stored procedure retrieves all Sales Order Headers (SOHeader) for a particular CpnyID and OrdNbr. NOTE: this is just an example. With Catalina’s API, you can call any stored procedure.

SOHeader_all has 2 parameters:
– @parm1: This parameter is for the CpnyID
– @parm2: This parameter is for the OrdNbr (can use a wildcard like ‘O000%’ which will bring back all orders that start with O000.

You can see what the procedure looks like here:

PROCEDURE [dbo].[SOHeader_all]
	@parm1 varchar( 10 ),
	@parm2 varchar( 15 )
AS
	SELECT *
	FROM SOHeader
	WHERE CpnyID = @parm1
	   AND OrdNbr LIKE @parm2
	ORDER BY CpnyID,
	   OrdNbr DESC

So, if you wanted to retrieve all orders that started with “O000” for CpnyID = “0060” you would call the stored procedure like this:

exec SOHeader_all @parm1='0060', @parm2='O000%'

So, now how to call this using Postman through Catalina’s API for SL?

First you need to know where your Catalina API is installed. I am going to use the server name yourserver.com as the domain name. So, for this example, we would look at the endpoint as the following:

http://yourserver.com/ctDynamicsSL/api/customSQL/<ProcedureName>

As you can see above, you would replace yourServer.com with wherever your server is. And you can see <ProcedureName> in the URL. this would be replaced with the actual stored procedure name you want to call (in this example, we are going to replace it with SOHeader_all). So, the new URL for the endpoint would look like the following:

http://yourserver.com/ctDynamicsSL/api/customSQL/SOHeader_all

In Postman, you would make it look like below. NOTE: when calling a customSQL stored procedure, you must use the action type of “POST”

Next, you need to set the authentication. This is done on the “Authorization” tab. Catalina’s API uses “Basic Auth”. So, make sure that you set the type for “Basic Auth” in the dropdown. And then enter the username and password that was given to you from your installer.

After that, you will have been given a SiteID from your installer. You will need to create a Header for that SiteID. You do this on the headers tab. You should enter that SiteID (in my example it is “DEFAULT”, but you would use the SiteID given to you by your installer) and the default CpnyID (in my example that is “0060”, but you would use your CpnyID of your database)

Finally, you will want to enter the body of the parameters that are being passed. There are 2 parameters for SOHeader_all (@parm1 and @parm2). The format of the body that you would set is below.

{
    "parameters": [
        {
            "name": "parm1",
            "value": "0060"
        },
        {
            "name": "parm2",
            "value": "O0005121"
        }
    ]
}

So, your Body tab in Postman would look like this (NOTE: make sure you select the “raw” radio button as shown below)

Then all you have to do is simply hit the “Send” button and the system should retrieve the results from your stored procedure call. In my example, it looks like below



Catalina API Error Not Able to Load Assembly

Question

When I try to access Catalina’s API for Dynamics SL, I am getting an error that looks like this. What is the problem, and how can I fix it?

Answer:

Look at the web.config of your ctDynamicsSL web application and remove the section <system.codedom>. So looking below, just remove this total section from your web.config

  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
    </compilers>
  </system.codedom>

Call Custom Stored Procedure via Catalina’s RESTful API for Dynamics SL

Catalina has had a way to call custom stored procedures from their SOAP based web services for Dynamics SL for years.  You can now do it using the RESTful API version.

Looking at the Swagger Documentation, you can now see a customSQL resource (If you don’t see this, contact Catalina Support to see about getting updated to the latest version of Catalina API for Dynamics SL)

Example using one of our procedures:

/api/customSQL/xct_spDSLvalidateContactID

{ 
    "parameters": 
    [
        { 
        "name": "ContactID", "value": "BJON"
        } 
        ,
        { 
        "name": "CustID", "value": "CT0100"
        } 
        ,
        { 
        "name": "Type", "value": "B"
        } 
    ]
    ,
    "checkSum": "3CB06C9A4A83BECCFC60684C271818EDEEAA5770" 
}

NOTE:  the checksum is a security feature that is turned on by default.  This allows the API to double check to make sure that you are who you say you are.  Use a SHA1 hash of the stored procedure name to generate the checksum.

The checksum requirement can be disabled in your DSLCONFIGFILE.xml  file.

You can generate the checksum using any SHA1 library, or you can use the library included in our service distribution: /ctDynamicsSL/bin/ctStandardLib.dll

var checksum = ctStandardLib.ctHelper.getHash(siteKey, storedProcedureName);


Retrieve Catalina Queue FIFO

If you use the Catalina Queue Engine for queuing records, you might want to retrieve data in a FIFO (First In First Out) method. This means you want to grab the oldest records first. This is easily accomplished by calling the Catalina Queue API with the parameter sortBy in the query string.

Example, if you are retrieving the queue ORDERS, you would format your URL, for the Queue API, like this:

http://YOURSERVER/ctDynamicsSL/api/queue/ORDER?sortBy=createdDate

This will then sort the queue in Ascending order by createdDate. Which means it will retrieve oldest items first.

Below is a curl example that does the same thing.

curl -X GET \
'http://YourServer/ctDynamicsSL/api/queue/QUEUETYPE?sortBy=createdDate' \
-H 'Accept: application/json' \
-H 'Authorization: Basic YOURAUTHHERE' \
-H 'Cache-Control: no-cache' \
-H 'Content-Type: application/json' \
-H 'CpnyID: YOURCPNYID' \
-H 'SiteID: YOURSITEID' \
-H 'cache-control: no-cache'

How to get a list of triggers

If you are like me, you spend a lot of time in Microsoft SQL Server. Often, a trigger can cause you a lot of grief. Whether it is a recursive trigger that goes into an endless loop. Or a trigger that is updating data in the recordset that you are trying to save (causing problems in your client code).

Here is a quick way to get a list of all triggers in a particular DB

SELECT 
     sysobjects.name AS trigger_name 
    ,USER_NAME(sysobjects.uid) AS trigger_owner 
    ,s.name AS table_schema 
    ,OBJECT_NAME(parent_obj) AS table_name 
    ,OBJECTPROPERTY( id, 'ExecIsUpdateTrigger') AS isupdate 
    ,OBJECTPROPERTY( id, 'ExecIsDeleteTrigger') AS isdelete 
    ,OBJECTPROPERTY( id, 'ExecIsInsertTrigger') AS isinsert 
    ,OBJECTPROPERTY( id, 'ExecIsAfterTrigger') AS isafter 
    ,OBJECTPROPERTY( id, 'ExecIsInsteadOfTrigger') AS isinsteadof 
    ,OBJECTPROPERTY(id, 'ExecIsTriggerDisabled') AS [disabled] 
FROM sysobjects WITH(NOLOCK)
INNER JOIN sys.tables t WITH(NOLOCK)
    ON sysobjects.parent_obj = t.object_id 
INNER JOIN sys.schemas s WITH(NOLOCK)
    ON t.schema_id = s.schema_id 
WHERE sysobjects.type = 'TR' 

You will get a result like this that will list out the triggers and which tables they are tied to.