<aside> 📌 These instructions helps you set up your API:s to Copyl Integration Platform, so that the API reports Trigger Events to Copyl.
</aside>
Make sure you have included Nuget Package CopylHelper
version 8.2.7+
Add information needed in the appsettings.json
file
"AppSettings": {
"ServiceId": "",
"AppId": "",
"AppName": "",
"ApiKey": "",
"EnterpriseId": "",
"OcpApimSubscriptionKey": "",
...
}
Create a helper function that will shorten the implementation code and make it easy to change IPaaS:
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using System;
using System.Threading.Tasks;
namespace CopylAPI_Users.Helpers
{
public static class CopylIntegrationPlatformHelper
{
public static async Task SendEventToCIPAsync(IConfiguration configuration, dynamic _obj, string triggerName)
{
// Post to Copyl Integration Platform
try
{
CopylHelper.Entities.IntegrationAppTriggerEventDTO _triggerEvent = new();
_triggerEvent.SysCode = configuration["AppSettings:AppName"] + "." + triggerName;
_triggerEvent.EnterpriseId = new Guid(configuration["AppSettings:EnterpriseId"]);
_triggerEvent.ApiKey = new Guid(configuration["AppSettings:ApiKey"]);
_triggerEvent.Data = JsonConvert.SerializeObject(_obj, new Newtonsoft.Json.Converters.ExpandoObjectConverter());
_ = await CopylHelper.Trigger.PublishTriggerToCopylAsync(_triggerEvent, configuration["AppSettings:OcpApimSubscriptionKey"]);
}
catch (Exception exception)
{
throw new Exception("Unhandled exception when posting trigger to Copyl app: 'Copyl Users API'. " + triggerName, exception);
}
// END Post Trigger to Copyl Integration Platform
}
}
}
Make an instance of IConfiguration
in the controller.
We are doing this in the _baseController
:
public abstract class BaseController : ControllerBase
{
protected readonly CopylContext _context;
protected readonly ILogger _logger;
protected readonly IHttpClientFactory _httpClientFactory;
protected readonly IDistributedCache _cache;
protected readonly IHubContext<UserHub> _hubContext;
protected readonly IConfiguration _configuration;
protected readonly IServiceProvider _serviceProvider;
protected BaseController(
CopylContext context,
ILogger logger,
IHttpClientFactory httpClientFactory,
IDistributedCache cache,
IHubContext<UserHub> hubContext,
IConfiguration configuration,
IServiceProvider serviceProvider)
{
_context = context;
_logger = logger;
_httpClientFactory = httpClientFactory;
_cache = cache;
_hubContext = hubContext;
_configuration = configuration;
_serviceProvider = serviceProvider;
}
Add integration trigger events in: POST
, PUT
and DELETE
await CopylIntegrationPlatformHelper.SendEventToCIPAsync(_configuration, ***YOUR_OBJECT***, MethodBase.GetCurrentMethod().Name);
<aside>
⚠️ Note: when an async method is called, the MethodBase.GetCurrentMethod().Name
will be “MoveNext
”. Hard-code the name of the procedure if that’s the case.
</aside>