ActiveCampaign API Integration With .NET

Introduction 

 
Want to integrate ActiveCampaign's account in the project? Not getting any library or package of ActiveCampaign? Don't know how to achieve it? In this blog, I will answer all of these questions with the help of the Github repository and learn to how to schedule it using System.Threading’s TimerCallback.
 
ActiveCampaign 
 
ActiveCampaign is a cloud software platform for small-to-mid-sized businesses. The company offers software for customer experience automation, which combines email marketing, marketing automation, sales automation, and CRM categories.
 
For API documentation please follow the below link.
 
In the repository, you can see APIResult.cs file which has models help to bind results of the ActiveCampaign API.
 
ActiveCampaign API needs api_action and api_key as a mandate parameters to execute the API.
 
ActiveCampaignClient.cs file has few functions that can help to execute ActiveCampaign API.
 
With the help of documentation, you could call API with few filters also. For example, getting contacts based on the attached tag.
 
For reference, you could check the "GetContactList" function.
 
What if I want to sync contacts or notes on a daily basis?
 
We have to create a Time scheduler on the server. We could also achieve this with TimerCallback.
 
We will make a Task which will run after some amount of intervals. For reference, you can see the Task.cs file in the repository.
 
Now we need to execute these Tasks. For that, we require the Global.asax file. Here, we can write some code to set tasks, then initialize and execute them. For reference, you can check “Global.asax”.
 
Here are a few basic settings on IIS after deployment.
  1. IIS Manager -> Application pools -> DefaultAppPool->Right Click->Advance Settings
  2. Set Idle Time-out Action to zero. Zero means infinite. Site will never go in idle mode.
  3. Set Regular Time interval(minutes) to Zero under the Recycle section. Zero means infinite. The site will never recycle.
If you are creating a separate site to execute these Tasks, then you may also need to create a time scheduler which will trigger your site daily once in a day (only if your server restarts daily).
 
Since you must initialize all the Tasks, you need to at least call the Applicaton_start function in Global.asax. This is called on the very first request of the site. If your server has been scheduled to restart, then your Tasks will not continue to execute.
 
Follow the below steps to set the Time scheduler.
  1. Open Task Scheduler in Window.
  2. Click on "Create basic task".
  3. Give a name to your task and click on the "Next" button.
  4. Select when do you want the task to start and click "Next" and select "Daily". Daily because we want to task to run daily. There are several options for you to schedule your task.
  5. Select the date and time. This Date and time are set to the initial start. Keep uncheck “Synchronize across time zones”. Set the "Recur every day" field to "1", as we want to run this task every day.
  6. In next step, select "Start a program" then click on "Next".
  7. The next step is to choose the browser’s .exe file. It could be IE, Chrome or could be any other browser.
  8. Input your URL which you want to render in this task in the "Add arguments" field and click "Next"
  9. Click on "Finish".
After setting the up the task we can check whether it is working fine or not by right click on it and select “Run”.
 
Suggestions
 
Try to keep a log of every execution of the task and sync process. This way, it will be easier for you to track an error if one occurs.