0

Get Custom Object Schema

by
Published today

Retrieve one custom object schema by its fully qualified name or objectTypeId.

Script hubspot Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 4 hours ago
1
//native
2

3
/**
4
 * Get Custom Object Schema
5
 * Retrieve one custom object schema by its fully qualified name or objectTypeId. Requires crm.schemas.custom.read.
6
 */
7
export async function main(auth: RT.Hubspot, object_type: string) {
8
  const url = new URL(`https://api.hubapi.com/crm/v3/schemas/${object_type}`)
9

10
  const response = await fetch(url, {
11
    headers: {
12
      Authorization: `Bearer ${auth.token}`,
13
      Accept: "application/json",
14
    },
15
  })
16

17
  if (!response.ok) {
18
    throw new Error(`${response.status} ${await response.text()}`)
19
  }
20

21
  return await response.json()
22
}
23