Web RESTful service API calls in Citect?

Is it possible in Citect to make RESTful API calls? For example a PUT command with a JSON payload?

  • We have connected Citect to Archibus CAFM using SOAP web services. But this was done using an external .NET class library whose functions were called using Cicode .NET functions. It should be possible to interact with REST services also with some tweaks.
  • Thanks! I'll have a look, I saw your topic with a link to the setup guide.
    Also, sorry for slow reply, this forum sends me emails for new topics, but not for replies to my own topics..
  • Hello I read your doc about web services in Citect. Very helpful. But I didn't found the C# source code. Can you share it?
    My goal is to use REST to implement some missing automation in Insight.
    I did my C# class with basic authentication that works with other REST web services, but not connecting the endpoint of insight. I'm struggling with the error: "The underlying connection is closed. An unexpected error occurred on a send" that appears every time I call the GET Method. Any Ideas ?
    Thank you.
  • Not sure about the error, it could be related to TLS.
    Send me your email address so I can share the test project with you.
  • Hello Balaji,

    We are doing some work in Australia on REST programming in Citect 7.5 and would also benefit greatly from your work done on this. If you could share your Citect project with source code for the libraries that would be awesome. My email is Matthew.wood@acectrl.com

    thankyou greatly.

    matthew wood 

  • Hey Matt, 

    Check your email, I've reached out to you.

    Cheers

  • Could please send me an example project? aleksejka8686@gmail.com I would like to get an electricity price to my Citect project from API.

  • Hello, could you also please provide source code, I am trying to do the exact same thing: jason.sanders.email@gmail.com

  • This message is a couple of years old, but I'm kind of in this situation too.  I'd like to be able to do some POSTs with JSON.  I was trying to figure out a way to do it without a custom .NET library and didn't really come up with one.  There are two problems: one is the HTTP connection itself (which could be https), the second is the JSON serialization.  On the HTTP/HTTPS side there may also be headers involved.  Neither of those things seems really practical in the CiCode world.

    The problem I'm having with calling external .NET DLLs is that it seems a little brittle.  I ran some experiments and I had to build exactly for .NET 4.8 and x86 for it to work.  I will show you what I did below.  Like I said, I think it's brittle.  I feel like it's safer to come in the other direction using the API and have an external application.

    This whole mechanism could really stand to have a lot of improvement.  The other thing I really want to do is to be able to publish things via MQTT.  Can't really find a great way to do that yet either.

    using System.Net;
    using System.Net.Http;
    using System.Text;
    using System.Threading.Tasks;
    using System.Runtime.Serialization.Json;
    using System.IO;

    namespace Squadcast
    {
        public class Incident {
            public string message { get; set; }
            public string description { get; set; }
            public string status { get; set; }
        }

        public class SquadcastClient {
                public string test2() {
                    return "eat me";
                }

                public string test() {
                    var incident = new Incident { message = "This is a test incident", description="This is a test incident generated from .NET", status="triggered" };


                    MemoryStream ms = new MemoryStream();
                    new DataContractJsonSerializer(typeof(Incident)).WriteObject(ms, incident);
                    var text = Encoding.Default.GetString(ms.ToArray());

                    var body = new StringContent(
                            text,
                            Encoding.UTF8,
                            "application/json");

                    var request = new HttpRequestMessage(HttpMethod.Post,
                                            "">api.squadcast.com/.../xxxxxxxxxxxxxx");

                    request.Content = body;

                    var client = new HttpClient();
                    var task = client.SendAsync(request);

                    var waiter = task.GetAwaiter();

                    task.Wait();

                    var response = task.GetAwaiter().GetResult();

                    return "response " + response.StatusCode.ToString()

                    }
        }
    }