Blog about tips & tricks for CMS enhancement

eric.petersson

Getting started with using Lime CRM Rest API


Are you about to get started with using a customer's Lime CRM Rest API as part of an integration? Or perhaps really don't know how to approach the API? Then this blog post is for you - let's get started!

What is Lime CRM?

Lime is one of those Customer Relationship Management systems whom corporations are using for handling customer data in a separated system. Some part of the system typically involves maintenance of invoices, customer relationships but also custom business logic added for supplying the needs of a business. This part is the core of Lime CRM - the custom business implementations.

How you get started - for customer

When purchasing the usage of Lime CRM, a consultant from Lime will be setting up and integrating the system in need. When that is done, an experimental environment is quite often setup to try out the various functions. This is typically how the environment looks like (Lime CRM Windows Application):

The Lime CRM system overview for customers

Here you customer will take part of the data sent from applications and handle the customer relationships. In the middle of the top navigation you see the different Limetypes, the custom business sections of the Lime CRM system.

How you get started - for developer

Lime brings certain developer guidelines when implementing the integrations. These are available throughout web applications served at http and looks something like this:

Developer guidelines for developing with Lime CRM Rest API

Here you will find most things documented for your customer by Lime's consultants. Typically you may try various attempts of calling the different types of operation requests directly in the system, like below:

View of some configured API calls in Lime CRM Rest API developer documentation.
Direct implementation for trying out Rest API calls in the developer documentation.

If the built in "try out calls system" in the developer Lime API documentation is nothing for you, you may find Postman or Swagger as good examples for fiddling with the calls.

Implementation example in C# ASP.NET

The code snippets below is an example with RestSharp how you may call the Lime Rest API for Get and Post for one of the Limetypes configured.

Request-Url: https://limeslimeapiurl/v1/object/yourlimetype/
Type: GET

        private string ResponseBody(string feed)
        {
            // string feed is in this case the request url
            try
            {
                // Ignore insecure calls, for now 
                ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate
                {
                    return true;
                });

                var client = new RestClient(feed);
                var request = new RestRequest(Method.GET);

                request.AddHeader(HttpRequestHeader.Accept.ToString(), "application/hal+json");
                request.AddHeader("cache-control", "no-cache");
                request.AddHeader("x-api-key", "your-lime-api-key-here");

                IRestResponse response = client.Execute(request);

                if (response.IsSuccessful)
                {
                    return _jsonContent = response.Content;
                }

                _log.Error($"There was a problem with retrieving Lime CRM content for {response.Content}. " +
                    $"The following status code was retieved {response.StatusCode}");
            }
            catch (Exception ex)
            {
                _log.Error($"Could not retrieve json feed from Lundalogik Lime CRM API", ex);
            }

            return string.Empty;
        }

Similar example, but with Post instead:

Request-Url: https://limeslimeapiurl/v1/object/yourlimetype/
Type: POST

private string RequestBody(string feed, string json)
        {
            // string feed is in this case the request url
            try
            {
                // Ignore insecure calls, for now
                ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate
                {
                    return true;
                });

                var client = new RestClient(feed);
                var request = new RestRequest(Method.POST);

                request.AddParameter("application/json; charset=utf-8", json, ParameterType.RequestBody);
                request.AddHeader("x-api-key", "your-lime-api-key-here");
                request.RequestFormat = DataFormat.Json;

                IRestResponse response = client.Execute(request);

                if (response.IsSuccessful)
                {
                    return _jsonContent = response.Content;
                }

                _log.Error($"There was a problem with posting into Lime CRM content. " +
                    $"The following status code was retrieved {response.StatusCode}. " + 
                    $"The following content was retrieved: {response.Content}. ");
            }
            catch (Exception ex)
            {
                _log.Error("Unable to post json request body into Lundalogik Lime CRM.", ex);
            }

            return string.Empty;
        }

In this blog today we looked at Lime CRM, what it is, what to expect when configuring and a look for a developer's perspective how to implement a Get and Post type example.