Learn how to use GraphQL to query your HubSpot data
CRM
as a root query field, then enter a data type as a child field. You can include any of the following data types from the CRM:
IN
and NOT_IN
operators. Learn more about filtering with the CRM Search API._collection
to retrieve a list of objects of that type. You can provide arguments to a query field to fetch a single object or filter a collection of objects.
uniqueIdentifier
, and the property’s value as the uniqueIdentifierValue
. For example, the following query would fetch a contact with an ID of 753:items
as a child field. To filter the objects in the response, include the filter
argument, then provide a map of filter operators to their associated values. A filter operator consists of the property you want to filter by, followed by a suffix. For example, the query below would fetch and filter a collection of contacts with hubspot.com email addresses:__in
operator to filter on a multiple checkbox property, the data in the response will include instances that partially match one or more of the values in your filter argument.For example, if your query field was contact_collection(filter: {hs_buying_role__in: ["END_USER", "INFLUENCER"]})
, then the response would include contacts who had End User selected as one of their buying roles, but didn’t necessarily have Influencer as one of their buying roles.associations
as a child field of the original data type you entered.associations
, enter the association you want to include by following the naming scheme of {ASSOCIATED_DATA_TYPE}_collection__{LABEL_SUFFIX}
.
p_
.primary
. If you created a custom association label, the label suffix will be lower-cased, with each word in the label separated by an underscore. For example, if your custom association label is My custom association label, the label suffix would be my_custom_association_label
.items
as a child field of your association, then include any properties you need from each item in the collection._collection
query or a query that gets a single CRM object by a unique property other than id
uses HubSpot’s search API, and is therefore subject to the CRM search limits outlined here.HUBDB
as a root query field, then enter the name of a table to retrieve a single row from that table, or enter a name followed by _collection
to retrieve multiple rows from that table.
uniqueIdentifier
then provide the associated value of the row you want to retrieve as the uniqueIdentifierValue
. For example, the following query would retrieve a row from an executives table with a role of CEO:uniqueIdentifier
has non-unique values, your query will only return the first row, ordered by row ID.associations
as a child field of items
.associations
, enter the name of the foreign table with the _collection
suffix, followed by two underscores and the name of the foreign ID column. For example, if the foreign ID column is recent_posts, and the name of the foreign table you want to reference is blog_posts, then the resulting field to include in your query would be blog_posts_collection__recent_posts
.items
as a child field of the foreign table field you just entered, then include any columns you need from the foreign table. For example, to include additional columns from the executives table from the csuiteExecutives query above, along with the title and link from a blog_posts foreign table, you’d update the query to the following:hs_
.hs_child_table_collection
as a child field of the items
of the parent table collection....
) combined with a type condition, which includes the on
keyword and the name of the child table collection. For example, if you wanted to update the csuiteExecutives
query from above to include columns from the team
and recent_posts
child tables:{draft: true}
as a query argument to the name of the table that you’re retrieving. If you’ve added new columns since you last published the table, they will not be included.
BLOG
as a root query field, then enter a data type as a child field. You can include any of the following data types:
uniqueIdentifier
.uniqueIdentifier
.draft: true
.KB
as a root query field, then enter a data type as a child field. You can include any of the following data types:
uniqueIdentifier
.Argument | Type | Description |
---|---|---|
filter | Input type | A set of filter options to apply on the collection items |
limit | Integer | The maximum number of items to fetch. If your query’s data source is the CRM , the default limit is 10 items, and the maximum limit is 500.If you’re using HUBDB as a data source, the default limit is 1000 rows, with no maximum limit.If you’re using BLOG as a data source, the default limit for blog posts and tags is 20, while the default limit for authors is 1000. The maximum limit for blog posts is 300. There is no maximum limit for fetching blog authors or tags. |
orderBy | Enum array | The ordering to apply on the fetched items. The default ordering is ascending by the item’s id . |
offset | Integer | The index from where to start fetching items. The default is 0. When paginating results, you should include the offset field as a query argument, as well as including it in the fields of your query. |
email__contains
or name__eq
). The supported operators are shown in the table below:
Filter | Postfix | Field types | Example |
---|---|---|---|
equal | __eq | String, Number, Date, DateTime | email__eq: “user@domain.com” |
not equal | __neq | String, Number, Date, DateTime | firstname__neq: “Bob” |
less than | __lt | Number, DateTime | price__lt: 45 |
less than or equal | __lte | Number, DateTime | started__lte: 1633606374 |
greater than | __gt | Number, DateTime | salary__gt: 60000 |
greater than or equal | __gte | Number, DateTime | birthdate__gte: 1633606374 |
contains | __contains | String | name__contains: “Inc.” |
does not contain | __not_contains | String | address_not_contains: “Miami” |
in given list | __in | Enumeration, Number | hs_buying_role__in: [“END_USER”, "INFLUENCER"] |
not in given list | __not_in | Enumeration, Number | status__not_in: [“REJECTED”, "PENDING"] |
has value / does not have value | __null | Any type | email__null: false |
limit
field isn’t included in your query, the maximum number of items returned in the results will be 10. You can increase this limit by providing the limit
query argument within the parantheses following the collection name of your query, subject to the data source maximums described in the table above.
You can also provide the offset
query argument within the parantheses of your query collection name, which specifies the index from which to start fetching items.
For example, the following query would start fetching results from an index of 10 and continue until the query’s limit of 30 is reached:
offset
, limit
, and total
fields within the query itself, these values will be returned in the results, which can help you make any additional queries for any remaining data.
{}
), and the filters within the resulting group will be AND
ed together.
OR
operator, followed by a list of comma-separated filter groups within square brackets (e.g., []
).
For example, if you want to filter a list of Job custom objects to include records with a status of either “full-time” OR “contract”, then the resulting filter would be:
OR
together must be specified as a separate filter group, even if the filter name is the same (i.e., status__eq
in the example above).
The same format would apply if you want to OR
together different filter types. For example, if you want to filter job records to include jobs with a “full-time” status OR jobs in the department “engineering”, then the resulting query would be:
AND
logic of filters within a filter group with the OR logic between different filter groups to create more complex filters.
For example, if you wanted to represent the following logical expression as a GraphQL filter:
status="full-time" AND ((department="engineering" AND salary >= 80000) OR (department="sales" AND salary>=100000))
The resulting filter argument in your query would be:
OR
operator appears as a checkbox in the Explorer side panel of GraphiQL, selecting the checkbox will cause your query to be invalid due to the way GraphiQL autocompletes the query argument. You should instead follow the steps above to structure your query’s filtering logic manually.OR
operator is not supported when querying for HubDB data.limit
field in the Query argument types table above.
contact_collection
:
company_collection__primary
:
ticket_collection__primary
:
429 Too Many Requests
. The only exception is that templates and modules with GraphQL queries loaded by site visitors will continue to function to preserve website user experience. All other ad-hoc uses of the endpoint will no longer function (e.g., during template/module development, using the GraphiQL UI, and UI extensions using GraphQL queries). Accumulated points from the previous minute are not carried over to the next.extensions
field.
query_complexity
field.rate_limit_info
./collector/graphql
endpoint, the following scopes are required:
crm.objects.contacts.read
scope is required if you’re fetching contacts in your query.
POST
request to the /collector/graphql
endpoint and include the following fields:
Parameter | Type | Description |
---|---|---|
operationName | String | A label for the query included in the request |
query | String | The GraphQL query to execute |
variables | JSON object | A JSON object containing any variables you want to pass to the query |