Published
on
June 28, 2019
| 1,900 views
| 7 followers
members are following updates on this item.
In a previous post, (Querying objects by their URL path) we discussed how we can get objects by path before and why that would be of use in certain situations.
You can also get objects by ID and in some cases that’s what you want to do.
You will need to get the object ID either by querying the object by path using the API, or by inspecting the DOM on the object in question.
Getting started is just as easy as when we showed you how to get started with getting objects by path. This time, we will be passing the id in the path of the GET request and not as a query parameter. You can use the /.api/api.svc/objects/byPath?path=/my/path to get the object id for this example.
We will be using NodeJS again in this example:
axios.get(`https://my.domain/.api/api.svc/objects/{id}/view`).then((response) => {
const result = response.data.response;
console.log(result);
}).catch((err) => {
console.log(err);
})
}
Using the /.api/api.svc/objects/{objectId}/view endpoint returns contextual data about the object that with that id. 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', .... }
Look familiar? It’s exactly the same as the response we got back from using the /.api/api.svc/objects/byPath endpoint. That’s because it is. Having more than one option to querying objects allows developers to be more flexible in certain instances where one might not be able to use the path.
Now you may be wondering, if I can get object by path why do I care about the ID? Sure you could use the path to get the object information, but what if there is no path in the response? You will see this happen from time to time - not all objects in Igloo have a path you can navigate to. This is where using the ID becomes advantageous over the path.