Skip to content

Instantly share code, notes, and snippets.

@yuriycto
Created December 9, 2021 14:40
Show Gist options
  • Save yuriycto/059395e4abc43d42078d8237093d416b to your computer and use it in GitHub Desktop.
Save yuriycto/059395e4abc43d42078d8237093d416b to your computer and use it in GitHub Desktop.
Processing incoming request from Outside world
using Newtonsoft.Json;
using PX.Data;
using PX.Data.Webhooks;
using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Http.Results;
namespace WebHooksConfiguration
{
class ObjectJSON
{
string Name { get; set; }
}
public class TestWebHooks : IWebhookHandler
{
public async Task<System.Web.Http.IHttpActionResult> ProcessRequestAsync(
HttpRequestMessage request, CancellationToken cancellationToken)
{
using (var scope = GetAdminScope())
{
if (request.Method == HttpMethod.Post)
{
string jsonContent = request.Content.ReadAsStringAsync().Result;
ObjectJSON obj = JsonConvert.DeserializeObject<ObjectJSON>(jsonContent);
}
}
return new OkResult(request);
}
private IDisposable GetAdminScope()
{
var userName = "admin";
if (PXDatabase.Companies.Length > 0)
{
var company = PXAccess.GetCompanyName();
if (string.IsNullOrEmpty(company))
{
company = PXDatabase.Companies[0];
}
userName = userName + "@" + company;
}
return new PXLoginScope(userName);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment