Published
on
April 29, 2019
| 2,715 views
| 0 followers
members are following updates on this item.
It can be cumbersome inspecting the DOM to get an object’s ID. Luckily we can use an object’s URL path to query objects for their information. Using the /.api/api.svc/objects/byPath?path=/my/path
endpoint you can get object data from Igloo without the need for an object ID.
Getting started is straight forward enough. Find the URL path of the object you want to query and pass it as a query parameter in your GET request. You don't need the entire URL path, only everything after the domain (e.g.https://my.domain.com/this/is/what/we/want). Once you have your path, you are ready to move on to the next step.
For the purposes of this example I will be using Nodejs to make the API call.
/**
* Get object data by the path to that object
*
* @param {string} path Path to the object in IGLOO
* @returns {Object} API Response with object data
*/
getObjectByPath(path) {
client.get(`https://my.domain/.api/api.svc/objects/byPath?path=${path}`).then((response) => {
console.log(response.data.response); // We just want to log the data to the console to illustrate the point
}).catch((err) => {
console.log(err);
});
}
Using the /.api/api.svc/objects/byPath?path=/my/path
endpoint returns contextual data about the object that has that URL. Here is what the abbreviated response looks like:
{
....
id: '41bb7a8e-3e08-4f6f-90d3-0fc2aece486a',
href: '/my/path',
navType: 1,
IsArchived: false,
IsScheduledForArchiving: false,
SpaceId: null,
commentprivileges: '1',
title: 'My path object',
name: '{41bb7a8e-3e08-4f6f-90d3-0fc2aece486a}',
content: 'content of my path!',
description: 'no description here',
....
}
The response object provides a lot of information, so I encourage you to inspect the rest of the data returned from the API call. You may have noticed that the response includes the ID of the object as well. That's the beauty of this endpoint, you can use it to grab the ID should it be needed for other API calls, or you can use it just to view basic data about the object(who created it, the title, content, description, etc.).
Getting objects by their URL path is very convenient, especially when you don't know what the ID of the object is. This allows for a more fluid development experience, however, there are use cases where having the ID is required and or more convenient. These cases will be explored further in a separate blog post.