Apr 12, 2022 10:39 AM
Community - hope you can help. I'm working on a complex workflow that uses at least one custom coded workflow step. The issue I'm running into is that I need to search/filter/sort custom objects (rather than contacts/companies etc) in the coded workflow step and I don't understand how to use the Javascript APIs to access these objects.
Is there a document I've failed to find or a code example/snippet somewhere that can help?
Regards
Solved! Go to Solution.
May 24, 2022 4:56 PM
Hey there @SteveHTM,
There are a few ways to make API calls related to custom objects. The most important part of this is identifying what's called the objectTypeId of the custom object. The easiest way to identify this id in the CRM is by going to the index page of the custom object you're looking to query, and take a look at the url.
I've attached a screenshot of an example. Note the part highlighted at the top. The object type id will always be in this portion of the url on the index page of the custom object. It will always be in the format "2-" followed by...I think it's 6 or 7 digits.
Another option would be to retrieve all schemas in the portal and find the ID based on the label of the custom object, or the schema name - "Hospital" for example, if we were looking at the object in the screenshot. This, in most cases, won't be necessary. See the "Get all schemas" endpoint in the docs HERE.
You won't be able to use the hubspot api client in the same fashion as you would if you were querying the standard objects, which would allow you to use simple dot notation to access the appropriate endpoints.
Below is an example search api request using a custom object
let courseSearchObj = {
filterGroups: [
{
filters: [
{
value: `${enrollmentInfo.course_id}`,
propertyName: "thinkific_course_id",
operator: "EQ"
}
]
}
],
properties: ["id", "thinkific_course_id", "name"],
limit: 1,
after: 0
};
let courseSearchRes = await hubspotClient.apiRequest({
method: "POST",
path: `/crm/v3/objects/2-1877015/search`,
headers: {
accept: "application/json",
"content-type": "application/json"
},
body: courseSearchObj
});
The docs linked earlier on in this post will give more details on searching via API when working with custom objects. Make sure to navigate to the "Objects" tab.
Hopefully this helps.
May 24, 2022 4:56 PM
Hey there @SteveHTM,
There are a few ways to make API calls related to custom objects. The most important part of this is identifying what's called the objectTypeId of the custom object. The easiest way to identify this id in the CRM is by going to the index page of the custom object you're looking to query, and take a look at the url.
I've attached a screenshot of an example. Note the part highlighted at the top. The object type id will always be in this portion of the url on the index page of the custom object. It will always be in the format "2-" followed by...I think it's 6 or 7 digits.
Another option would be to retrieve all schemas in the portal and find the ID based on the label of the custom object, or the schema name - "Hospital" for example, if we were looking at the object in the screenshot. This, in most cases, won't be necessary. See the "Get all schemas" endpoint in the docs HERE.
You won't be able to use the hubspot api client in the same fashion as you would if you were querying the standard objects, which would allow you to use simple dot notation to access the appropriate endpoints.
Below is an example search api request using a custom object
let courseSearchObj = {
filterGroups: [
{
filters: [
{
value: `${enrollmentInfo.course_id}`,
propertyName: "thinkific_course_id",
operator: "EQ"
}
]
}
],
properties: ["id", "thinkific_course_id", "name"],
limit: 1,
after: 0
};
let courseSearchRes = await hubspotClient.apiRequest({
method: "POST",
path: `/crm/v3/objects/2-1877015/search`,
headers: {
accept: "application/json",
"content-type": "application/json"
},
body: courseSearchObj
});
The docs linked earlier on in this post will give more details on searching via API when working with custom objects. Make sure to navigate to the "Objects" tab.
Hopefully this helps.
May 25, 2022 3:56 PM
Thank you @nikodev - this is helpful material that really should be added to the API documentation.
Steve
Apr 13, 2022 5:45 PM
Hello @SteveHTM , I would like to invite our top experts to share their ideas @LMartinez7 @bryce-corey any recommendations to @SteveHTM matter?
Thank you,
Pam
![]() | Você sabia que a Comunidade está disponível em outros idiomas? Participe de conversas regionais, alterando suas configurações de idioma ! Did you know that the Community is available in other languages? Join regional conversations by changing your language settings ! |