3

I'm integrating an Asp.NET application with Acumatica that needs to update shipping information (tracking #, carrier, etc.) when it becomes available in Acumatica. Is there a way to have Acumatica call an endpoint on my Asp.NET app when a shipment is created? I've searched through a lot of the docs (available here), but I haven't come across anything to send OUT information from Acumatica to another web service.

Ideally, this outgoing call would send the shipment object in the payload.

big_water
  • 3,024
  • 2
  • 26
  • 44

3 Answers3

2

This wasn't available when you asked the question but push notifications seem to be exactly what you're looking for:

Help - https://help.acumatica.com/(W(9))/Main?ScreenId=ShowWiki&pageid=d8d2835f-5450-4b83-852e-dbadd76a5af8

Presentation - https://adn.acumatica.com/content/uploads/2018/05/Push-Notifications.pdf

bbrown
  • 6,370
  • 5
  • 37
  • 43
1

In my answer I suppose that you know how to call some outside service from C# code, and for your is a challenge how to send notification from Acumatica. I propose you to extend each Persist method in each Acumatica graph, from which you expect to send notification when object is persisted in db. IMHO the best option for this is to override method persist ( btw, it overriding persist method is well described in T300 ). In code of extension class you can do the following:

public void Persist(PersistDelegate baseMethod) 
{ 
   baseMethod(); // calling this method will preserve your changes in db

   //here should go your code, that will send push/pop/delete etc web request into your asp.net application. Or in other words your web hook.
  }
Yuriy Zaletskyy
  • 4,983
  • 5
  • 34
  • 54
  • Do you know where I can find the course documentation on how to modify the Acumatica graphs? Also, can I get the object being persisted to send with the web request? – big_water Feb 20 '17 at 16:06
  • You already mentioned link in your question. I recommend you to see first few chapters of T100 course, and then in T300 course in pdf you'll see how to extend class library – Yuriy Zaletskyy Feb 20 '17 at 16:09
  • at following link you can see more details: http://blog.zaletskyy.com/how-to-start-with-acumatica-development . In case if you will find my post useful, please mark my answer as accepted plz – Yuriy Zaletskyy Feb 21 '17 at 11:36
  • I didn't get a chance to fully test this, but your blog post was helpful. thank you – big_water Feb 22 '17 at 16:07
0

If you don't have Acumatica 2017R2, then you have to create your own extension project and then you can call it from your Acumatica code:

using System;
using System.Collections.Generic;
using System.IO;
using System.Net;

namespace MyApp
{
    public static class Utility
    {
        private static WebRequest CreateRequest(string url, Dictionary headers)
        {
            if (Uri.IsWellFormedUriString(url, UriKind.Absolute))
            {
                WebRequest req = WebRequest.Create(url);
                if (headers != null)
                {
                    foreach (var header in headers)
                    {
                        if (!WebHeaderCollection.IsRestricted(header.Key))
                        {
                            req.Headers.Add(header.Key, header.Value);
                        }
                    }
                }
                return req;
            }
            else
            {
                throw(new ArgumentException("Invalid URL provided.", "url"));
            }
        }
        public static string MakeRequest(string url, Dictionary headers = null)
        {
            WebResponse resp = CreateRequest(url, headers).GetResponse();
            StreamReader reader = new StreamReader(resp.GetResponseStream());
            string response = reader.ReadToEnd();
            reader.Close();
            resp.Close();
            return response;
        }
        public static byte[] MakeRequestInBytes(string url, Dictionary headers = null)
        {
            byte[] rb = null;
            WebResponse resp = CreateRequest(url, headers).GetResponse();
            using (BinaryReader br = new BinaryReader(resp.GetResponseStream()))
            {
                rb = br.ReadBytes((int)resp.ContentLength);
                br.Close();
            }
            resp.Close();
            return rb;
        }
    }
}

You can then call it like this:

try
{
  Utility.MakeRequest(theUrl, anyHeadersYouNeed);
}
catch(System.Net.WebException ex)
{
  throw(new PXException("There was an error.", ex));
}
bbrown
  • 6,370
  • 5
  • 37
  • 43