HubSpot
Pending HubSpot review. HubSpot is still reviewing Houston's app. Until HubSpot lists it, you will see an unverified app warning while connecting: select Connect app, type I accept the risk, then select Connect.
HubSpot
Find and read your HubSpot contacts, companies, deals and tickets, see how they are linked to each other, and follow their notes, tasks, calls, meetings and logged emails. Agents can also look up deal and ticket pipelines and their stages, the account's owners, and the properties each kind of record has.
Choose None, Read or Write separately for Contacts, Companies, Deals, Tickets and Activities (notes, tasks, calls, meetings and logged emails); each starts at Read. Write adds creating and updating those records, linking and unlinking them, and moving deals and tickets between stages. Owners are always readable.
The connection sees the whole HubSpot account, not only the records of the person who connected it. HubSpot's permissions for the connected app or key still apply.
Connect by signing in with HubSpot, or with an access token. Deleting records, bulk imports, custom objects, marketing tools and files are not available, and HubSpot's request limits apply.
Setup instructions
Setup instructions
Connect HubSpot
- Choose None, Read or Write for Contacts, Companies, Deals, Tickets and Activities, and select Authorize connection.
- In HubSpot, choose the account to connect, review the permissions Houston asks for and select Connect app.
Connecting installs Houston's app in the HubSpot account, which needs a Super Admin or a user with the HubSpot Marketplace access permission. Raising a level asks HubSpot for the extra permissions again.
HubSpot has no separate permissions for activities (notes, tasks, calls, meetings and logged emails), so Houston enforces the Activities level.
Advanced
Service key
Choose Service key or private app access token in Houston. A Super Admin or a user with the Developer tools access permission can create a service key in HubSpot:
- Go to Development, then Keys > Service keys, and select Create service key.
- Enter a name, select Add new scope, tick the scopes below and select Update.
- Select Create and confirm.
- Open the key, select Show, then Copy, and paste it in Houston as Access token.
Scopes to tick:
| Access | Read | Write |
|---|---|---|
| Always | crm.objects.owners.read, sales-email-read |
|
| Contacts | crm.objects.contacts.read, crm.schemas.contacts.read |
also crm.objects.contacts.write |
| Companies | crm.objects.companies.read, crm.schemas.companies.read |
also crm.objects.companies.write |
| Deals | crm.objects.deals.read, crm.schemas.deals.read |
also crm.objects.deals.write |
| Tickets | crm.objects.tickets.read, crm.schemas.tickets.read |
also crm.objects.tickets.write |
Houston still enforces each level you choose when the key allows more.
Existing private app
HubSpot stopped creating legacy private apps on October 26, 2026, but existing ones
keep working. In HubSpot, go to Development > Legacy apps, open the app, then on
the Auth tab select Show token and Copy. Paste it in Houston as Access
token. An older app may hold the tickets scope instead of the crm.objects.tickets
scopes; it covers tickets too.
Missing data or permission errors
- If agents report a missing scope, add it to the service key or private app (select Edit on the key), or connect again with HubSpot.
- A rotated, expired or deleted key stops working: paste the new key in the connection.
- To revoke Houston's access, uninstall Houston from the account's Connected Apps in HubSpot, or delete the key, then remove the connection in Houston.
- HubSpot limits how many requests an app or key may make every 10 seconds, and service keys and private apps also share a daily quota for the account; busy accounts can briefly reach these limits.
Files
Files
connector.luau
-- HubSpot CRM API 2026-09 (date-based version; HubSpot stops supporting it around March 2028). -- Arguments and results keep HubSpot's native field names. type Options = {[string]: any} local API = "https://api.hubapi.com" local VERSION = "2026-09" local ACTIVITY_TYPES = {"notes", "tasks", "calls", "meetings", "emails"} -- The object types this connection's access allows at level, in the order given. Activities share -- the engagements row; every other type has its own. local function allowedTypes(types: {string}, level: string): {string} local allowed: {string} = {} for _, kind in types do local row = if table.find(ACTIVITY_TYPES, kind) then "engagements" else kind if houston.allows(row .. ":" .. level) then table.insert(allowed, kind) end end return allowed end local OBJECT_TYPES = {"contacts", "companies", "deals", "tickets", "notes", "tasks", "calls", "meetings", "emails"} local READABLE = allowedTypes(OBJECT_TYPES, "read") local WRITABLE = allowedTypes(OBJECT_TYPES, "write") local PIPELINE_TYPES = {"deals", "tickets"} local PIPELINES = allowedTypes(PIPELINE_TYPES, "read") local CATEGORIES = {"HUBSPOT_DEFINED", "USER_DEFINED", "INTEGRATOR_DEFINED"} local OPERATORS = {"EQ", "NEQ", "LT", "LTE", "GT", "GTE", "BETWEEN", "IN", "NOT_IN", "HAS_PROPERTY", "NOT_HAS_PROPERTY", "CONTAINS_TOKEN", "NOT_CONTAINS_TOKEN"} local DIRECTIONS = {"ASCENDING", "DESCENDING"} -- Property names a query or body may list, and associations or association types one call may send. local MAX_NAMES = 500 local MAX_LINKS = 100 local function options(input: any): Options if input == nil then return {} end assert(type(input) == "table", "options must be an object") for key in input do assert(type(key) == "string", "options must have named fields") end return table.clone(input) end local function take(args: Options, field: string): any local value = args[field] args[field] = nil return value end local function done(name: string, args: Options) local unknown = next(args) assert(unknown == nil, name .. " received an unknown option " .. tostring(unknown)) end local function text(value: any, field: string): string assert(type(value) == "string" and value ~= "", field .. " must be a nonempty string") return value end local function integer(value: any, field: string, min: number, max: number): number assert(type(value) == "number" and value == math.floor(value) and value >= min and value <= max, field .. " must be an integer from " .. tostring(min) .. " to " .. tostring(max)) return value end local function oneOf(value: any, field: string, allowed: {string}): string assert(type(value) == "string" and table.find(allowed, value) ~= nil, field .. " must be one of " .. table.concat(allowed, ", ")) return value end -- Record IDs are strings of digits. With idProperty, an ID is that property's unique value instead, -- such as a contact's email. local function idValue(value: any, field: string, idProperty: boolean?): string if idProperty then return text(value, field) end assert(type(value) == "string" and string.match(value, "^%d+$") ~= nil, field .. " must be a string of digits") return value end -- A record ID in a path, as one encoded segment. local function recordId(value: any, field: string, idProperty: boolean?): string return url.segment(idValue(value, field, idProperty), field) end -- An object type taken from args[field]: one this connection may read, or one of allowed. local function objectType(args: Options, field: string, allowed: {string}?): string return oneOf(take(args, field), field, allowed or READABLE) end -- A record taken from args as path segments: its object type and its record ID. local function record(args: Options, typeField: string, idField: string, allowed: {string}?): (string, string) return objectType(args, typeField, allowed), recordId(take(args, idField), idField) end -- A dense array of 1 to max items, so that it encodes as a JSON array. local function array(value: any, field: string, max: number): {any} local problem = field .. " must be an array of 1 to " .. tostring(max) .. " items" assert(type(value) == "table", problem) local count = 0 for _ in value do count += 1 end assert(count >= 1 and count <= max and count == #value, problem) return value end -- Property names, or object types when allowed is given. HubSpot reads query lists comma-separated. local function names(value: any, field: string, allowed: {string}?): {string} for index, name in array(value, field, MAX_NAMES) do local item = field .. "[" .. tostring(index) .. "]" if allowed then oneOf(name, item, allowed) else assert(type(name) == "string" and string.match(name, "^[^,]+$") ~= nil, item .. " must be a nonempty name without commas") end end return value end -- Moves the named options from args into a query string, in the order given. Lists go -- comma-separated, and archived is sent only when true. local function query(args: Options, fields: {string}, maxLimit: number?): string local parts: {string} = {} for _, field in fields do local value = take(args, field) if value == nil then continue end if field == "archived" then assert(type(value) == "boolean", "archived must be a boolean") if value then table.insert(parts, "archived=true") end elseif field == "limit" then table.insert(parts, "limit=" .. tostring(integer(value, field, 1, maxLimit :: number))) elseif field == "properties" or field == "propertiesWithHistory" or field == "associations" then local items: {string} = {} for _, name in names(value, field, if field == "associations" then READABLE else nil) do table.insert(items, url.encode(name)) end table.insert(parts, field .. "=" .. table.concat(items, ",")) else table.insert(parts, field .. "=" .. url.encode(text(value, field))) end end return if #parts > 0 then "?" .. table.concat(parts, "&") else "" end -- Property values to write: strings, numbers or booleans; an empty string clears a value. local function properties(value: any): Options assert(type(value) == "table" and next(value) ~= nil, "properties must be a nonempty object of property names and values") local copy: Options = {} for name, item in value do assert(type(name) == "string" and name ~= "", "properties must have property names as keys") local field = "properties." .. name assert(type(item) == "string" or type(item) == "boolean" or type(item) == "number", field .. " must be a string, number or boolean") copy[name] = item end return copy end -- An object whose fields are all among the given names. local function closed(value: any, field: string, fields: {string}): Options assert(type(value) == "table", field .. " must be an object") for key in value do assert(table.find(fields, key) ~= nil, field .. " received an unknown field " .. tostring(key)) end return value end -- A search filter: {propertyName, operator, value?, highValue?, values?}, with string values. local function searchFilter(value: any, field: string) closed(value, field, {"propertyName", "operator", "value", "highValue", "values"}) text(value.propertyName, field .. ".propertyName") oneOf(value.operator, field .. ".operator", OPERATORS) for _, key in {"value", "highValue"} do assert(value[key] == nil or type(value[key]) == "string", field .. "." .. key .. " must be a string") end if value.values ~= nil then for index, item in array(value.values, field .. ".values", MAX_NAMES) do assert(type(item) == "string", field .. ".values[" .. tostring(index) .. "] must be a string") end end end -- Association types to set: {{associationCategory, associationTypeId}}, as HubSpot sends them. local function associationTypes(value: any, field: string): {Options} local types: {Options} = {} for index, item in array(value, field, MAX_LINKS) do local path = field .. "[" .. tostring(index) .. "]" closed(item, path, {"associationCategory", "associationTypeId"}) table.insert(types, { associationCategory = oneOf(item.associationCategory, path .. ".associationCategory", CATEGORIES), associationTypeId = integer(item.associationTypeId, path .. ".associationTypeId", 1, 2147483647), }) end return types end -- HubSpot errors are {status, message, correlationId, category, errors = {{message, code, context}}}, -- every field optional; rate limits answer {errorType, policyName}. 429, 423 (a 2-second lock) and -- 477 (a data migration) are transient, except the daily limit: policyName DAILY, or, for access -- tokens (not OAuth), X-HubSpot-RateLimit-Daily-Remaining 0, which decides when the body is -- unreadable. Server errors are retryable only for idempotent calls: a create that failed with one -- may still have been applied. -- Validation errors can list many properties, so up to 16 KiB is read; the message keeps a bounded -- part of each field. local function fail(operation: string, response: HttpResponse, idempotent: boolean): never local ok, decoded = pcall(json.decode, await(response.body:readPrefix(16384))) local problem: Options = if ok and type(decoded) == "table" then decoded else {} local status = response.statusCode local message = "HubSpot HTTP " .. tostring(status) local category = if type(problem.category) == "string" then problem.category else problem.errorType if type(category) == "string" then message ..= " (" .. string.sub(category, 1, 100) .. ")" end if type(problem.message) == "string" then message ..= ": " .. string.sub(problem.message, 1, 600) end local errors = if type(problem.errors) == "table" then problem.errors else {} local scopes: {string} = {} for index = 1, math.min(#errors, 10) do local item = errors[index] if type(item) ~= "table" then continue end if index <= 3 and type(item.message) == "string" then message ..= "; " .. string.sub(item.message, 1, 200) end local required = if type(item.context) == "table" then item.context.requiredGranularScopes else nil if status == 403 and type(required) == "table" then for _, scope in required do if type(scope) == "string" and #scopes < 10 then table.insert(scopes, string.sub(scope, 1, 100)) end end end end if #scopes > 0 then message ..= "; needs one of: " .. table.concat(scopes, ", ") end if status == 429 and type(problem.policyName) == "string" then message ..= "; policy " .. string.sub(problem.policyName, 1, 64) end local remaining = response.headers["x-hubspot-ratelimit-daily-remaining"] local daily = status == 429 and (problem.policyName == "DAILY" or (remaining ~= nil and tonumber(remaining[1]) == 0)) if daily and problem.policyName ~= "DAILY" then message ..= "; daily limit reached" end local retry = response.headers["retry-after"] if retry and retry[1] then message ..= "; Retry-After: " .. string.sub(retry[1], 1, 40) end if type(problem.correlationId) == "string" then message ..= "; correlationId " .. string.sub(problem.correlationId, 1, 64) end if status == 401 then message ..= " (check the connection's access token, or reconnect)" end return houston.fail({operation = operation, layer = "upstream", upstream_status = status, message = message, retryable = (status == 429 and not daily) or status == 423 or status == 477 or (idempotent and status >= 500)}) end -- One request to HubSpot. A table body is sent as JSON and a string body as is. An empty reply to a -- DELETE (204) gives {success = true}; any other reply must be a JSON object. idempotent marks -- reads, updates and association changes, which are safe to repeat after a server error. local function call(operation: string, method: string, path: string, body: any, idempotent: boolean): Options local headers: HttpHeaders = {} local payload: string? = nil if type(body) == "table" then headers["Content-Type"] = {"application/json"} payload = json.encode(body) elseif body ~= nil then payload = body end local response = await(http.request({method = method, url = API .. path, headers = headers, body = payload})) if response.statusCode < 200 or response.statusCode >= 300 then fail(operation, response, idempotent) end local raw = await(response.body:readAll()) if method == "DELETE" and string.match(raw, "^%s*$") then return {success = true} end local ok, value = pcall(json.decode, raw) if not ok or type(value) ~= "table" or not string.match(raw, "^%s*{") then houston.fail({operation = operation, layer = "upstream", upstream_status = response.statusCode, retryable = false, message = "HubSpot returned an invalid JSON object"}) end return value end -- List replies keep results an array, even when HubSpot leaves it out. local function results(value: Options): Options if value.results == nil then value.results = json.decode("[]") end return value end -- A CRM API path, /crm/<family>/<VERSION>/<segments>, from segments already checked or encoded. local function crm(family: string, ...: string): string return table.concat({"/crm", family, VERSION, ...}, "/") end local help = { text = "HubSpot CRM API " .. VERSION .. [[ for one HubSpot account: contacts, companies, deals and tickets, their activities (notes, tasks, calls, meetings and logged emails), the associations between records, deal and ticket pipelines, owners and property definitions. Every operation takes one named options object with HubSpot's field names and returns HubSpot's JSON unchanged. Connector calls return completed values: use them directly, without await. ]] .. (if #READABLE > 0 then "objectType is one of " .. table.concat(READABLE, ", ") .. (if #WRITABLE > 0 then "; writes take " .. table.concat(WRITABLE, ", ") else "") .. ".\n" else "This connection reads no records: only owners are available.\n") .. [[ A record is {id, properties, createdAt, updatedAt, archived, associations?}. HubSpot returns only a few default properties unless properties names more, so list every property needed; values are strings (numbers and dates too) or null. listProperties gives an object type's property names, types and allowed options. Record, owner, pipeline and stage IDs are strings. Lists return one page: while paging.next.after is present, pass it back unchanged as after. results is always an array. Example: local page = hubspot.listObjects({objectType = "contacts", limit = 100, properties = {"email", "firstname"}}); for the next page, repeat the call with the same options plus after = page.paging.next.after. searchObjects filters and sorts records: its description gives its limits, and the search topic its filters. The associations and activities topics explain how records are linked and how to read their notes, tasks, calls, meetings and emails. Rate limits: signing in with HubSpot allows 110 requests per 10 seconds per HubSpot account, shared by every Houston connection to it; an access token allows 100 to 190 per 10 seconds per key or app (250 with HubSpot's API limit increase), plus a daily quota for the account. The association endpoints have their own limits: 100 (Free and Starter) or 150 (Professional and Enterprise) requests per 10 seconds, and up to 500,000 per day (200 and 1,000,000 with the API limit increase). Prefer batchReadObjects, batchReadAssociations and searchObjects to loops of single reads. Houston itself retries only a short 429 wait. Errors read 'HubSpot HTTP <status> (<category>): <message>', for example 'HubSpot HTTP 400 (VALIDATION_ERROR): Property values were not valid'. 429 (except the daily limit), 423, 477 and server errors are retryable. A 477 means HubSpot is moving the account between data centres, which can last hours: Retry-After says how long. A missing permission is a 403 (MISSING_SCOPES) naming the scopes needed ('needs one of: ...'): the account admin must add the scope to the service key or app, or reconnect. A 401 means the token is invalid or revoked.]] .. (if #WRITABLE > 0 then [[ Writes: createObject creates records, activities included (see the activities topic); updateObject changes their properties, which also moves a deal or ticket between stages; createDefaultAssociation, createAssociation and deleteAssociation link and unlink records (see the associations topic). Each one's description gives its rules. All of them give the same result when repeated except createObject, whose server errors are therefore not retryable.]] else ""), functions = {} :: {[string]: any}, sections = { search = [[searchObjects body fields: query (text searched in the default text properties), filterGroups, sorts, properties, limit and after. filterGroups are ORed and the filters inside one group are ANDed: at most 5 groups, 6 filters per group and 18 filters in all. A filter is {propertyName, operator, value} where operator is EQ, NEQ, LT, LTE, GT, GTE, HAS_PROPERTY, NOT_HAS_PROPERTY, CONTAINS_TOKEN or NOT_CONTAINS_TOKEN (value may use * as a wildcard, as in "*@example.com"); BETWEEN takes value and highValue; IN and NOT_IN take values, an array, which must be lowercase for string properties. Values are strings; dates may be epoch milliseconds or ISO 8601. The pseudo-property associations.{type}, with a singular type such as associations.contact or associations.company, finds records associated with that record ID. sorts holds one rule, {propertyName, direction = "ASCENDING" | "DESCENDING"}; results default to creation order. HubSpot refuses a search request body over 3,000 characters. Example: hubspot.searchObjects({objectType = "deals", filterGroups = {{filters = { {propertyName = "dealstage", operator = "EQ", value = "contractsent"}, {propertyName = "amount", operator = "GTE", value = "10000"}}}}, sorts = {{propertyName = "closedate", direction = "ASCENDING"}}, properties = {"dealname", "amount"}})]], associations = [[Associations link two records. Every pair has a default, unlabelled association; labels add meaning, such as a primary company or a custom label like Decision maker. An association type is {associationCategory, associationTypeId}: HUBSPOT_DEFINED for HubSpot's own types, USER_DEFINED for an account's custom labels (listAssociationLabels gives each pair's typeId values and labels). Type IDs depend on direction: contact to company is 279 (primary 1), company to contact 280. HUBSPOT_DEFINED type IDs from HubSpot's documentation: contact to company 279 (primary 1), deal 4, ticket 15, call 193, email 197, meeting 199, note 201, task 203; company to contact 280 (primary contact 2), deal 342 (primary 6), ticket 340 (primary 25), call 181, email 185, meeting 187, note 189, task 191; deal to contact 3, company 341 (primary 5), ticket 27, call 205, email 209, meeting 211, note 213, task 215; ticket to contact 16, company 339 (primary 26), deal 28, call 219, email 223, meeting 225, note 227, task 229; call to contact 194, company 182, deal 206, ticket 220; email to contact 198, company 186, deal 210, ticket 224; meeting to contact 200, company 188, deal 212, ticket 226; note to contact 202, company 190, deal 214, ticket 228; task to contact 204, company 192, deal 216, ticket 230. listAssociations reads one record's associations of one type; batchReadAssociations reads them for up to 1,000 records; listObjects and getObject also return associated IDs with associations = {"companies"}.]] .. (if #WRITABLE > 0 then [[ createDefaultAssociation links two records without a label, createAssociation sets labelled types on a pair, and deleteAssociation unlinks a pair. createObject can link a new record at creation with associations = {{to = {id}, types}}.]] else ""), activities = [[Notes, tasks, calls, meetings and emails (logged one-to-one emails) are object types like contacts. hs_timestamp places an activity on the timeline (a task's due date), as ISO 8601 UTC or epoch milliseconds. Useful properties: notes: hs_timestamp, hs_note_body (at most 65,536 characters), hubspot_owner_id, hs_attachment_ids. tasks: hs_timestamp, hs_task_subject, hs_task_body, hs_task_status (NOT_STARTED or COMPLETED), hs_task_priority (LOW, MEDIUM or HIGH), hs_task_type (EMAIL, CALL or TODO), hubspot_owner_id, hs_task_reminders (epoch milliseconds). calls: hs_timestamp, hs_call_title, hs_call_body, hs_call_direction, hs_call_duration, hs_call_status. meetings: hs_timestamp, hs_meeting_title, hs_meeting_body, hs_meeting_start_time, hs_meeting_end_time, hs_meeting_outcome. emails: hs_timestamp, hs_email_subject, hs_email_text, hs_email_direction, hs_email_status; reading email content needs HubSpot's sales-email-read permission. To read one record's activities, call listAssociations (for example from a contact to notes), then batchReadObjects on the returned toObjectId values (as strings) with the properties above; or searchObjects on the activity type with a filter on associations.contact. hubspot_owner_id holds an owner id from listOwners.]] .. (if houston.allows("engagements:write") then [[ Create an activity with createObject and associations to the records it concerns, for example a note on contact 101: createObject({objectType = "notes", properties = {hs_timestamp = "2026-11-13T10:00:00Z", hs_note_body = "Called about renewal."}, associations = {{to = {id = "101"}, types = {{associationCategory = "HUBSPOT_DEFINED", associationTypeId = 202}}}}}). See createObject for the properties each activity requires. Complete a task with updateObject and hs_task_status = "COMPLETED".]] else ""), }, } local exports: {[string]: any} = {help = help} -- Schemas and hints shared by several operations. local OBJECT_TYPE = {type = "string", enum = OBJECT_TYPES} local RECORD_ID = {type = "string", pattern = "^[0-9]+$", description = "A record ID, as a string."} local LOOKUP_ID = {type = "string", minLength = 1, description = "A record ID (digits, as a string), or with idProperty that property's value."} -- Without idProperty, IDs must be record IDs: strings of digits. local WITHOUT_ID_PROPERTY = {["not"] = {required = {"idProperty"}}} local DIGITS = {pattern = "^[0-9]+$"} local ID_PROPERTY = {type = "string", minLength = 1, description = "A unique property, such as email for contacts, whose value objectId holds instead of the record ID."} local AFTER = {type = "string", minLength = 1, description = "paging.next.after from the previous page."} local function nameList(description: string): Options return {type = "array", items = {type = "string", pattern = "^[^,]+$"}, minItems = 1, maxItems = MAX_NAMES, description = description} end local PROPERTY_NAMES = nameList("Property internal names to return; without it HubSpot returns only a few defaults.") local HISTORY_NAMES = nameList("Properties to return with their previous values, in propertiesWithHistory.") local ASSOCIATED = {type = "array", items = OBJECT_TYPE, minItems = 1, maxItems = MAX_NAMES, description = "Object types whose associated record IDs to include in each record's associations."} local ARCHIVED = {type = "boolean", description = "true returns only archived (deleted) items."} local ASSOCIATION_TYPES = {type = "array", minItems = 1, maxItems = MAX_LINKS, items = { type = "object", properties = {associationCategory = {type = "string", enum = CATEGORIES}, associationTypeId = {type = "integer", minimum = 1, maximum = 2147483647}}, required = {"associationCategory", "associationTypeId"}, additionalProperties = false, }} local PROPERTIES = {type = "object", minProperties = 1, additionalProperties = {type = {"string", "number", "boolean"}}, description = "Property internal names and values; an empty string clears a value."} local READ = {readOnlyHint = true, openWorldHint = true} local WRITE = {readOnlyHint = false, destructiveHint = false, openWorldHint = true} local IDEMPOTENT = {readOnlyHint = false, destructiveHint = false, idempotentHint = true, openWorldHint = true} local DESTRUCTIVE = {readOnlyHint = false, destructiveHint = true, idempotentHint = true, openWorldHint = true} help.functions.listOwners = { description = [[One page of the account's owners, the users (type "PERSON") and queues (type "QUEUE") that records can be assigned to: {results = {{id, email, firstName, lastName, userId, type, teams}}, paging?}. teams lists the teams an owner belongs to. An owner's id is what hubspot_owner_id holds; userId is the HubSpot user's ID. email finds one owner. limit is 1 to 500 (default 100).]], inputSchema = { type = "object", properties = {email = {type = "string", minLength = 1}, limit = {type = "integer", minimum = 1, maximum = 500}, after = AFTER, archived = ARCHIVED}, additionalProperties = false, examples = {{}, {email = "[email protected]"}} :: {any}, }, annotations = READ, } function exports.listOwners(input: any): Options local args = options(input) local q = query(args, {"email", "limit", "after", "archived"}, 500) done("listOwners", args) return results(call("listOwners", "GET", crm("owners") .. q, nil, true)) end help.functions.getOwner = { description = [[One owner: {id, email, firstName, lastName, userId, type ("PERSON" or "QUEUE"), teams, archived}. ownerId is the owner's id, or its userId with idProperty = "userId".]], inputSchema = { type = "object", properties = {ownerId = {type = "string", pattern = "^[0-9]+$"}, idProperty = {type = "string", enum = {"id", "userId"}}, archived = ARCHIVED}, required = {"ownerId"}, additionalProperties = false, examples = {{ownerId = "41629779"}}, }, annotations = READ, } function exports.getOwner(input: any): Options local args = options(input) local id = recordId(take(args, "ownerId"), "ownerId") if args.idProperty ~= nil then oneOf(args.idProperty, "idProperty", {"id", "userId"}) end local q = query(args, {"idProperty", "archived"}) done("getOwner", args) return call("getOwner", "GET", crm("owners", id) .. q, nil, true) end if #READABLE > 0 then help.functions.listObjects = { description = [[One page of records of objectType, oldest first: {results = {record}, paging = {next = {after}}?}. limit is 1 to 100 (HubSpot's default is 10). properties names the properties to return, beyond a few defaults; associations adds each record's associated IDs of those types. archived = true lists only archived records. propertiesWithHistory lowers the number of records HubSpot returns per request.]], inputSchema = { type = "object", properties = {objectType = OBJECT_TYPE, limit = {type = "integer", minimum = 1, maximum = 100}, after = AFTER, properties = PROPERTY_NAMES, propertiesWithHistory = HISTORY_NAMES, associations = ASSOCIATED, archived = ARCHIVED}, required = {"objectType"}, additionalProperties = false, examples = { {objectType = "contacts", limit = 50, properties = {"email", "firstname", "lastname"}}, {objectType = "deals", after = "9876", associations = {"contacts", "companies"}}, } :: {any}, }, annotations = READ, } function exports.listObjects(input: any): Options local args = options(input) local kind = objectType(args, "objectType") local q = query(args, {"limit", "after", "properties", "propertiesWithHistory", "associations", "archived"}, 100) done("listObjects", args) return results(call("listObjects", "GET", crm("objects", kind) .. q, nil, true)) end help.functions.getObject = { description = [[One record: {id, properties, createdAt, updatedAt, archived, associations?, propertiesWithHistory?}. objectId is the record ID, or with idProperty the value of that unique property, such as a contact's email with idProperty = "email". properties names the properties to return beyond a few defaults; associations adds associated record IDs of those types. The ID goes in the URL path, so a value containing / or %, or made only of dots, is refused: read such a record with batchReadObjects, which sends IDs in its body.]], inputSchema = { type = "object", properties = {objectType = OBJECT_TYPE, objectId = LOOKUP_ID, idProperty = ID_PROPERTY, properties = PROPERTY_NAMES, propertiesWithHistory = HISTORY_NAMES, associations = ASSOCIATED, archived = ARCHIVED}, required = {"objectType", "objectId"}, ["if"] = WITHOUT_ID_PROPERTY, ["then"] = {properties = {objectId = DIGITS}}, additionalProperties = false, examples = { {objectType = "companies", objectId = "512", properties = {"name", "domain"}}, {objectType = "contacts", objectId = "[email protected]", idProperty = "email"}, } :: {any}, }, annotations = READ, } function exports.getObject(input: any): Options local args = options(input) local kind = objectType(args, "objectType") local id = recordId(take(args, "objectId"), "objectId", args.idProperty ~= nil) local q = query(args, {"idProperty", "properties", "propertiesWithHistory", "associations", "archived"}) done("getObject", args) return call("getObject", "GET", crm("objects", kind, id) .. q, nil, true) end help.functions.searchObjects = { description = [[Searches records of objectType: {total, results = {record}, paging = {next = {after}}?}. Every field except objectType goes to HubSpot unchanged once its shape is checked; the search topic explains filterGroups, filters and sorts. limit is 1 to 200 (default 10). Search is eventually consistent (new or changed records take a moment to appear), excludes archived records, stops at 10,000 results and allows 5 requests per second per account.]], inputSchema = { type = "object", properties = { objectType = OBJECT_TYPE, query = {type = "string", minLength = 1, description = "Text searched in the default text properties."}, filterGroups = {type = "array", minItems = 1, maxItems = 5, items = { type = "object", properties = {filters = {type = "array", minItems = 1, maxItems = 6, items = { type = "object", properties = {propertyName = {type = "string", minLength = 1}, operator = {type = "string", enum = OPERATORS}, value = {type = "string"}, highValue = {type = "string"}, values = {type = "array", minItems = 1, maxItems = MAX_NAMES, items = {type = "string"}}}, required = {"propertyName", "operator"}, additionalProperties = false, }}}, required = {"filters"}, additionalProperties = false, }}, sorts = {type = "array", minItems = 1, maxItems = 1, items = { type = "object", properties = {propertyName = {type = "string", minLength = 1}, direction = {type = "string", enum = DIRECTIONS}}, required = {"propertyName", "direction"}, additionalProperties = false, }}, properties = PROPERTY_NAMES, limit = {type = "integer", minimum = 1, maximum = 200}, after = AFTER, }, required = {"objectType"}, additionalProperties = false, examples = { {objectType = "contacts", filterGroups = {{filters = {{propertyName = "email", operator = "CONTAINS_TOKEN", value = "*@example.com"}}}}, limit = 20}, {objectType = "deals", filterGroups = {{filters = {{propertyName = "dealstage", operator = "EQ", value = "contractsent"}, {propertyName = "amount", operator = "GTE", value = "10000"}}}}, sorts = {{propertyName = "closedate", direction = "ASCENDING"}}, properties = {"dealname", "amount", "closedate"}}, {objectType = "notes", filterGroups = {{filters = {{propertyName = "associations.contact", operator = "EQ", value = "101"}}}}, properties = {"hs_note_body", "hs_timestamp"}}, } :: {any}, }, annotations = READ, } function exports.searchObjects(input: any): Options local args = options(input) local kind = objectType(args, "objectType") local body: Options = {} if args.query ~= nil then body.query = text(take(args, "query"), "query") end if args.filterGroups ~= nil then local groups = array(take(args, "filterGroups"), "filterGroups", 5) local total = 0 for index, group in groups do local field = "filterGroups[" .. tostring(index) .. "]" closed(group, field, {"filters"}) for position, filter in array(group.filters, field .. ".filters", 6) do searchFilter(filter, field .. ".filters[" .. tostring(position) .. "]") total += 1 end end assert(total <= 18, "filterGroups may hold at most 18 filters in all") body.filterGroups = groups end if args.sorts ~= nil then body.sorts = array(take(args, "sorts"), "sorts", 1) for index, sort in body.sorts do local field = "sorts[" .. tostring(index) .. "]" closed(sort, field, {"propertyName", "direction"}) text(sort.propertyName, field .. ".propertyName") oneOf(sort.direction, field .. ".direction", DIRECTIONS) end end if args.properties ~= nil then body.properties = names(take(args, "properties"), "properties") end if args.limit ~= nil then body.limit = integer(take(args, "limit"), "limit", 1, 200) end if args.after ~= nil then body.after = text(take(args, "after"), "after") end done("searchObjects", args) return results(call("searchObjects", "POST", crm("objects", kind, "search"), body, true)) end help.functions.batchReadObjects = { description = [[Reads up to 100 records of objectType at once: {status, results = {record}, numErrors?, errors?}. inputs are {{id}}: record IDs, or with idProperty values of that unique property. IDs that do not exist are reported in errors (HTTP 207) while the others are returned. properties names the properties to return beyond a few defaults; propertiesWithHistory lowers the number of records HubSpot returns per request.]], inputSchema = { type = "object", properties = { objectType = OBJECT_TYPE, inputs = {type = "array", minItems = 1, maxItems = 100, items = { type = "object", properties = {id = LOOKUP_ID}, required = {"id"}, additionalProperties = false, }}, idProperty = ID_PROPERTY, properties = PROPERTY_NAMES, propertiesWithHistory = HISTORY_NAMES, archived = ARCHIVED, }, required = {"objectType", "inputs"}, ["if"] = WITHOUT_ID_PROPERTY, ["then"] = {properties = {inputs = {items = {properties = {id = DIGITS}}}}}, additionalProperties = false, examples = {{objectType = "contacts", inputs = {{id = "101"}, {id = "102"}}, properties = {"email"}}}, }, annotations = READ, } function exports.batchReadObjects(input: any): Options local args = options(input) local kind = objectType(args, "objectType") local idProperty = take(args, "idProperty") local body: Options = {inputs = {}} for index, item in array(take(args, "inputs"), "inputs", 100) do local field = "inputs[" .. tostring(index) .. "]" closed(item, field, {"id"}) idValue(item.id, field .. ".id", idProperty ~= nil) table.insert(body.inputs, {id = item.id}) end if idProperty ~= nil then body.idProperty = text(idProperty, "idProperty") end if args.properties ~= nil then body.properties = names(take(args, "properties"), "properties") end if args.propertiesWithHistory ~= nil then body.propertiesWithHistory = names(take(args, "propertiesWithHistory"), "propertiesWithHistory") end local q = query(args, {"archived"}) done("batchReadObjects", args) return results(call("batchReadObjects", "POST", crm("objects", kind, "batch", "read") .. q, body, true)) end help.functions.listAssociations = { description = [[One page of the records of toObjectType associated with one record: {results = {{toObjectId, associationTypes = {{category, typeId, label}}}}, paging?}. toObjectId may come back as a number or a string; pass it to other operations as a string. limit is 1 to 500 (the default).]], inputSchema = { type = "object", properties = {objectType = OBJECT_TYPE, objectId = RECORD_ID, toObjectType = OBJECT_TYPE, limit = {type = "integer", minimum = 1, maximum = 500}, after = AFTER}, required = {"objectType", "objectId", "toObjectType"}, additionalProperties = false, examples = {{objectType = "deals", objectId = "9876", toObjectType = "contacts"}}, }, annotations = READ, } function exports.listAssociations(input: any): Options local args = options(input) local kind, id = record(args, "objectType", "objectId") local to = objectType(args, "toObjectType") local q = query(args, {"limit", "after"}, 500) done("listAssociations", args) return results(call("listAssociations", "GET", crm("objects", kind, id, "associations", to) .. q, nil, true)) end help.functions.batchReadAssociations = { description = [[Reads the toObjectType associations of up to 1,000 records of fromObjectType: {status, results = {{from = {id}, to = {{toObjectId, associationTypes}}, paging?}}, errors?}. inputs are {{id, after?}}; after continues one record's associations from its paging.next.after.]], inputSchema = { type = "object", properties = { fromObjectType = OBJECT_TYPE, toObjectType = OBJECT_TYPE, inputs = {type = "array", minItems = 1, maxItems = 1000, items = { type = "object", properties = {id = RECORD_ID, after = AFTER}, required = {"id"}, additionalProperties = false, }}, }, required = {"fromObjectType", "toObjectType", "inputs"}, additionalProperties = false, examples = {{fromObjectType = "deals", toObjectType = "companies", inputs = {{id = "9876"}, {id = "9877"}}}}, }, annotations = READ, } function exports.batchReadAssociations(input: any): Options local args = options(input) local from = objectType(args, "fromObjectType") local to = objectType(args, "toObjectType") local inputs: {Options} = {} for index, item in array(take(args, "inputs"), "inputs", 1000) do local field = "inputs[" .. tostring(index) .. "]" closed(item, field, {"id", "after"}) idValue(item.id, field .. ".id") table.insert(inputs, {id = item.id, after = if item.after ~= nil then text(item.after, field .. ".after") else nil}) end done("batchReadAssociations", args) return results(call("batchReadAssociations", "POST", crm("associations", from, to, "batch", "read"), {inputs = inputs}, true)) end help.functions.listAssociationLabels = { description = [[The association types from fromObjectType to toObjectType in this account, HubSpot's and custom labels: {results = {{category, typeId, label}}}. label is null for the default type.]], inputSchema = { type = "object", properties = {fromObjectType = OBJECT_TYPE, toObjectType = OBJECT_TYPE}, required = {"fromObjectType", "toObjectType"}, additionalProperties = false, examples = {{fromObjectType = "contacts", toObjectType = "companies"}}, }, annotations = READ, } function exports.listAssociationLabels(input: any): Options local args = options(input) local from = objectType(args, "fromObjectType") local to = objectType(args, "toObjectType") done("listAssociationLabels", args) return results(call("listAssociationLabels", "GET", crm("associations", from, to, "labels"), nil, true)) end help.functions.listProperties = { description = [[The non-sensitive property definitions of objectType (HubSpot leaves out properties holding sensitive data): {results = {{name, label, type, fieldType, groupName, description, options = {{label, value}}, calculated, hasUniqueValue, hidden, ...}}}. name is the internal name that properties lists and writes use; for enumerations, options give the values a property accepts (such as lifecyclestage or hs_task_status).]], inputSchema = { type = "object", properties = {objectType = OBJECT_TYPE, archived = ARCHIVED}, required = {"objectType"}, additionalProperties = false, examples = {{objectType = "deals"}}, }, annotations = READ, } function exports.listProperties(input: any): Options local args = options(input) local kind = objectType(args, "objectType") local q = query(args, {"archived"}) done("listProperties", args) return results(call("listProperties", "GET", crm("properties", kind) .. q, nil, true)) end help.functions.getProperty = { description = [[One property definition: {name, label, type, fieldType, groupName, description, options, ...}.]], inputSchema = { type = "object", properties = {objectType = OBJECT_TYPE, propertyName = {type = "string", pattern = "^[A-Za-z0-9_]+$"}, archived = ARCHIVED}, required = {"objectType", "propertyName"}, additionalProperties = false, examples = {{objectType = "tasks", propertyName = "hs_task_status"}}, }, annotations = READ, } function exports.getProperty(input: any): Options local args = options(input) local kind = objectType(args, "objectType") local name = take(args, "propertyName") assert(type(name) == "string" and string.match(name, "^[%w_]+$") ~= nil, "propertyName must be a property's internal name") local q = query(args, {"archived"}) done("getProperty", args) return call("getProperty", "GET", crm("properties", kind, name) .. q, nil, true) end if #PIPELINES > 0 then help.functions.listPipelines = { description = [[Every deal or ticket pipeline with its stages: {results = {{id, label, displayOrder, archived, stages = {{id, label, displayOrder, metadata}}}}}. Stage IDs are what a deal's dealstage and a ticket's hs_pipeline_stage hold; pipeline IDs are what pipeline and hs_pipeline hold. For deals, stage metadata.probability is the win probability; for tickets, metadata.ticketState is OPEN or CLOSED.]], inputSchema = { type = "object", properties = {objectType = {type = "string", enum = PIPELINE_TYPES}}, required = {"objectType"}, additionalProperties = false, examples = {{objectType = "deals"}}, }, annotations = READ, } function exports.listPipelines(input: any): Options local args = options(input) local kind = objectType(args, "objectType", PIPELINES) done("listPipelines", args) return results(call("listPipelines", "GET", crm("pipelines", kind), nil, true)) end help.functions.getPipeline = { description = [[One deal or ticket pipeline: {id, label, displayOrder, archived, stages = {{id, label, displayOrder, metadata}}}. The default pipeline's ID is often "default" for deals and "0" for tickets.]], inputSchema = { type = "object", properties = {objectType = {type = "string", enum = PIPELINE_TYPES}, pipelineId = {type = "string", minLength = 1}}, required = {"objectType", "pipelineId"}, additionalProperties = false, examples = {{objectType = "tickets", pipelineId = "0"}}, }, annotations = READ, } function exports.getPipeline(input: any): Options local args = options(input) local kind = objectType(args, "objectType", PIPELINES) local id = url.segment(text(take(args, "pipelineId"), "pipelineId"), "pipelineId") done("getPipeline", args) return call("getPipeline", "GET", crm("pipelines", kind, id), nil, true) end end end if #WRITABLE > 0 then help.functions.createObject = { description = [[Creates a record of objectType and returns it (HTTP 201). properties sets property values by internal name; associations links the new record, each {to = {id}, types = {{associationCategory, associationTypeId}}} (see the associations topic for type IDs). HubSpot refuses a contact whose email already exists (409). Not idempotent: a failed or timed-out call may still have created the record, so search for it before repeating. Required properties: notes, tasks and calls need hs_timestamp; emails hs_timestamp and hs_email_direction; meetings hs_timestamp, hs_meeting_title and hs_meeting_start_time (HubSpot's meetings guide also marks hubspot_owner_id required); deals dealname, dealstage and pipeline (HubSpot uses the default pipeline when pipeline is left out); tickets subject, hs_pipeline_stage and hs_pipeline (again the default pipeline when left out); companies name or domain; contacts at least one of email, firstname or lastname.]], inputSchema = { type = "object", properties = { objectType = OBJECT_TYPE, properties = PROPERTIES, associations = {type = "array", minItems = 1, maxItems = MAX_LINKS, items = { type = "object", properties = { to = {type = "object", properties = {id = RECORD_ID}, required = {"id"}, additionalProperties = false}, types = ASSOCIATION_TYPES, }, required = {"to", "types"}, additionalProperties = false, }}, }, required = {"objectType", "properties"}, additionalProperties = false, examples = { {objectType = "contacts", properties = {email = "[email protected]", firstname = "Ana", lastname = "Silva"}}, {objectType = "notes", properties = {hs_timestamp = "2026-11-13T10:00:00Z", hs_note_body = "Called about renewal."}, associations = {{to = {id = "101"}, types = {{associationCategory = "HUBSPOT_DEFINED", associationTypeId = 202}}}}}, {objectType = "tasks", properties = {hs_timestamp = "2026-11-20T09:00:00Z", hs_task_subject = "Send contract", hs_task_status = "NOT_STARTED", hs_task_priority = "HIGH", hs_task_type = "TODO"}, associations = {{to = {id = "9876"}, types = {{associationCategory = "HUBSPOT_DEFINED", associationTypeId = 216}}}}}, } :: {any}, }, annotations = WRITE, } function exports.createObject(input: any): Options local args = options(input) local kind = objectType(args, "objectType", WRITABLE) local body: Options = {properties = properties(take(args, "properties"))} if args.associations ~= nil then body.associations = {} for index, item in array(take(args, "associations"), "associations", MAX_LINKS) do local field = "associations[" .. tostring(index) .. "]" closed(item, field, {"to", "types"}) local to = closed(item.to, field .. ".to", {"id"}) idValue(to.id, field .. ".to.id") table.insert(body.associations, {to = {id = to.id}, types = associationTypes(item.types, field .. ".types")}) end end done("createObject", args) return call("createObject", "POST", crm("objects", kind), body, false) end help.functions.updateObject = { description = [[Changes the named properties of a record and returns it; other properties keep their values, and an empty string clears one. objectId is the record ID, or with idProperty that unique property's value. That value goes in the URL path, so one containing / or %, or made only of dots, is refused: find the record ID with batchReadObjects and update by record ID. Move a deal with dealstage (a stage ID from listPipelines), adding pipeline when the stage belongs to another pipeline; move a ticket with hs_pipeline_stage (and hs_pipeline).]], inputSchema = { type = "object", properties = {objectType = OBJECT_TYPE, objectId = LOOKUP_ID, properties = PROPERTIES, idProperty = ID_PROPERTY}, required = {"objectType", "objectId", "properties"}, ["if"] = WITHOUT_ID_PROPERTY, ["then"] = {properties = {objectId = DIGITS}}, additionalProperties = false, examples = { {objectType = "deals", objectId = "9876", properties = {dealstage = "closedwon"}}, {objectType = "deals", objectId = "9876", properties = {pipeline = "renewals", dealstage = "1234567"}}, {objectType = "contacts", objectId = "[email protected]", idProperty = "email", properties = {jobtitle = "CTO"}}, } :: {any}, }, annotations = IDEMPOTENT, } function exports.updateObject(input: any): Options local args = options(input) local kind = objectType(args, "objectType", WRITABLE) local id = recordId(take(args, "objectId"), "objectId", args.idProperty ~= nil) local body = {properties = properties(take(args, "properties"))} local q = query(args, {"idProperty"}) done("updateObject", args) return call("updateObject", "PATCH", crm("objects", kind, id) .. q, body, true) end help.functions.createDefaultAssociation = { description = [[Links two records with HubSpot's default, unlabelled association, in both directions: {status, results = {{from, to, associationSpec}}}.]], inputSchema = { type = "object", properties = {fromObjectType = OBJECT_TYPE, fromObjectId = RECORD_ID, toObjectType = OBJECT_TYPE, toObjectId = RECORD_ID}, required = {"fromObjectType", "fromObjectId", "toObjectType", "toObjectId"}, additionalProperties = false, examples = {{fromObjectType = "contacts", fromObjectId = "101", toObjectType = "companies", toObjectId = "512"}}, }, annotations = IDEMPOTENT, } function exports.createDefaultAssociation(input: any): Options local args = options(input) local from, fromId = record(args, "fromObjectType", "fromObjectId", WRITABLE) local to, toId = record(args, "toObjectType", "toObjectId") done("createDefaultAssociation", args) return call("createDefaultAssociation", "PUT", crm("objects", from, fromId, "associations", "default", to, toId), "", true) end help.functions.createAssociation = { description = [[Sets labelled association types between two records: {fromObjectTypeId, fromObjectId, toObjectTypeId, toObjectId, labels}. types replaces the labels the pair already has, so include every label to keep. Type IDs depend on direction; see the associations topic and listAssociationLabels.]], inputSchema = { type = "object", properties = {objectType = OBJECT_TYPE, objectId = RECORD_ID, toObjectType = OBJECT_TYPE, toObjectId = RECORD_ID, types = ASSOCIATION_TYPES}, required = {"objectType", "objectId", "toObjectType", "toObjectId", "types"}, additionalProperties = false, examples = {{objectType = "contacts", objectId = "101", toObjectType = "companies", toObjectId = "512", types = {{associationCategory = "HUBSPOT_DEFINED", associationTypeId = 1}}}}, }, annotations = DESTRUCTIVE, } function exports.createAssociation(input: any): Options local args = options(input) local kind, id = record(args, "objectType", "objectId", WRITABLE) local to, toId = record(args, "toObjectType", "toObjectId") local types = associationTypes(take(args, "types"), "types") done("createAssociation", args) return call("createAssociation", "PUT", crm("objects", kind, id, "associations", to, toId), types, true) end help.functions.deleteAssociation = { description = [[Removes every association between two records, labelled or not, and returns {success = true}. Neither record is deleted; createDefaultAssociation or createAssociation links them again.]], inputSchema = { type = "object", properties = {objectType = OBJECT_TYPE, objectId = RECORD_ID, toObjectType = OBJECT_TYPE, toObjectId = RECORD_ID}, required = {"objectType", "objectId", "toObjectType", "toObjectId"}, additionalProperties = false, examples = {{objectType = "contacts", objectId = "101", toObjectType = "companies", toObjectId = "512"}}, }, annotations = DESTRUCTIVE, } function exports.deleteAssociation(input: any): Options local args = options(input) local kind, id = record(args, "objectType", "objectId", WRITABLE) local to, toId = record(args, "toObjectType", "toObjectId") done("deleteAssociation", args) return call("deleteAssociation", "DELETE", crm("objects", kind, id, "associations", to, toId), nil, true) end end return exportshouston.json
{ "schema_version": 2, "name": "HubSpot", "warning": "**Pending HubSpot review.** HubSpot is still reviewing Houston's app. Until HubSpot lists it, you will see an *unverified app* warning while connecting: select **Connect app**, type **I accept the risk**, then select **Connect**.", "files": [ "connector.luau" ], "icon": "icon.svg", "access": [ { "name": "contacts", "label": "Contacts", "levels": [ { "value": "none", "label": "None" }, { "value": "read", "label": "Read" }, { "value": "write", "label": "Write" } ], "default": "read" }, { "name": "companies", "label": "Companies", "levels": [ { "value": "none", "label": "None" }, { "value": "read", "label": "Read" }, { "value": "write", "label": "Write" } ], "default": "read" }, { "name": "deals", "label": "Deals", "description": "Deals and their pipelines.", "levels": [ { "value": "none", "label": "None" }, { "value": "read", "label": "Read" }, { "value": "write", "label": "Write" } ], "default": "read" }, { "name": "tickets", "label": "Tickets", "description": "Tickets and their pipelines.", "levels": [ { "value": "none", "label": "None" }, { "value": "read", "label": "Read" }, { "value": "write", "label": "Write" } ], "default": "read" }, { "name": "engagements", "label": "Activities", "description": "Notes, tasks, calls, meetings and logged emails.", "levels": [ { "value": "none", "label": "None" }, { "value": "read", "label": "Read" }, { "value": "write", "label": "Write" } ], "default": "read" } ], "auth": { "oauth": { "type": "oauth2", "label": "Connect with HubSpot", "order": 1, "authorize_url": "https://app.hubspot.com/oauth/authorize", "token_url": "https://api.hubapi.com/oauth/2026-09/token", "client_auth": "body", "pkce": "S256", "client_id": "{{publisher.client_id}}", "client_secret": "{{publisher.client_secret}}", "require_refresh": true, "scopes": [ { "values": [ "oauth", "crm.objects.owners.read", "sales-email-read" ] }, { "if": "{{ allows access.contacts \"read\" }}", "values": [ "crm.objects.contacts.read", "crm.schemas.contacts.read" ] }, { "if": "{{ allows access.contacts \"write\" }}", "values": [ "crm.objects.contacts.write" ] }, { "if": "{{ allows access.companies \"read\" }}", "values": [ "crm.objects.companies.read", "crm.schemas.companies.read" ] }, { "if": "{{ allows access.companies \"write\" }}", "values": [ "crm.objects.companies.write" ] }, { "if": "{{ allows access.deals \"read\" }}", "values": [ "crm.objects.deals.read", "crm.schemas.deals.read" ] }, { "if": "{{ allows access.deals \"write\" }}", "values": [ "crm.objects.deals.write" ] }, { "if": "{{ allows access.tickets \"read\" }}", "values": [ "crm.objects.tickets.read", "crm.schemas.tickets.read" ] }, { "if": "{{ allows access.tickets \"write\" }}", "values": [ "crm.objects.tickets.write" ] } ], "token_response": { "scopes": "/scopes" }, "refresh_response": { "scopes": "/scopes" } }, "token": { "config": { "token": { "type": "secret", "label": "Access token", "required": true } }, "label": "Service key or private app access token", "order": 2, "type": "manual" } }, "publisher": { "client_id": { "type": "string", "label": "HubSpot app client ID", "order": 1 }, "client_secret": { "type": "secret", "label": "HubSpot app client secret", "order": 2 } }, "proxy": [ { "match": { "protocol": "http", "host": [ "api.hubapi.com" ], "method": [ "GET" ], "path": [ "/crm/associations/2026-09/{fromObjectType}/{toObjectType}/labels", "/crm/owners/2026-09", "/crm/owners/2026-09/{ownerId}" ] }, "action": { "headers": { "set": { "Authorization": "Bearer {{auth.oauth.access_token || auth.token.token}}" } } } }, { "match": { "protocol": "http", "host": [ "api.hubapi.com" ], "method": [ "POST" ], "path": [ "/crm/associations/2026-09/{fromObjectType}/{toObjectType}/batch/read" ] }, "action": { "headers": { "set": { "Authorization": "Bearer {{auth.oauth.access_token || auth.token.token}}" } } } }, { "if": "{{ allows access.contacts \"read\" }}", "match": { "protocol": "http", "host": [ "api.hubapi.com" ], "method": [ "GET" ], "path": [ "/crm/objects/2026-09/contacts", "/crm/objects/2026-09/contacts/{objectId}", "/crm/objects/2026-09/contacts/{objectId}/associations/{toObjectType}", "/crm/properties/2026-09/contacts", "/crm/properties/2026-09/contacts/{propertyName}" ], "colon_path_parameters": [ "objectId" ] }, "action": { "headers": { "set": { "Authorization": "Bearer {{auth.oauth.access_token || auth.token.token}}" } } } }, { "if": "{{ allows access.contacts \"read\" }}", "match": { "protocol": "http", "host": [ "api.hubapi.com" ], "method": [ "POST" ], "path": [ "/crm/objects/2026-09/contacts/search", "/crm/objects/2026-09/contacts/batch/read" ] }, "action": { "headers": { "set": { "Authorization": "Bearer {{auth.oauth.access_token || auth.token.token}}" } } } }, { "if": "{{ allows access.contacts \"write\" }}", "match": { "protocol": "http", "host": [ "api.hubapi.com" ], "method": [ "POST" ], "path": [ "/crm/objects/2026-09/contacts" ] }, "action": { "headers": { "set": { "Authorization": "Bearer {{auth.oauth.access_token || auth.token.token}}" } } } }, { "if": "{{ allows access.contacts \"write\" }}", "match": { "protocol": "http", "host": [ "api.hubapi.com" ], "method": [ "PATCH" ], "path": [ "/crm/objects/2026-09/contacts/{objectId}" ], "colon_path_parameters": [ "objectId" ] }, "action": { "headers": { "set": { "Authorization": "Bearer {{auth.oauth.access_token || auth.token.token}}" } } } }, { "if": "{{ allows access.contacts \"write\" }}", "match": { "protocol": "http", "host": [ "api.hubapi.com" ], "method": [ "PUT" ], "path": [ "/crm/objects/2026-09/contacts/{objectId}/associations/{toObjectType}/{toObjectId}", "/crm/objects/2026-09/contacts/{fromObjectId}/associations/default/{toObjectType}/{toObjectId}" ] }, "action": { "headers": { "set": { "Authorization": "Bearer {{auth.oauth.access_token || auth.token.token}}" } } } }, { "if": "{{ allows access.contacts \"write\" }}", "match": { "protocol": "http", "host": [ "api.hubapi.com" ], "method": [ "DELETE" ], "path": [ "/crm/objects/2026-09/contacts/{objectId}/associations/{toObjectType}/{toObjectId}" ] }, "action": { "headers": { "set": { "Authorization": "Bearer {{auth.oauth.access_token || auth.token.token}}" } } } }, { "if": "{{ allows access.companies \"read\" }}", "match": { "protocol": "http", "host": [ "api.hubapi.com" ], "method": [ "GET" ], "path": [ "/crm/objects/2026-09/companies", "/crm/objects/2026-09/companies/{objectId}", "/crm/objects/2026-09/companies/{objectId}/associations/{toObjectType}", "/crm/properties/2026-09/companies", "/crm/properties/2026-09/companies/{propertyName}" ], "colon_path_parameters": [ "objectId" ] }, "action": { "headers": { "set": { "Authorization": "Bearer {{auth.oauth.access_token || auth.token.token}}" } } } }, { "if": "{{ allows access.companies \"read\" }}", "match": { "protocol": "http", "host": [ "api.hubapi.com" ], "method": [ "POST" ], "path": [ "/crm/objects/2026-09/companies/search", "/crm/objects/2026-09/companies/batch/read" ] }, "action": { "headers": { "set": { "Authorization": "Bearer {{auth.oauth.access_token || auth.token.token}}" } } } }, { "if": "{{ allows access.companies \"write\" }}", "match": { "protocol": "http", "host": [ "api.hubapi.com" ], "method": [ "POST" ], "path": [ "/crm/objects/2026-09/companies" ] }, "action": { "headers": { "set": { "Authorization": "Bearer {{auth.oauth.access_token || auth.token.token}}" } } } }, { "if": "{{ allows access.companies \"write\" }}", "match": { "protocol": "http", "host": [ "api.hubapi.com" ], "method": [ "PATCH" ], "path": [ "/crm/objects/2026-09/companies/{objectId}" ], "colon_path_parameters": [ "objectId" ] }, "action": { "headers": { "set": { "Authorization": "Bearer {{auth.oauth.access_token || auth.token.token}}" } } } }, { "if": "{{ allows access.companies \"write\" }}", "match": { "protocol": "http", "host": [ "api.hubapi.com" ], "method": [ "PUT" ], "path": [ "/crm/objects/2026-09/companies/{objectId}/associations/{toObjectType}/{toObjectId}", "/crm/objects/2026-09/companies/{fromObjectId}/associations/default/{toObjectType}/{toObjectId}" ] }, "action": { "headers": { "set": { "Authorization": "Bearer {{auth.oauth.access_token || auth.token.token}}" } } } }, { "if": "{{ allows access.companies \"write\" }}", "match": { "protocol": "http", "host": [ "api.hubapi.com" ], "method": [ "DELETE" ], "path": [ "/crm/objects/2026-09/companies/{objectId}/associations/{toObjectType}/{toObjectId}" ] }, "action": { "headers": { "set": { "Authorization": "Bearer {{auth.oauth.access_token || auth.token.token}}" } } } }, { "if": "{{ allows access.deals \"read\" }}", "match": { "protocol": "http", "host": [ "api.hubapi.com" ], "method": [ "GET" ], "path": [ "/crm/objects/2026-09/deals", "/crm/objects/2026-09/deals/{objectId}", "/crm/objects/2026-09/deals/{objectId}/associations/{toObjectType}", "/crm/properties/2026-09/deals", "/crm/properties/2026-09/deals/{propertyName}", "/crm/pipelines/2026-09/deals", "/crm/pipelines/2026-09/deals/{pipelineId}" ], "colon_path_parameters": [ "objectId" ] }, "action": { "headers": { "set": { "Authorization": "Bearer {{auth.oauth.access_token || auth.token.token}}" } } } }, { "if": "{{ allows access.deals \"read\" }}", "match": { "protocol": "http", "host": [ "api.hubapi.com" ], "method": [ "POST" ], "path": [ "/crm/objects/2026-09/deals/search", "/crm/objects/2026-09/deals/batch/read" ] }, "action": { "headers": { "set": { "Authorization": "Bearer {{auth.oauth.access_token || auth.token.token}}" } } } }, { "if": "{{ allows access.deals \"write\" }}", "match": { "protocol": "http", "host": [ "api.hubapi.com" ], "method": [ "POST" ], "path": [ "/crm/objects/2026-09/deals" ] }, "action": { "headers": { "set": { "Authorization": "Bearer {{auth.oauth.access_token || auth.token.token}}" } } } }, { "if": "{{ allows access.deals \"write\" }}", "match": { "protocol": "http", "host": [ "api.hubapi.com" ], "method": [ "PATCH" ], "path": [ "/crm/objects/2026-09/deals/{objectId}" ], "colon_path_parameters": [ "objectId" ] }, "action": { "headers": { "set": { "Authorization": "Bearer {{auth.oauth.access_token || auth.token.token}}" } } } }, { "if": "{{ allows access.deals \"write\" }}", "match": { "protocol": "http", "host": [ "api.hubapi.com" ], "method": [ "PUT" ], "path": [ "/crm/objects/2026-09/deals/{objectId}/associations/{toObjectType}/{toObjectId}", "/crm/objects/2026-09/deals/{fromObjectId}/associations/default/{toObjectType}/{toObjectId}" ] }, "action": { "headers": { "set": { "Authorization": "Bearer {{auth.oauth.access_token || auth.token.token}}" } } } }, { "if": "{{ allows access.deals \"write\" }}", "match": { "protocol": "http", "host": [ "api.hubapi.com" ], "method": [ "DELETE" ], "path": [ "/crm/objects/2026-09/deals/{objectId}/associations/{toObjectType}/{toObjectId}" ] }, "action": { "headers": { "set": { "Authorization": "Bearer {{auth.oauth.access_token || auth.token.token}}" } } } }, { "if": "{{ allows access.tickets \"read\" }}", "match": { "protocol": "http", "host": [ "api.hubapi.com" ], "method": [ "GET" ], "path": [ "/crm/objects/2026-09/tickets", "/crm/objects/2026-09/tickets/{objectId}", "/crm/objects/2026-09/tickets/{objectId}/associations/{toObjectType}", "/crm/properties/2026-09/tickets", "/crm/properties/2026-09/tickets/{propertyName}", "/crm/pipelines/2026-09/tickets", "/crm/pipelines/2026-09/tickets/{pipelineId}" ], "colon_path_parameters": [ "objectId" ] }, "action": { "headers": { "set": { "Authorization": "Bearer {{auth.oauth.access_token || auth.token.token}}" } } } }, { "if": "{{ allows access.tickets \"read\" }}", "match": { "protocol": "http", "host": [ "api.hubapi.com" ], "method": [ "POST" ], "path": [ "/crm/objects/2026-09/tickets/search", "/crm/objects/2026-09/tickets/batch/read" ] }, "action": { "headers": { "set": { "Authorization": "Bearer {{auth.oauth.access_token || auth.token.token}}" } } } }, { "if": "{{ allows access.tickets \"write\" }}", "match": { "protocol": "http", "host": [ "api.hubapi.com" ], "method": [ "POST" ], "path": [ "/crm/objects/2026-09/tickets" ] }, "action": { "headers": { "set": { "Authorization": "Bearer {{auth.oauth.access_token || auth.token.token}}" } } } }, { "if": "{{ allows access.tickets \"write\" }}", "match": { "protocol": "http", "host": [ "api.hubapi.com" ], "method": [ "PATCH" ], "path": [ "/crm/objects/2026-09/tickets/{objectId}" ], "colon_path_parameters": [ "objectId" ] }, "action": { "headers": { "set": { "Authorization": "Bearer {{auth.oauth.access_token || auth.token.token}}" } } } }, { "if": "{{ allows access.tickets \"write\" }}", "match": { "protocol": "http", "host": [ "api.hubapi.com" ], "method": [ "PUT" ], "path": [ "/crm/objects/2026-09/tickets/{objectId}/associations/{toObjectType}/{toObjectId}", "/crm/objects/2026-09/tickets/{fromObjectId}/associations/default/{toObjectType}/{toObjectId}" ] }, "action": { "headers": { "set": { "Authorization": "Bearer {{auth.oauth.access_token || auth.token.token}}" } } } }, { "if": "{{ allows access.tickets \"write\" }}", "match": { "protocol": "http", "host": [ "api.hubapi.com" ], "method": [ "DELETE" ], "path": [ "/crm/objects/2026-09/tickets/{objectId}/associations/{toObjectType}/{toObjectId}" ] }, "action": { "headers": { "set": { "Authorization": "Bearer {{auth.oauth.access_token || auth.token.token}}" } } } }, { "if": "{{ allows access.engagements \"read\" }}", "match": { "protocol": "http", "host": [ "api.hubapi.com" ], "method": [ "GET" ], "path": [ "/crm/objects/2026-09/notes", "/crm/objects/2026-09/notes/{objectId}", "/crm/objects/2026-09/notes/{objectId}/associations/{toObjectType}", "/crm/objects/2026-09/tasks", "/crm/objects/2026-09/tasks/{objectId}", "/crm/objects/2026-09/tasks/{objectId}/associations/{toObjectType}", "/crm/objects/2026-09/calls", "/crm/objects/2026-09/calls/{objectId}", "/crm/objects/2026-09/calls/{objectId}/associations/{toObjectType}", "/crm/objects/2026-09/meetings", "/crm/objects/2026-09/meetings/{objectId}", "/crm/objects/2026-09/meetings/{objectId}/associations/{toObjectType}", "/crm/objects/2026-09/emails", "/crm/objects/2026-09/emails/{objectId}", "/crm/objects/2026-09/emails/{objectId}/associations/{toObjectType}", "/crm/properties/2026-09/notes", "/crm/properties/2026-09/notes/{propertyName}", "/crm/properties/2026-09/tasks", "/crm/properties/2026-09/tasks/{propertyName}", "/crm/properties/2026-09/calls", "/crm/properties/2026-09/calls/{propertyName}", "/crm/properties/2026-09/meetings", "/crm/properties/2026-09/meetings/{propertyName}", "/crm/properties/2026-09/emails", "/crm/properties/2026-09/emails/{propertyName}" ], "colon_path_parameters": [ "objectId" ] }, "action": { "headers": { "set": { "Authorization": "Bearer {{auth.oauth.access_token || auth.token.token}}" } } } }, { "if": "{{ allows access.engagements \"read\" }}", "match": { "protocol": "http", "host": [ "api.hubapi.com" ], "method": [ "POST" ], "path": [ "/crm/objects/2026-09/notes/search", "/crm/objects/2026-09/notes/batch/read", "/crm/objects/2026-09/tasks/search", "/crm/objects/2026-09/tasks/batch/read", "/crm/objects/2026-09/calls/search", "/crm/objects/2026-09/calls/batch/read", "/crm/objects/2026-09/meetings/search", "/crm/objects/2026-09/meetings/batch/read", "/crm/objects/2026-09/emails/search", "/crm/objects/2026-09/emails/batch/read" ] }, "action": { "headers": { "set": { "Authorization": "Bearer {{auth.oauth.access_token || auth.token.token}}" } } } }, { "if": "{{ allows access.engagements \"write\" }}", "match": { "protocol": "http", "host": [ "api.hubapi.com" ], "method": [ "POST" ], "path": [ "/crm/objects/2026-09/notes", "/crm/objects/2026-09/tasks", "/crm/objects/2026-09/calls", "/crm/objects/2026-09/meetings", "/crm/objects/2026-09/emails" ] }, "action": { "headers": { "set": { "Authorization": "Bearer {{auth.oauth.access_token || auth.token.token}}" } } } }, { "if": "{{ allows access.engagements \"write\" }}", "match": { "protocol": "http", "host": [ "api.hubapi.com" ], "method": [ "PATCH" ], "path": [ "/crm/objects/2026-09/notes/{objectId}", "/crm/objects/2026-09/tasks/{objectId}", "/crm/objects/2026-09/calls/{objectId}", "/crm/objects/2026-09/meetings/{objectId}", "/crm/objects/2026-09/emails/{objectId}" ], "colon_path_parameters": [ "objectId" ] }, "action": { "headers": { "set": { "Authorization": "Bearer {{auth.oauth.access_token || auth.token.token}}" } } } }, { "if": "{{ allows access.engagements \"write\" }}", "match": { "protocol": "http", "host": [ "api.hubapi.com" ], "method": [ "PUT" ], "path": [ "/crm/objects/2026-09/notes/{objectId}/associations/{toObjectType}/{toObjectId}", "/crm/objects/2026-09/notes/{fromObjectId}/associations/default/{toObjectType}/{toObjectId}", "/crm/objects/2026-09/tasks/{objectId}/associations/{toObjectType}/{toObjectId}", "/crm/objects/2026-09/tasks/{fromObjectId}/associations/default/{toObjectType}/{toObjectId}", "/crm/objects/2026-09/calls/{objectId}/associations/{toObjectType}/{toObjectId}", "/crm/objects/2026-09/calls/{fromObjectId}/associations/default/{toObjectType}/{toObjectId}", "/crm/objects/2026-09/meetings/{objectId}/associations/{toObjectType}/{toObjectId}", "/crm/objects/2026-09/meetings/{fromObjectId}/associations/default/{toObjectType}/{toObjectId}", "/crm/objects/2026-09/emails/{objectId}/associations/{toObjectType}/{toObjectId}", "/crm/objects/2026-09/emails/{fromObjectId}/associations/default/{toObjectType}/{toObjectId}" ] }, "action": { "headers": { "set": { "Authorization": "Bearer {{auth.oauth.access_token || auth.token.token}}" } } } }, { "if": "{{ allows access.engagements \"write\" }}", "match": { "protocol": "http", "host": [ "api.hubapi.com" ], "method": [ "DELETE" ], "path": [ "/crm/objects/2026-09/notes/{objectId}/associations/{toObjectType}/{toObjectId}", "/crm/objects/2026-09/tasks/{objectId}/associations/{toObjectType}/{toObjectId}", "/crm/objects/2026-09/calls/{objectId}/associations/{toObjectType}/{toObjectId}", "/crm/objects/2026-09/meetings/{objectId}/associations/{toObjectType}/{toObjectId}", "/crm/objects/2026-09/emails/{objectId}/associations/{toObjectType}/{toObjectId}" ] }, "action": { "headers": { "set": { "Authorization": "Bearer {{auth.oauth.access_token || auth.token.token}}" } } } } ] }icon.svg
README.md
--- description: Read and update HubSpot contacts, companies, deals, tickets and activities. --- # HubSpot Find and read your HubSpot contacts, companies, deals and tickets, see how they are linked to each other, and follow their notes, tasks, calls, meetings and logged emails. Agents can also look up deal and ticket pipelines and their stages, the account's owners, and the properties each kind of record has. Choose **None**, **Read** or **Write** separately for **Contacts**, **Companies**, **Deals**, **Tickets** and **Activities** (notes, tasks, calls, meetings and logged emails); each starts at **Read**. **Write** adds creating and updating those records, linking and unlinking them, and moving deals and tickets between stages. Owners are always readable. > The connection sees the whole HubSpot account, not only the records of the person > who connected it. HubSpot's permissions for the connected app or key still apply. Connect by signing in with HubSpot, or with an access token. Deleting records, bulk imports, custom objects, marketing tools and files are not available, and HubSpot's request limits apply.SETUP.md
# Connect HubSpot 1. Choose **None**, **Read** or **Write** for **Contacts**, **Companies**, **Deals**, **Tickets** and **Activities**, and select **Authorize connection**. 2. In HubSpot, choose the account to connect, review the permissions Houston asks for and select **Connect app**. > Connecting installs Houston's app in the HubSpot account, which needs a Super Admin > or a user with the **HubSpot Marketplace access** permission. Raising a level asks > HubSpot for the extra permissions again. HubSpot has no separate permissions for activities (notes, tasks, calls, meetings and logged emails), so Houston enforces the **Activities** level. ## Advanced ### Service key Choose **Service key or private app access token** in Houston. A Super Admin or a user with the **Developer tools access** permission can create a [service key](https://developers.hubspot.com/docs/apps/developer-platform/build-apps/authentication/account-service-keys) in HubSpot: 1. Go to **Development**, then **Keys** > **Service keys**, and select **Create service key**. 2. Enter a name, select **Add new scope**, tick the scopes below and select **Update**. 3. Select **Create** and confirm. 4. Open the key, select **Show**, then **Copy**, and paste it in Houston as **Access token**. Scopes to tick: | Access | Read | Write | | --- | --- | --- | | Always | `crm.objects.owners.read`, `sales-email-read` | | | Contacts | `crm.objects.contacts.read`, `crm.schemas.contacts.read` | also `crm.objects.contacts.write` | | Companies | `crm.objects.companies.read`, `crm.schemas.companies.read` | also `crm.objects.companies.write` | | Deals | `crm.objects.deals.read`, `crm.schemas.deals.read` | also `crm.objects.deals.write` | | Tickets | `crm.objects.tickets.read`, `crm.schemas.tickets.read` | also `crm.objects.tickets.write` | Houston still enforces each level you choose when the key allows more. ### Existing private app HubSpot stopped creating legacy private apps on October 26, 2026, but existing ones keep working. In HubSpot, go to **Development** > **Legacy apps**, open the app, then on the **Auth** tab select **Show token** and **Copy**. Paste it in Houston as **Access token**. An older app may hold the `tickets` scope instead of the `crm.objects.tickets` scopes; it covers tickets too. ### Missing data or permission errors - If agents report a missing scope, add it to the service key or private app (select **Edit** on the key), or connect again with HubSpot. - A rotated, expired or deleted key stops working: paste the new key in the connection. - To revoke Houston's access, uninstall Houston from the account's **Connected Apps** in HubSpot, or delete the key, then remove the connection in Houston. - HubSpot limits how many requests an app or key may make every 10 seconds, and service keys and private apps also share a daily quota for the account; busy accounts can briefly reach these limits.tests
authentication.luau
return { contract = function(m) m.authentication({ { auth = {}, config = {}, endpoint = {"GET", "https://api.hubapi.com/crm/owners/2026-09"}, expected = "Bearer synthetic-oauth-token", header = "Authorization", method = "oauth", oauth = true, publisher = {client_id = "synthetic-public-client", client_secret = "synthetic-client-secret"}, scopes = true, }, { auth = {token = "synthetic-method-secret"}, config = {}, endpoint = {"GET", "https://api.hubapi.com/crm/owners/2026-09"}, expected = "Bearer synthetic-method-secret", header = "Authorization", method = "token", publisher = {}, }, }) end, }errors.luau
return { scenario = {publisher = {}, access = {contacts = "write", companies = "write", deals = "write", tickets = "write", engagements = "write"}, config = {}, auth_method = "token", auth_config = {token = "fixture-token"}}, configure = function() calls = 0 status = 200 payload = "{}" responseHeaders = {} http = {request = function(req) calls += 1 return fixture.operation({statusCode = status, headers = responseHeaders, body = fixture.reader(payload)}) end} end, run = function(c) local names = {} for name in c do table.insert(names, name) end table.sort(names) assert(table.concat(names, ",") == "batchReadAssociations,batchReadObjects,createAssociation,createDefaultAssociation,createObject,deleteAssociation," .. "getObject,getOwner,getPipeline,getProperty,listAssociationLabels,listAssociations,listObjects,listOwners,listPipelines,listProperties," .. "searchObjects,updateObject", "token read-write got " .. table.concat(names, ",")) local CONTACT = {objectType = "contacts", objectId = "101"} local CREATE = {objectType = "contacts", properties = {email = "[email protected]"}} local UPDATE = {objectType = "deals", objectId = "9876", properties = {amount = "abc"}} local LINK = {objectType = "contacts", objectId = "101", toObjectType = "companies", toObjectId = "512", types = {{associationCategory = "HUBSPOT_DEFINED", associationTypeId = 1}}} local function upstream(code: number, body: string, headers: {[string]: {string}}, fn: (any) -> any, input: any, expected: {string}, absent: {string}?): string status, payload, responseHeaders = code, body, headers local before = calls local ok, err = pcall(fn, input) local message = tostring(err) assert(not ok, "call succeeded") for _, text in expected do assert(string.find(message, text, 1, true), "missing " .. text .. " in " .. message) end for _, text in absent or {} do assert(not string.find(message, text, 1, true), "unexpected " .. text .. " in " .. message) end assert(calls == before + 1, "a failed call was repeated") return message end upstream(401, '{"status":"error","message":"Authentication credentials not found.","correlationId":"c-401","category":"INVALID_AUTHENTICATION"}', {}, c.listOwners, nil, {"HubSpot HTTP 401 (INVALID_AUTHENTICATION): Authentication credentials not found.", "correlationId c-401", "check the connection's access token, or reconnect", '"retryable":false'}) upstream(403, json.encode({status = "error", message = "This app hasn't been granted all required scopes to make this call.", correlationId = "c-403", category = "MISSING_SCOPES", errors = {{message = "One or more of the following scopes are required.", context = {requiredGranularScopes = {"crm.objects.contacts.read", "crm.objects.contacts.sensitive.read"}}}}}), {}, c.getObject, CONTACT, {"HTTP 403 (MISSING_SCOPES)", "One or more of the following scopes are required.", "needs one of: crm.objects.contacts.read, crm.objects.contacts.sensitive.read", '"retryable":false'}) upstream(400, json.encode({status = "error", message = "Property values were not valid", correlationId = "c-400", category = "VALIDATION_ERROR", errors = {{message = "Property amount must be a number", code = "INVALID_DECIMAL", context = {propertyName = {"amount"}}}}}), {}, c.updateObject, UPDATE, {"HTTP 400 (VALIDATION_ERROR): Property values were not valid; Property amount must be a number", "correlationId c-400", '"retryable":false'}) -- Long bodies keep their category and cut messages; a body beyond the 16 KiB read for errors -- gives the status line alone. local long = upstream(400, json.encode({status = "error", category = "VALIDATION_ERROR", message = string.rep("x", 5000), errors = {{message = string.rep("y", 5000)}, {message = "second"}, {message = "third"}, {message = "fourth"}}}), {}, c.searchObjects, {objectType = "contacts"}, {"HTTP 400 (VALIDATION_ERROR): " .. string.rep("x", 600), string.rep("y", 200), "; second; third"}, {string.rep("x", 601), string.rep("y", 201), "fourth"}) assert(#long < 2000, "error message is not bounded: " .. #long) upstream(400, json.encode({status = "error", category = "VALIDATION_ERROR", message = string.rep("x", 20000)}), {}, c.searchObjects, {objectType = "contacts"}, {"HubSpot HTTP 400", '"retryable":false'}, {"VALIDATION_ERROR", "xxx"}) upstream(409, '{"status":"error","message":"Contact already exists. Existing ID: 101","category":"CONFLICT"}', {}, c.createObject, CREATE, {"HTTP 409 (CONFLICT): Contact already exists", '"retryable":false'}) -- Throttling: the rolling and per-second search limits pass; the daily limit lasts until midnight. upstream(429, '{"status":"error","message":"You have reached your ten_secondly_rolling limit.","errorType":"RATE_LIMIT","correlationId":"c-429","policyName":"TEN_SECONDLY_ROLLING"}', {}, c.listObjects, {objectType = "contacts"}, {"HTTP 429 (RATE_LIMIT)", "policy TEN_SECONDLY_ROLLING", '"retryable":true'}) upstream(429, '{"status":"error","message":"You have reached your daily limit.","errorType":"RATE_LIMIT","policyName":"DAILY"}', {}, c.createObject, CREATE, {"HTTP 429 (RATE_LIMIT): You have reached your daily limit.", "policy DAILY", '"retryable":false'}) upstream(429, '{"status":"error","message":"You have reached your secondly limit.","errorType":"RATE_LIMIT"}', {}, c.searchObjects, {objectType = "deals"}, {"HTTP 429", "secondly limit", '"retryable":true'}) -- Access tokens also report the daily quota in a header, which decides even when the body is unreadable. local SPENT = {["x-hubspot-ratelimit-daily-remaining"] = {"0"}} upstream(429, "<html>Too many requests</html>", SPENT, c.listObjects, {objectType = "deals"}, {"HubSpot HTTP 429", "daily limit reached", '"retryable":false'}) upstream(429, json.encode({status = "error", errorType = "RATE_LIMIT", policyName = "DAILY", message = string.rep("x", 20000)}), SPENT, c.getObject, CONTACT, {"HubSpot HTTP 429", "daily limit reached", '"retryable":false'}) upstream(429, '{"status":"error","errorType":"RATE_LIMIT","policyName":"TEN_SECONDLY_ROLLING"}', SPENT, c.listOwners, nil, {"policy TEN_SECONDLY_ROLLING", "daily limit reached", '"retryable":false'}) upstream(429, "<html>Too many requests</html>", {["x-hubspot-ratelimit-daily-remaining"] = {"5000"}}, c.listObjects, {objectType = "deals"}, {"HubSpot HTTP 429", '"retryable":true'}, {"daily limit"}) upstream(423, '{"status":"error","message":"Locked"}', {}, c.createAssociation, LINK, {"HubSpot HTTP 423: Locked", '"retryable":true'}) upstream(477, '{"status":"error","message":"Migration in progress"}', {["retry-after"] = {"3600"}}, c.getObject, CONTACT, {"HTTP 477", "Retry-After: 3600", '"retryable":true'}) -- Server errors: reads, updates and association changes are safe to repeat; a create may have been applied. upstream(502, "<html><body>Bad gateway</body></html>", {}, c.listObjects, {objectType = "deals"}, {"HubSpot HTTP 502", '"retryable":true'}, {"html"}) upstream(502, "", {}, c.updateObject, UPDATE, {"HubSpot HTTP 502", '"retryable":true'}) upstream(500, '{"status":"error","message":"internal error"}', {}, c.createObject, CREATE, {"HTTP 500: internal error", '"retryable":false'}) upstream(500, '{"status":"error","message":"internal error"}', {}, c.createAssociation, LINK, {"HTTP 500: internal error", '"retryable":true'}) upstream(503, "", {}, c.createDefaultAssociation, {fromObjectType = "contacts", fromObjectId = "101", toObjectType = "companies", toObjectId = "512"}, {"HubSpot HTTP 503", '"retryable":true'}) upstream(504, "", {}, c.deleteAssociation, {objectType = "contacts", objectId = "101", toObjectType = "companies", toObjectId = "512"}, {"HubSpot HTTP 504", '"retryable":true'}) upstream(404, "<!DOCTYPE html><html><head><title>Not found</title></head></html>", {}, c.getProperty, {objectType = "contacts", propertyName = "missing"}, {"HubSpot HTTP 404", '"retryable":false'}, {"html", "Not found"}) -- A success must carry a JSON object. upstream(200, "<html>Maintenance</html>", {}, c.getObject, CONTACT, {"HubSpot returned an invalid JSON object", '"retryable":false'}) upstream(200, "[]", {}, c.listObjects, {objectType = "contacts"}, {"invalid JSON object"}) -- Only deleteAssociation answers with an empty body (204); any other empty success is malformed. upstream(200, "", {}, c.getObject, CONTACT, {"invalid JSON object"}) upstream(201, "", {}, c.createObject, CREATE, {"invalid JSON object", '"retryable":false'}) upstream(204, "", {}, c.createAssociation, LINK, {"invalid JSON object"}) end, }examples.luau
-- Every documented example runs as a real call against a permissive HubSpot mock; full access -- documents every operation. Each operation's examples come from its help record: indexes are tried -- until the record has no more, so a new example cannot be skipped. local function run(c) local names = {} for name in c do table.insert(names, name) end table.sort(names) local count = 0 for _, name in names do local index = 1 while true do local ok, err = pcall(fixture.example, name, index) if not ok then assert(index > 1 and string.find(tostring(err), "example index out of range", 1, true), name .. " example " .. index .. ": " .. tostring(err)) break end count += 1 index += 1 end end assert(calls == count, "an example made no request, or more than one") end local function configure() calls = 0 http = {request = function(req) calls += 1 assert(string.find(req.url, "https://api.hubapi.com/crm/", 1, true) == 1, req.url) return fixture.operation({statusCode = 200, headers = {}, body = fixture.reader('{"id":"1","results":[],"total":0}')}) end} end local scenario = {publisher = {client_id = "fixture-client", client_secret = "fixture-private-secret"}, config = {}, auth_method = "oauth", auth_config = {}} return {scenario = scenario, access = {contacts = "write", companies = "write", deals = "write", tickets = "write", engagements = "write"}, configure = configure, run = run}manifest.luau
local API = "https://api.hubapi.com" local OBJECTS = API .. "/crm/objects/2026-09/" -- Each access row and the object types it covers. local ROWS = { contacts = {"contacts"}, companies = {"companies"}, deals = {"deals"}, tickets = {"tickets"}, engagements = {"notes", "tasks", "calls", "meetings", "emails"}, } local RANK = {none = 0, read = 1, write = 2} -- The OAuth scopes of the schema version 1 read-only and read-write choices, which the default -- levels and every row at write must request unchanged. local READ_SCOPES = { "oauth", "crm.objects.contacts.read", "crm.objects.companies.read", "crm.objects.deals.read", "crm.objects.tickets.read", "crm.objects.owners.read", "crm.schemas.contacts.read", "crm.schemas.companies.read", "crm.schemas.deals.read", "crm.schemas.tickets.read", "sales-email-read", } local WRITE_SCOPES = {"crm.objects.contacts.write", "crm.objects.companies.write", "crm.objects.deals.write", "crm.objects.tickets.write"} local function reads(row: string): {string} local routes = {} for _, kind in ROWS[row] do table.insert(routes, "GET " .. OBJECTS .. kind .. "?limit=100&properties=hs_timestamp,hubspot_owner_id") table.insert(routes, "GET " .. OBJECTS .. kind .. "/101") table.insert(routes, "GET " .. OBJECTS .. kind .. "/sku%3A123?idProperty=sku") table.insert(routes, "GET " .. OBJECTS .. kind .. "/101/associations/contacts?limit=500&after=x1") table.insert(routes, "POST " .. OBJECTS .. kind .. "/search") table.insert(routes, "POST " .. OBJECTS .. kind .. "/batch/read?archived=true") table.insert(routes, "GET " .. API .. "/crm/properties/2026-09/" .. kind .. "?archived=true") table.insert(routes, "GET " .. API .. "/crm/properties/2026-09/" .. kind .. "/hs_timestamp") end if row == "deals" or row == "tickets" then table.insert(routes, "GET " .. API .. "/crm/pipelines/2026-09/" .. row) table.insert(routes, "GET " .. API .. "/crm/pipelines/2026-09/" .. row .. "/0") end return routes end local function writes(row: string): {string} local routes = {} for _, kind in ROWS[row] do table.insert(routes, "POST " .. OBJECTS .. kind) table.insert(routes, "PATCH " .. OBJECTS .. kind .. "/101?idProperty=email") table.insert(routes, "PATCH " .. OBJECTS .. kind .. "/sku%3A123?idProperty=sku") table.insert(routes, "PUT " .. OBJECTS .. kind .. "/101/associations/companies/512") table.insert(routes, "PUT " .. OBJECTS .. kind .. "/101/associations/default/companies/512") table.insert(routes, "DELETE " .. OBJECTS .. kind .. "/101/associations/companies/512") end return routes end return { contract = function(m) -- Association batch reads and labels name both object types in placeholders, and owners -- belong to no row, so they are available at every level. local base = { "POST " .. API .. "/crm/associations/2026-09/deals/companies/batch/read", "GET " .. API .. "/crm/associations/2026-09/contacts/companies/labels", "GET " .. API .. "/crm/owners/2026-09?email=ana%40example.com&limit=500", "GET " .. API .. "/crm/owners/2026-09/41629779?idProperty=userId", } -- The token never reaches HubSpot's OAuth endpoints (token exchange, introspection, revocation, -- or /oauth/v1/access-tokens, which echoes the token), account details, other hosts, record -- deletes, bulk writes, merges, schema administration, other object types or API versions. -- Some routes stay reachable although the connector never sends them. An {objectId} placeholder -- admits any one segment, and /crm/properties/2026-09/<type>/{propertyName} also admits -- "groups" (property groups); both are GET and expose nothing beyond the granted scopes. The -- {fromObjectType} and {toObjectType} placeholders of the association routes admit any object type, -- such as quotes: a manifest cannot constrain placeholder values, and listing every pair of the -- nine types would take about 500 paths. Luau bounds them to the nine types, and the token's scopes -- bound what HubSpot answers. local anyTypeReads = { "GET " .. API .. "/crm/associations/2026-09/contacts/quotes/labels", "POST " .. API .. "/crm/associations/2026-09/quotes/contacts/batch/read", } local contactsToAnyType = {"GET " .. OBJECTS .. "contacts/101/associations/quotes"} local contactsToAnyTypeWrites = { "PUT " .. OBJECTS .. "contacts/101/associations/quotes/7", "PUT " .. OBJECTS .. "contacts/101/associations/default/quotes/7", "DELETE " .. OBJECTS .. "contacts/101/associations/quotes/7", } local denied = { "POST " .. API .. "/oauth/2026-09/token", "POST " .. API .. "/oauth/v3/token", "POST " .. API .. "/oauth/v1/token", "GET " .. API .. "/oauth/v1/access-tokens/fixture-token", "GET " .. API .. "/oauth/v1/refresh-tokens/x", "DELETE " .. API .. "/oauth/v1/refresh-tokens/x", "POST " .. API .. "/oauth/2026-09/token/introspect", "POST " .. API .. "/oauth/2026-09/token/revoke", "POST " .. API .. "/oauth/v2/private-apps/get/access-token-info", "POST https://api.hubspot.com/oauth/2026-09/token", "GET https://api.hubspot.com/crm/owners/2026-09", "GET https://api.hubapi.com.evil.test/crm/owners/2026-09", "GET https://api-eu1.hubapi.com/crm/owners/2026-09", "GET https://app.hubspot.com/oauth/authorize", "GET " .. API .. "/account-info/2026-09/details", "DELETE " .. OBJECTS .. "contacts/101", "POST " .. OBJECTS .. "contacts/batch/create", "POST " .. OBJECTS .. "contacts/batch/update", "POST " .. OBJECTS .. "contacts/batch/upsert", "POST " .. OBJECTS .. "contacts/batch/archive", "POST " .. OBJECTS .. "contacts/merge", "POST " .. OBJECTS .. "contacts/gdpr-delete", "PUT " .. OBJECTS .. "contacts/101", "POST " .. API .. "/crm/associations/2026-09/contacts/companies/batch/create", "POST " .. API .. "/crm/associations/2026-09/contacts/companies/batch/archive", "POST " .. API .. "/crm/associations/2026-09/contacts/companies/batch/associate/default", "POST " .. API .. "/crm/associations/2026-09/contacts/companies/labels", "DELETE " .. API .. "/crm/associations/2026-09/contacts/companies/labels/36", "GET " .. API .. "/crm/associations/2026-09/definitions/configurations/all", "POST " .. API .. "/crm/pipelines/2026-09/deals", "DELETE " .. API .. "/crm/pipelines/2026-09/deals/default", "PATCH " .. API .. "/crm/pipelines/2026-09/deals/default", "GET " .. API .. "/crm/pipelines/2026-09/deals/default/audit", "POST " .. API .. "/crm/properties/2026-09/contacts", "PATCH " .. API .. "/crm/properties/2026-09/contacts/email", "DELETE " .. API .. "/crm/properties/2026-09/contacts/email", "GET " .. OBJECTS .. "products", "GET " .. OBJECTS .. "users", "GET " .. OBJECTS .. "2-1234", "POST " .. OBJECTS .. "products", "GET " .. API .. "/crm/objects/v3/contacts", "GET " .. API .. "/crm/v3/objects/contacts", "GET " .. API .. "/crm/objects/2026-03/contacts", "GET " .. API .. "/crm/pipelines/2026-09/orders", "GET " .. OBJECTS .. "contacts/%2e%2e/users", "GET " .. OBJECTS .. "contacts/101/../../users", "GET " .. OBJECTS .. "contacts/101%2Fassociations/companies", } -- The default levels, every row at write, every row at none, then each row alone at write. local cases: {{[string]: string}} = { {}, {contacts = "write", companies = "write", deals = "write", tickets = "write", engagements = "write"}, {contacts = "none", companies = "none", deals = "none", tickets = "none", engagements = "none"}, } for row in ROWS do local access = {contacts = "none", companies = "none", deals = "none", tickets = "none", engagements = "none"} access[row] = "write" table.insert(cases, access) end local publisher = {client_id = "publisher-client", client_secret = "publisher-secret"} for index, access in cases do local function rank(row: string): number return RANK[access[row] or "read"] end local scopes = {"oauth", "crm.objects.owners.read", "sales-email-read"} for row in ROWS do if row == "engagements" then continue end if rank(row) >= 1 then table.insert(scopes, "crm.objects." .. row .. ".read"); table.insert(scopes, "crm.schemas." .. row .. ".read") end if rank(row) == 2 then table.insert(scopes, "crm.objects." .. row .. ".write") end end if index == 1 then m.sortedEqual(m.concat(READ_SCOPES), scopes) end if index == 2 then m.sortedEqual(m.concat(READ_SCOPES, WRITE_SCOPES), scopes) end -- A manual token follows the same proxy rules, so the default and full levels cover it. for _, method in if index <= 2 then {"oauth", "token"} else {"oauth"} do local r, err = m.resolve(if method == "oauth" then publisher else nil, {}, if method == "token" then {token = "fixture-token"} else nil, method, access) assert(r and not err, tostring(err)) if method == "oauth" then m.sortedEqual(m.concat(scopes), m.concat(r.Scopes)) r.Context.Auth.oauth.access_token = "fixture-token" else assert(m.count(r.Scopes) == 0, "a manual token requests no scopes") end m.routes(r, "Bearer fixture-token", true, m.concat(base, anyTypeReads)) for row in ROWS do m.routes(r, "Bearer fixture-token", rank(row) >= 1, reads(row)) m.routes(r, "Bearer fixture-token", rank(row) == 2, writes(row)) if index == 2 and method == "oauth" then m.rejectOverrides(r, m.concat(reads(row), writes(row))) end end if index == 2 and method == "oauth" then m.rejectOverrides(r, base) end m.routes(r, "Bearer fixture-token", rank("contacts") >= 1, contactsToAnyType) m.routes(r, "Bearer fixture-token", rank("contacts") == 2, contactsToAnyTypeWrites) m.routes(r, "Bearer fixture-token", false, denied) end end local result, err = m.exports({}, "token", nil, nil, cases[3]) assert(result and not err, tostring(err)) assert(result.type == "result" and m.equal(result.exports, {"getOwner", "listOwners"}), "every row at none keeps only owners") assert(string.find(result.help, "This connection reads no records: only owners are available.", 1, true), result.help) result, err = m.exports({}, "token", nil, nil, {contacts = "write", companies = "none", deals = "read", tickets = "none", engagements = "none"}) assert(result and not err and result.type == "result", tostring(err)) assert(string.find(result.help, "objectType is one of contacts, deals; writes take contacts.", 1, true), result.help) end, }oauth_read_only.luau
return { scenario = {publisher = {client_id = "fixture-client", client_secret = "fixture-private-secret"}, config = {}, auth_method = "oauth", auth_config = {}}, configure = function() requests, responses = {}, {} http = {request = function(req) for name in req.headers or {} do assert(string.lower(name) ~= "authorization", "the proxy injects Authorization") end table.insert(requests, req) assert(#responses > 0, "unexpected request: " .. req.url) local response = table.remove(responses, 1) return fixture.operation({statusCode = response.status or 200, headers = response.headers or {}, body = fixture.reader(response.body or "")}) end} end, run = function(c) local OBJECTS = "https://api.hubapi.com/crm/objects/2026-09/" local function last() return requests[#requests] end local names = {} for name in c do table.insert(names, name) end table.sort(names) assert(table.concat(names, ",") == "batchReadAssociations,batchReadObjects,getObject,getOwner,getPipeline,getProperty,listAssociationLabels," .. "listAssociations,listObjects,listOwners,listPipelines,listProperties,searchObjects", "read-only got " .. table.concat(names, ",")) responses = {{body = '{"id":"9876","properties":{"dealname":"Renewal","dealstage":"contractsent"}}'}, {body = '{"total":0,"results":[]}'}} assert(c.getObject({objectType = "deals", objectId = "9876", properties = {"dealname", "dealstage"}}).properties.dealstage == "contractsent") assert(last().method == "GET" and last().url == OBJECTS .. "deals/9876?properties=dealname,dealstage" and last().body == nil, last().url) local search = {filterGroups = {{filters = {{propertyName = "hs_task_status", operator = "NEQ", value = "COMPLETED"}}}}, limit = 50} local found = c.searchObjects({objectType = "tasks", filterGroups = search.filterGroups, limit = search.limit}) assert(found.total == 0 and json.encode(found.results) == "[]") assert(last().method == "POST" and last().url == OBJECTS .. "tasks/search" and last().headers["Content-Type"][1] == "application/json", last().url) assert(json.encode(json.decode(last().body)) == json.encode(search), last().body) assert(#requests == 2 and #responses == 0) end, }partial_access.luau
return { scenario = {publisher = {}, access = {contacts = "write", companies = "none", deals = "read", tickets = "none", engagements = "none"}, config = {}, auth_method = "token", auth_config = {token = "fixture-token"}}, configure = function() requests = {} http = {request = function(req) table.insert(requests, req) return fixture.operation({statusCode = 200, headers = {}, body = fixture.reader('{"id":"1","results":[]}')}) end} end, run = function(c) local OBJECTS = "https://api.hubapi.com/crm/objects/2026-09/" local names = {} for name in c do table.insert(names, name) end table.sort(names) assert(table.concat(names, ",") == "batchReadAssociations,batchReadObjects,createAssociation,createDefaultAssociation,createObject,deleteAssociation," .. "getObject,getOwner,getPipeline,getProperty,listAssociationLabels,listAssociations,listObjects,listOwners,listPipelines,listProperties," .. "searchObjects,updateObject", "partial access got " .. table.concat(names, ",")) local function fails(expected: string, fn: (any) -> any, input: any) local before = #requests local ok, err = pcall(fn, input) assert(not ok and string.find(tostring(err), expected, 1, true), tostring(err)) assert(#requests == before, "a refused call reached HubSpot") end fails("objectType must be one of contacts, deals", c.getObject, {objectType = "companies", objectId = "512"}) fails("objectType must be one of contacts, deals", c.searchObjects, {objectType = "notes"}) fails("associations[1] must be one of contacts, deals", c.listObjects, {objectType = "contacts", associations = {"tickets"}}) fails("objectType must be one of deals", c.listPipelines, {objectType = "tickets"}) fails("objectType must be one of contacts", c.createObject, {objectType = "deals", properties = {dealname = "Renewal"}}) fails("objectType must be one of contacts", c.updateObject, {objectType = "deals", objectId = "9876", properties = {amount = "1"}}) fails("toObjectType must be one of contacts, deals", c.createDefaultAssociation, {fromObjectType = "contacts", fromObjectId = "101", toObjectType = "companies", toObjectId = "512"}) fails("objectType must be one of contacts", c.deleteAssociation, {objectType = "deals", objectId = "9876", toObjectType = "contacts", toObjectId = "101"}) c.listPipelines({objectType = "deals"}) c.createDefaultAssociation({fromObjectType = "contacts", fromObjectId = "101", toObjectType = "deals", toObjectId = "9876"}) assert(#requests == 2 and requests[1].url == "https://api.hubapi.com/crm/pipelines/2026-09/deals" and requests[2].method == "PUT" and requests[2].url == OBJECTS .. "contacts/101/associations/default/deals/9876", requests[#requests].url) end, }read_only.luau
return { scenario = {publisher = {}, config = {}, auth_method = "token", auth_config = {token = "fixture-token"}}, configure = function() requests, responses = {}, {} http = {request = function(req) for name in req.headers or {} do assert(string.lower(name) ~= "authorization", "the proxy injects Authorization") end table.insert(requests, req) assert(#responses > 0, "unexpected request: " .. req.url) local response = table.remove(responses, 1) return fixture.operation({statusCode = response.status or 200, headers = response.headers or {}, body = fixture.reader(response.body or "")}) end} end, run = function(c) local API = "https://api.hubapi.com" local OBJECTS = API .. "/crm/objects/2026-09/" local SEGMENT = "must be one nonempty URL path segment" local function last() return requests[#requests] end local function same(a: any, b: any): boolean if type(a) ~= "table" or type(b) ~= "table" then return a == b end for key, value in a do if not same(value, b[key]) then return false end end for key in b do if a[key] == nil then return false end end return true end local function get(href: string) assert(last().method == "GET" and last().url == href and last().body == nil, last().method .. " " .. last().url) end local function post(href: string, expected: any) assert(last().method == "POST" and last().url == href, last().method .. " " .. last().url) assert(last().headers["Content-Type"][1] == "application/json", "JSON body without Content-Type") assert(same(json.decode(last().body), expected), "unexpected body " .. last().body) end local function empty(value: any) assert(#value.results == 0 and json.encode(value.results) == "[]", json.encode(value)) end local function fails(expected: {string}, fn: (...any) -> any, ...: any) local ok, err = pcall(fn, ...) assert(not ok, "call succeeded") for _, text in expected do assert(string.find(tostring(err), text, 1, true), "missing " .. text .. " in " .. tostring(err)) end end local names = {} for name in c do table.insert(names, name) end table.sort(names) assert(table.concat(names, ",") == "batchReadAssociations,batchReadObjects,getObject,getOwner,getPipeline,getProperty,listAssociationLabels," .. "listAssociations,listObjects,listOwners,listPipelines,listProperties,searchObjects", "read-only got " .. table.concat(names, ",")) -- Records: one page at a time, query lists comma-separated in a fixed order, archived only when true. responses = { {body = '{"results":[{"id":"101","properties":{"email":"[email protected]","firstname":"Ana"},"archived":false}],"paging":{"next":{"after":"102","link":"x"}}}'}, {body = '{"results":[]}'}, {body = '{}'}, {body = '{"results":[]}'}, {body = '{"id":"101","properties":{"email":"[email protected]"},"associations":{"companies":{"results":[{"id":"512","type":"contact_to_company"}]}}}'}, {body = '{"id":"512","properties":{"name":"Acme"}}'}, } local page = c.listObjects({objectType = "contacts", limit = 2, after = "100", properties = {"email", "first name"}, propertiesWithHistory = {"lifecyclestage"}, associations = {"companies", "deals"}, archived = true}) get(OBJECTS .. "contacts?limit=2&after=100&properties=email,first%20name&propertiesWithHistory=lifecyclestage&associations=companies,deals&archived=true") assert(page.results[1].properties.firstname == "Ana" and page.paging.next.after == "102", json.encode(page)) empty(c.listObjects({objectType = "contacts", after = page.paging.next.after})) get(OBJECTS .. "contacts?after=102") empty(c.listObjects({objectType = "deals", archived = false})) get(OBJECTS .. "deals") -- A cursor cannot add query parameters of its own. empty(c.listObjects({objectType = "contacts", after = "1&archived=true"})) get(OBJECTS .. "contacts?after=1%26archived%3Dtrue") local contact = c.getObject({objectType = "contacts", objectId = "[email protected]", idProperty = "email", properties = {"email"}, associations = {"companies"}}) get(OBJECTS .. "contacts/ana%40example.com?idProperty=email&properties=email&associations=companies") assert(contact.associations.companies.results[1].id == "512", json.encode(contact)) assert(c.getObject({objectType = "companies", objectId = "512", propertiesWithHistory = {"name"}, archived = true}).properties.name == "Acme") get(OBJECTS .. "companies/512?propertiesWithHistory=name&archived=true") -- A unique property value may hold characters such as a colon, sent percent-encoded. responses = {{body = '{"id":"77","properties":{"sku":"sku:123"}}'}} assert(c.getObject({objectType = "contacts", objectId = "sku:123", idProperty = "sku"}).id == "77") get(OBJECTS .. "contacts/sku%3A123?idProperty=sku") -- Search and batch reads POST exactly the given fields; 207 partial batches are results. responses = { {body = '{"total":1,"results":[{"id":"9876","properties":{"dealname":"Renewal"}}],"paging":{"next":{"after":"21"}}}'}, {body = '{"total":0,"results":[]}'}, {status = 207, body = '{"status":"COMPLETE","results":[{"id":"101"}],"numErrors":1,"errors":[{"status":"error","category":"OBJECT_NOT_FOUND","message":"Could not get some CONTACT objects"}]}'}, {body = '{"status":"COMPLETE","results":[{"id":"101","properties":{"email":"[email protected]"}}]}'}, {body = '{"status":"COMPLETE","results":[]}'}, {body = '{"status":"COMPLETE"}'}, } local filterGroups = {{filters = {{propertyName = "dealstage", operator = "EQ", value = "contractsent"}}}, {filters = {{propertyName = "amount", operator = "BETWEEN", value = "1000", highValue = "5000"}, {propertyName = "hs_tag_ids", operator = "IN", values = {"a", "b"}}}}} local sorts = {{propertyName = "closedate", direction = "ASCENDING"}} local found = c.searchObjects({objectType = "deals", query = "renewal", filterGroups = filterGroups, sorts = sorts, properties = {"dealname"}, limit = 200, after = "20"}) assert(found.total == 1 and found.results[1].id == "9876" and found.paging.next.after == "21") post(OBJECTS .. "deals/search", {query = "renewal", filterGroups = filterGroups, sorts = sorts, properties = {"dealname"}, limit = 200, after = "20"}) local none = c.searchObjects({objectType = "notes"}) empty(none) assert(none.total == 0 and last().body == "{}", last().body) post(OBJECTS .. "notes/search", {}) local batch = c.batchReadObjects({objectType = "contacts", inputs = {{id = "101"}, {id = "999"}}, properties = {"email"}, propertiesWithHistory = {"lifecyclestage"}, archived = true}) assert(batch.results[1].id == "101" and batch.numErrors == 1 and batch.errors[1].category == "OBJECT_NOT_FOUND") post(OBJECTS .. "contacts/batch/read?archived=true", {inputs = {{id = "101"}, {id = "999"}}, properties = {"email"}, propertiesWithHistory = {"lifecyclestage"}}) c.batchReadObjects({objectType = "contacts", idProperty = "email", inputs = {{id = "[email protected]"}}}) post(OBJECTS .. "contacts/batch/read", {idProperty = "email", inputs = {{id = "[email protected]"}}}) -- Body IDs are JSON values, not path segments: any nonempty unique value goes out unchanged. empty(c.batchReadObjects({objectType = "companies", idProperty = "path", inputs = {{id = "a/b"}, {id = "50%"}, {id = ".."}}})) post(OBJECTS .. "companies/batch/read", {idProperty = "path", inputs = {{id = "a/b"}, {id = "50%"}, {id = ".."}}}) empty(c.batchReadObjects({objectType = "tickets", inputs = {{id = "5"}}})) post(OBJECTS .. "tickets/batch/read", {inputs = {{id = "5"}}}) -- Associations between records, read one record or many at a time, and their labels. responses = { {body = '{"results":[{"toObjectId":101,"associationTypes":[{"category":"HUBSPOT_DEFINED","typeId":3,"label":null}]}],"paging":{"next":{"after":"x2"}}}'}, {body = '{"results":[]}'}, {status = 207, body = '{"status":"COMPLETE","results":[{"from":{"id":"9876"},"to":[{"toObjectId":512,"associationTypes":[{"category":"HUBSPOT_DEFINED","typeId":5,"label":"Primary"}]}]}],"errors":[{"status":"error","category":"OBJECT_NOT_FOUND"}]}'}, {body = '{"status":"COMPLETE","results":[]}'}, {body = '{"results":[{"category":"HUBSPOT_DEFINED","typeId":1,"label":"Primary"},{"category":"USER_DEFINED","typeId":36,"label":"Decision maker"}]}'}, {body = '{"results":[]}'}, } local linked = c.listAssociations({objectType = "deals", objectId = "9876", toObjectType = "contacts", limit = 500, after = "x1"}) get(OBJECTS .. "deals/9876/associations/contacts?limit=500&after=x1") assert(linked.results[1].toObjectId == 101 and linked.paging.next.after == "x2") empty(c.listAssociations({objectType = "contacts", objectId = "101", toObjectType = "notes"})) get(OBJECTS .. "contacts/101/associations/notes") local many = c.batchReadAssociations({fromObjectType = "deals", toObjectType = "companies", inputs = {{id = "9876"}, {id = "9877", after = "abc"}}}) assert(many.results[1].to[1].associationTypes[1].label == "Primary" and many.errors[1].category == "OBJECT_NOT_FOUND") post(API .. "/crm/associations/2026-09/deals/companies/batch/read", {inputs = {{id = "9876"}, {id = "9877", after = "abc"}}}) empty(c.batchReadAssociations({fromObjectType = "contacts", toObjectType = "notes", inputs = {{id = "101"}}})) post(API .. "/crm/associations/2026-09/contacts/notes/batch/read", {inputs = {{id = "101"}}}) assert(c.listAssociationLabels({fromObjectType = "contacts", toObjectType = "companies"}).results[2].typeId == 36) get(API .. "/crm/associations/2026-09/contacts/companies/labels") empty(c.listAssociationLabels({fromObjectType = "tickets", toObjectType = "deals"})) get(API .. "/crm/associations/2026-09/tickets/deals/labels") -- Pipelines, owners and property definitions. responses = { {body = '{"results":[{"id":"default","label":"Sales Pipeline","stages":[{"id":"appointmentscheduled","label":"Appointment scheduled","metadata":{"probability":"0.2"}}]}]}'}, {body = '{"results":[]}'}, {body = '{"id":"0","label":"Support Pipeline","stages":[{"id":"1","metadata":{"ticketState":"OPEN"}}]}'}, {body = '{"results":[{"id":"41629779","email":"[email protected]","userId":9586504,"type":"PERSON","teams":[]}],"paging":{"next":{"after":"6"}}}'}, {body = '{"results":[]}'}, {body = '{"id":"41629779","userId":9586504,"firstName":"Ana"}'}, {body = '{"results":[{"name":"dealstage","type":"enumeration","options":[{"label":"Closed won","value":"closedwon"}]}]}'}, {body = '{}'}, {body = '{"name":"hs_task_status","options":[{"value":"NOT_STARTED"},{"value":"COMPLETED"}]}'}, } assert(c.listPipelines({objectType = "deals"}).results[1].stages[1].id == "appointmentscheduled") get(API .. "/crm/pipelines/2026-09/deals") empty(c.listPipelines({objectType = "tickets"})) get(API .. "/crm/pipelines/2026-09/tickets") assert(c.getPipeline({objectType = "tickets", pipelineId = "0"}).stages[1].metadata.ticketState == "OPEN") get(API .. "/crm/pipelines/2026-09/tickets/0") local owners = c.listOwners({email = "[email protected]", limit = 500, after = "5", archived = true}) get(API .. "/crm/owners/2026-09?email=ana%40example.com&limit=500&after=5&archived=true") assert(owners.results[1].id == "41629779" and owners.paging.next.after == "6") empty(c.listOwners()) get(API .. "/crm/owners/2026-09") assert(c.getOwner({ownerId = "9586504", idProperty = "userId", archived = true}).firstName == "Ana") get(API .. "/crm/owners/2026-09/9586504?idProperty=userId&archived=true") assert(c.listProperties({objectType = "deals", archived = true}).results[1].options[1].value == "closedwon") get(API .. "/crm/properties/2026-09/deals?archived=true") empty(c.listProperties({objectType = "emails"})) get(API .. "/crm/properties/2026-09/emails") assert(c.getProperty({objectType = "tasks", propertyName = "hs_task_status"}).options[2].value == "COMPLETED") get(API .. "/crm/properties/2026-09/tasks/hs_task_status") assert(#responses == 0) -- Invalid input never reaches the network. local before = #requests local TYPE = "objectType must be one of contacts, companies, deals, tickets, notes, tasks, calls, meetings, emails" fails({"options must be an object"}, c.listObjects, "contacts") fails({"listObjects received an unknown option sort"}, c.listObjects, {objectType = "contacts", sort = "email"}) fails({TYPE}, c.listObjects, {}) fails({TYPE}, c.listObjects, {objectType = "products"}) fails({TYPE}, c.searchObjects, {objectType = "Contacts"}) fails({"toObjectType must be one of"}, c.listAssociations, {objectType = "deals", objectId = "1", toObjectType = "products"}) fails({"fromObjectType must be one of"}, c.batchReadAssociations, {fromObjectType = "2-1234", toObjectType = "deals", inputs = {{id = "1"}}}) -- The proxy admits any association type, so Luau keeps it to the nine. fails({"toObjectType must be one of"}, c.listAssociations, {objectType = "contacts", objectId = "101", toObjectType = "quotes"}) fails({"toObjectType must be one of"}, c.listAssociationLabels, {fromObjectType = "contacts", toObjectType = "quotes"}) fails({"fromObjectType must be one of"}, c.batchReadAssociations, {fromObjectType = "quotes", toObjectType = "contacts", inputs = {{id = "7"}}}) fails({"objectId must be a string of digits"}, c.getObject, {objectType = "contacts", objectId = 101}) fails({"objectId must be a string of digits"}, c.getObject, {objectType = "contacts", objectId = "abc"}) fails({"objectId must be a string of digits"}, c.getObject, {objectType = "contacts", objectId = "../users"}) fails({"objectId must be a string of digits"}, c.listAssociations, {objectType = "contacts", objectId = "[email protected]", toObjectType = "companies"}) fails({"objectId " .. SEGMENT}, c.getObject, {objectType = "contacts", objectId = "../users", idProperty = "email"}) fails({"objectId " .. SEGMENT}, c.getObject, {objectType = "contacts", objectId = "a/b", idProperty = "email"}) for _, limit in {0, 101, 1.5, "10"} do fails({"limit must be an integer from 1 to 100"}, c.listObjects, {objectType = "contacts", limit = limit}) end fails({"limit must be an integer from 1 to 500"}, c.listOwners, {limit = 501}) fails({"archived must be a boolean"}, c.listObjects, {objectType = "contacts", archived = "true"}) fails({"after must be a nonempty string"}, c.listObjects, {objectType = "contacts", after = 102}) fails({"associations[1] must be one of"}, c.listObjects, {objectType = "contacts", associations = {"products"}}) local filter = {propertyName = "email", operator = "HAS_PROPERTY"} local function groups(count: number, size: number) local list = {} for _ = 1, count do local filters = {} for _ = 1, size do table.insert(filters, filter) end table.insert(list, {filters = filters}) end return list end fails({"filterGroups must be an array of 1 to 5 items"}, c.searchObjects, {objectType = "contacts", filterGroups = groups(6, 1)}) fails({"filterGroups[1].filters must be an array of 1 to 6 items"}, c.searchObjects, {objectType = "contacts", filterGroups = groups(1, 7)}) fails({"at most 18 filters in all"}, c.searchObjects, {objectType = "contacts", filterGroups = groups(4, 5)}) fails({"filterGroups[1] received an unknown field filter"}, c.searchObjects, {objectType = "contacts", filterGroups = {{filter = {filter}}}}) fails({"filterGroups[1].filters[1] must be an object"}, c.searchObjects, {objectType = "contacts", filterGroups = {{filters = {"email"}}}}) fails({"sorts must be an array of 1 to 1 items"}, c.searchObjects, {objectType = "contacts", sorts = {{propertyName = "a"}, {propertyName = "b"}}}) local function search(f: any, s: any?) return {objectType = "contacts", filterGroups = {{filters = {f}}}, sorts = s} end local FILTER = "filterGroups[1].filters[1]" local OPERATORS = "EQ, NEQ, LT, LTE, GT, GTE, BETWEEN, IN, NOT_IN, HAS_PROPERTY, NOT_HAS_PROPERTY, CONTAINS_TOKEN, NOT_CONTAINS_TOKEN" fails({FILTER .. ".operator must be one of " .. OPERATORS}, c.searchObjects, search({propertyName = "email"})) fails({FILTER .. ".operator must be one of"}, c.searchObjects, search({propertyName = "email", operator = "CONTAINS"})) fails({FILTER .. ".propertyName must be a nonempty string"}, c.searchObjects, search({propertyName = "", operator = "EQ", value = "x"})) fails({FILTER .. " received an unknown field property"}, c.searchObjects, search({property = "email", propertyName = "email", operator = "EQ"})) fails({FILTER .. ".value must be a string"}, c.searchObjects, search({propertyName = "amount", operator = "GT", value = 5})) fails({FILTER .. ".highValue must be a string"}, c.searchObjects, search({propertyName = "amount", operator = "BETWEEN", value = "1", highValue = 9})) fails({FILTER .. ".values must be an array of 1 to 500 items"}, c.searchObjects, search({propertyName = "hs_tag_ids", operator = "IN", values = "a"})) fails({FILTER .. ".values[2] must be a string"}, c.searchObjects, search({propertyName = "hs_tag_ids", operator = "IN", values = {"a", 2}})) local ok = {propertyName = "email", operator = "HAS_PROPERTY"} fails({"sorts[1] must be an object"}, c.searchObjects, search(ok, {"createdate"})) fails({"sorts[1].direction must be one of ASCENDING, DESCENDING"}, c.searchObjects, search(ok, {{propertyName = "createdate"}})) fails({"sorts[1].propertyName must be a nonempty string"}, c.searchObjects, search(ok, {{direction = "ASCENDING"}})) fails({"sorts[1] received an unknown field order"}, c.searchObjects, search(ok, {{propertyName = "createdate", direction = "ASCENDING", order = 1}})) fails({"limit must be an integer from 1 to 200"}, c.searchObjects, {objectType = "contacts", limit = 201}) fails({"searchObjects received an unknown option archived"}, c.searchObjects, {objectType = "contacts", archived = true}) fails({"inputs must be an array of 1 to 100 items"}, c.batchReadObjects, {objectType = "contacts", inputs = {}}) local ids = {} for index = 1, 1001 do table.insert(ids, {id = tostring(index)}) end fails({"inputs must be an array of 1 to 100 items"}, c.batchReadObjects, {objectType = "contacts", inputs = table.move(ids, 1, 101, 1, {})}) fails({"inputs[1].id must be a string of digits"}, c.batchReadObjects, {objectType = "contacts", inputs = {{id = 101}}}) fails({"inputs[1].id must be a nonempty string"}, c.batchReadObjects, {objectType = "contacts", idProperty = "email", inputs = {{id = ""}}}) fails({"inputs[1] received an unknown field properties"}, c.batchReadObjects, {objectType = "contacts", inputs = {{id = "1", properties = {"email"}}}}) fails({"inputs must be an array of 1 to 1000 items"}, c.batchReadAssociations, {fromObjectType = "deals", toObjectType = "companies", inputs = ids}) fails({"properties must be an array of 1 to 500 items"}, c.listObjects, {objectType = "contacts", properties = {}}) fails({"properties must be an array of 1 to 500 items"}, c.searchObjects, {objectType = "contacts", properties = "email"}) fails({"properties[1] must be a nonempty name without commas"}, c.getObject, {objectType = "contacts", objectId = "1", properties = {"email,phone"}}) fails({"objectType must be one of deals, tickets"}, c.listPipelines, {objectType = "contacts"}) fails({"pipelineId must be a nonempty string"}, c.getPipeline, {objectType = "deals"}) fails({"pipelineId " .. SEGMENT}, c.getPipeline, {objectType = "deals", pipelineId = ".."}) fails({"propertyName must be a property's internal name"}, c.getProperty, {objectType = "contacts", propertyName = "a/b"}) fails({"ownerId must be a string of digits"}, c.getOwner, {ownerId = "abc"}) fails({"idProperty must be one of id, userId"}, c.getOwner, {ownerId = "1", idProperty = "email"}) assert(#requests == before, "invalid input reached the network") end, }writes.luau
return { scenario = {publisher = {client_id = "fixture-client", client_secret = "fixture-private-secret"}, config = {}, auth_method = "oauth", auth_config = {}}, access = {contacts = "write", companies = "write", deals = "write", tickets = "write", engagements = "write"}, configure = function() requests, responses = {}, {} http = {request = function(req) for name in req.headers or {} do assert(string.lower(name) ~= "authorization", "the proxy injects Authorization") end table.insert(requests, req) assert(#responses > 0, "unexpected request: " .. req.url) local response = table.remove(responses, 1) return fixture.operation({statusCode = response.status or 200, headers = response.headers or {}, body = fixture.reader(response.body or "")}) end} end, run = function(c) local OBJECTS = "https://api.hubapi.com/crm/objects/2026-09/" local function last() return requests[#requests] end local function same(a: any, b: any): boolean if type(a) ~= "table" or type(b) ~= "table" then return a == b end for key, value in a do if not same(value, b[key]) then return false end end for key in b do if a[key] == nil then return false end end return true end local function sent(method: string, href: string, expected: any) assert(last().method == method and last().url == href, last().method .. " " .. last().url) assert(last().headers["Content-Type"][1] == "application/json", "JSON body without Content-Type") assert(same(json.decode(last().body), expected), "unexpected body " .. last().body) end local function fails(expected: {string}, fn: (...any) -> any, ...: any) local ok, err = pcall(fn, ...) assert(not ok, "call succeeded") for _, text in expected do assert(string.find(tostring(err), text, 1, true), "missing " .. text .. " in " .. tostring(err)) end end local names = {} for name in c do table.insert(names, name) end table.sort(names) assert(table.concat(names, ",") == "batchReadAssociations,batchReadObjects,createAssociation,createDefaultAssociation,createObject,deleteAssociation," .. "getObject,getOwner,getPipeline,getProperty,listAssociationLabels,listAssociations,listObjects,listOwners,listPipelines,listProperties," .. "searchObjects,updateObject", "read-write got " .. table.concat(names, ",")) -- Creates send {properties, associations?}; values keep their JSON types. responses = { {status = 201, body = '{"id":"101","properties":{"email":"[email protected]"},"archived":false}'}, {status = 201, body = '{"id":"301","properties":{"hs_note_body":"Called about renewal."}}'}, {status = 201, body = '{"id":"401"}'}, } local contact = {email = "[email protected]", firstname = "Ana", hs_count = 3, opted_in = false} assert(c.createObject({objectType = "contacts", properties = contact}).id == "101") sent("POST", OBJECTS .. "contacts", {properties = contact}) local note = {hs_timestamp = "2026-11-13T10:00:00Z", hs_note_body = "Called about renewal."} local links = {{to = {id = "101"}, types = {{associationCategory = "HUBSPOT_DEFINED", associationTypeId = 202}}}, {to = {id = "512"}, types = {{associationCategory = "HUBSPOT_DEFINED", associationTypeId = 190}}}} c.createObject({objectType = "notes", properties = note, associations = links}) sent("POST", OBJECTS .. "notes", {properties = note, associations = links}) assert(string.find(last().body, '"types":[{', 1, true) ~= nil, last().body) local task = {hs_timestamp = "2026-11-20T09:00:00Z", hs_task_subject = "Send contract", hs_task_status = "NOT_STARTED"} local onDeal = {{to = {id = "9876"}, types = {{associationCategory = "HUBSPOT_DEFINED", associationTypeId = 216}}}} c.createObject({objectType = "tasks", properties = task, associations = onDeal}) sent("POST", OBJECTS .. "tasks", {properties = task, associations = onDeal}) -- Updates PATCH only the named properties, by record ID or by a unique property. responses = {{body = '{"id":"9876","properties":{"dealstage":"closedwon"}}'}, {body = '{"id":"101"}'}, {body = '{"id":"7"}'}} assert(c.updateObject({objectType = "deals", objectId = "9876", properties = {dealstage = "closedwon", amount = ""}}).properties.dealstage == "closedwon") sent("PATCH", OBJECTS .. "deals/9876", {properties = {dealstage = "closedwon", amount = ""}}) c.updateObject({objectType = "contacts", objectId = "[email protected]", idProperty = "email", properties = {jobtitle = "CTO"}}) sent("PATCH", OBJECTS .. "contacts/ana%40example.com?idProperty=email", {properties = {jobtitle = "CTO"}}) c.updateObject({objectType = "contacts", objectId = "sku:123", idProperty = "sku", properties = {jobtitle = "CTO"}}) sent("PATCH", OBJECTS .. "contacts/sku%3A123?idProperty=sku", {properties = {jobtitle = "CTO"}}) -- Associations: a default link has an empty body, a labelled one a JSON array, and a delete none. responses = { {body = '{"status":"COMPLETE","results":[{"from":{"id":"101"},"to":{"id":"512"},"associationSpec":{"associationCategory":"HUBSPOT_DEFINED","associationTypeId":279}}]}'}, {status = 201, body = '{"fromObjectTypeId":"0-1","fromObjectId":101,"toObjectTypeId":"0-2","toObjectId":512,"labels":["Primary"]}'}, {status = 204}, } assert(c.createDefaultAssociation({fromObjectType = "contacts", fromObjectId = "101", toObjectType = "companies", toObjectId = "512"}).results[1].to.id == "512") assert(last().method == "PUT" and last().url == OBJECTS .. "contacts/101/associations/default/companies/512", last().url) assert(last().body == "" and (last().headers == nil or last().headers["Content-Type"] == nil), "a default association sends an empty body") local types = {{associationCategory = "HUBSPOT_DEFINED", associationTypeId = 1}, {associationCategory = "USER_DEFINED", associationTypeId = 36}} local labels = c.createAssociation({objectType = "contacts", objectId = "101", toObjectType = "companies", toObjectId = "512", types = types}) assert(labels.labels[1] == "Primary" and labels.toObjectId == 512) sent("PUT", OBJECTS .. "contacts/101/associations/companies/512", types) assert(string.sub(last().body, 1, 1) == "[", last().body) local removed = c.deleteAssociation({objectType = "contacts", objectId = "101", toObjectType = "companies", toObjectId = "512"}) assert(removed.success == true and last().method == "DELETE" and last().url == OBJECTS .. "contacts/101/associations/companies/512" and last().body == nil, last().url) -- Invalid writes never reach the network. local before = #requests local LINK = {{associationCategory = "HUBSPOT_DEFINED", associationTypeId = 1}} fails({"properties must be a nonempty object"}, c.createObject, {objectType = "contacts", properties = {}}) fails({"properties must be a nonempty object"}, c.createObject, {objectType = "contacts"}) fails({"properties.address must be a string, number or boolean"}, c.createObject, {objectType = "contacts", properties = {address = {street = "1 Main St"}}}) fails({"properties must have property names as keys"}, c.updateObject, {objectType = "deals", objectId = "1", properties = {"closedwon"}}) fails({"objectId must be a string of digits"}, c.updateObject, {objectType = "deals", properties = {dealstage = "closedwon"}}) fails({"createObject received an unknown option idProperty"}, c.createObject, {objectType = "contacts", properties = {email = "[email protected]"}, idProperty = "email"}) fails({"updateObject received an unknown option associations"}, c.updateObject, {objectType = "deals", objectId = "1", properties = {dealstage = "x"}, associations = {}}) fails({"objectType must be one of"}, c.createObject, {objectType = "products", properties = {name = "Widget"}}) fails({"types must be an array of 1 to 100 items"}, c.createAssociation, {objectType = "contacts", objectId = "1", toObjectType = "companies", toObjectId = "2", types = {}}) fails({"types[1].associationCategory must be one of HUBSPOT_DEFINED, USER_DEFINED, INTEGRATOR_DEFINED"}, c.createAssociation, {objectType = "contacts", objectId = "1", toObjectType = "companies", toObjectId = "2", types = {{associationCategory = "PRIMARY", associationTypeId = 1}}}) fails({"types[1].associationTypeId must be an integer"}, c.createAssociation, {objectType = "contacts", objectId = "1", toObjectType = "companies", toObjectId = "2", types = {{associationCategory = "HUBSPOT_DEFINED", associationTypeId = 1.5}}}) fails({"types[1].associationTypeId must be an integer"}, c.createAssociation, {objectType = "contacts", objectId = "1", toObjectType = "companies", toObjectId = "2", types = {{associationCategory = "HUBSPOT_DEFINED", associationTypeId = "1"}}}) fails({"types[1] received an unknown field label"}, c.createAssociation, {objectType = "contacts", objectId = "1", toObjectType = "companies", toObjectId = "2", types = {{associationCategory = "HUBSPOT_DEFINED", associationTypeId = 1, label = "Primary"}}}) fails({"associations[1].to.id must be a string of digits"}, c.createObject, {objectType = "notes", properties = {hs_timestamp = "1"}, associations = {{to = {}, types = LINK}}}) fails({"associations[1].to must be an object"}, c.createObject, {objectType = "notes", properties = {hs_timestamp = "1"}, associations = {{types = LINK}}}) fails({"associations[1].types must be an array"}, c.createObject, {objectType = "notes", properties = {hs_timestamp = "1"}, associations = {{to = {id = "1"}}}}) fails({"associations[1] received an unknown field toObjectType"}, c.createObject, {objectType = "notes", properties = {hs_timestamp = "1"}, associations = {{to = {id = "1"}, types = LINK, toObjectType = "contacts"}}}) fails({"toObjectType must be one of"}, c.createDefaultAssociation, {fromObjectType = "contacts", fromObjectId = "1", toObjectType = "products", toObjectId = "2"}) fails({"toObjectType must be one of"}, c.createDefaultAssociation, {fromObjectType = "contacts", fromObjectId = "101", toObjectType = "quotes", toObjectId = "7"}) fails({"toObjectType must be one of"}, c.createAssociation, {objectType = "contacts", objectId = "101", toObjectType = "quotes", toObjectId = "7", types = LINK}) fails({"toObjectType must be one of"}, c.deleteAssociation, {objectType = "contacts", objectId = "101", toObjectType = "quotes", toObjectId = "7"}) fails({"toObjectId must be a string of digits"}, c.deleteAssociation, {objectType = "contacts", objectId = "1", toObjectType = "companies", toObjectId = "../2"}) fails({"deleteAssociation received an unknown option types"}, c.deleteAssociation, {objectType = "contacts", objectId = "1", toObjectType = "companies", toObjectId = "2", types = LINK}) assert(#requests == before, "invalid writes reached HubSpot") -- A failed write is reported once and never repeated. responses = {{status = 500, body = '{"status":"error","message":"internal error","category":"INTERNAL_ERROR"}'}} fails({"HubSpot HTTP 500 (INTERNAL_ERROR)", '"retryable":false'}, c.createObject, {objectType = "contacts", properties = {email = "[email protected]"}}) assert(#requests == before + 1 and #responses == 0) end, }