1

Get Property

by
Published May 11, 2023

Retrieve the definition of one property of a CRM object type (type, field type, options, ...).

Script hubspot Verified

The script

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

3
/**
4
 * Get Property
5
 * Retrieve the definition of one property of a CRM object type (type, field type, options, ...).
6
 */
7
export async function main(
8
  auth: RT.Hubspot,
9
  objectType: string,
10
  propertyName: string
11
) {
12
  const url = new URL(
13
    `https://api.hubapi.com/crm/v3/properties/${objectType}/${propertyName}`
14
  )
15

16
  const response = await fetch(url, {
17
    headers: {
18
      Authorization: `Bearer ${auth.token}`,
19
      Accept: "application/json",
20
    },
21
  })
22

23
  if (!response.ok) {
24
    throw new Error(`${response.status} ${await response.text()}`)
25
  }
26

27
  return await response.json()
28
}
29

Other submissions
  • Submitted by sindre svendby964 Deno
    Created 525 days ago
    1
    // Ctrl+. to cache dependencies on imports hover, Ctrl+S to format.
    2
    
    
    3
    type Hubspot = {
    4
      token: string;
    5
    };
    6
    export async function main(
    7
      auth: Hubspot,
    8
      objectType: string,
    9
      propertyName: string,
    10
    ) {
    11
      const res = await fetch(
    12
        `https://api.hubapi.com/crm/v3/properties/${objectType}/${propertyName}?archived=false`,
    13
        {
    14
          headers: {
    15
            Authorization: `Bearer ${auth.token}`,
    16
            Accept: "application/json",
    17
          },
    18
          method: "GET",
    19
        },
    20
      );
    21
      const jsonRes = await res.json();
    22
      if (jsonRes.status == "error") {
    23
        console.error(jsonRes);
    24
        throw new Error(jsonRes.message);
    25
      }
    26
      return jsonRes;
    27
    }
    28