Edits history of script submission #23466 for ' List Templates (hubspot)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * List Templates
     * List the design manager templates (pages, emails, blogs). Their `path` is what `templatePath` expects when creating pages and emails. Requires the content scope.
     */
    export async function main(
      auth: RT.Hubspot,
      limit: number | undefined,
      offset: number | undefined
    ) {
      const url = new URL(`https://api.hubapi.com/content/api/v2/templates`)
      if (limit != null) url.searchParams.append("limit", String(limit))
      if (offset != null) url.searchParams.append("offset", String(offset))
    
      const response = await fetch(url, {
        headers: {
          Authorization: `Bearer ${auth.token}`,
          Accept: "application/json",
        },
      })
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 5 hours ago