Last Updated:
November 7, 2022
by
Kathy Ziomek
| Version: 6
| 4,385 views
| 0 followers
members are following updates on this item.
Note: This article is an introduction to using the Igloo API. Returning and frequent developers should head over to the API Reference.
The Igloo API allows developers to perform I/O functions directly with the platform. For a list of currently available API endpoints, please skip ahead to the Igloo API Reference. If you are enrolled in Igloo Developer Support, a flat-file can be provided to you directly that has more information available than our public documentation.
Every object on the Igloo platform is represented and accessible by a 128-bit integer number (GUID) that is used to identify resources. This specification is based upon RFC 4122 and the primary way to interact with our API (More information on RFC 4122). The ID of your Igloo object is passed in every GET and POST request and could be anything- a blog post, file, the active user, or a page itself. To understand it clearly, consider that every unique object on the Igloo platform has an ID, and every unique object is accessible by its own URI/URL (Information about the difference between URI and URL).
The easiest way for a developer to obtain the ID that they are looking for is to run this JavaScript code in the console of any web browser after going to the URL of the object they need the ID for:
(() => {
var eip = document.getElementsByClassName('eip')[0].id,
guid = eip.substring(eip.length - 36);
return guid;
})();
(Fig. 2.1) This function will return the ID you need.
In the front-end of the web browser, we have a JavaScript language binding that utilizes the axios framework (GitHub page for the axios framework). API calls may be made using it from anywhere inside your Igloo like this:
/**
* @description axios - https://github.com/axios/axios
*/
var config = {
headers: {
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded'
}
};
axios.post('/.api/api.svc/createWiki/00000000-0000-0000-0000-000000000000/add', {
title: 'Jabberwocky',
content: 'Twas brillig, and the slithy toves did gyre and gimble in the wabe: All mimsy were the borogoves, and the mome raths outgrabe.'
}, config);
(Fig. 3.1) Basic usage of the native Igloo API client.
Tip: You may choose not to use the native API client, and there is no reason why you need to use it. It is there for convenience and ultimately developers should utilize whatever AJAX framework is most compatible with their solution.
Warning: Axios depends on a native ES6 Promise implementation to be supported. If your environment doesn’t support ES6 Promises, you can polyfill using this subset of rsvp.js
The most basic way in Ajax programming to access and utilize the Igloo API is to use XMLHttpRequest (MDN article on XMLHttpRequest):
var guid = '{guid}'; // 128-bit Integer ID value
var params = 'title=SOPs&content=This document outlines department specific SOPs...';
var request = new XMLHttpRequest();
request.addEventListener("load", reqListener);
request.open("GET", "https://mycommunity.igloocommunities.com/.api/api.svc/wikiarticles/" + guid + "/create");
request.setRequestHeader("Content-Type", "x-www-form-urlencoded");
request.send(params);
function reqListener() {
console.log(this.responseText);
}
(Fig. 4.1) Using XmlHttpRequest to work with the Igloo API.
jQuery is available on the Igloo platform as well, to make API calls using jQuery.ajax() (API documentation for jQuery.ajax() )
Note: The $ is bound to mooTools on the Igloo platform, therefore to call jQuery use ‘jQuery’ in one-off scenarios, or wrap your JavaScript code in an IIFE that binds the $ to jQuery.
var formData = {
title: 'SOPs',
content: "This document outlines department specific SOPs..."
};
jQuery.ajax({
url: 'https://mycommunity.igloocommunities.com/.api/api.svc/wikiarticles/{guid}/create',
type: 'POST',
data: formData,
dataType: 'json',
success: function (data, response, xhr) {
var result = jQuery.parseJSON(response);
console.log(result);
},
error: function (xhr, response, error) {
console.log(error);
}
});
(Fig. 5.1) Using jQuery to access the Igloo API.
The full list of available Igloo API endpoints are listed in the Igloo API Reference, which includes ready-executable code examples.