Edits history of script submission #23436 for ' Get Form (hubspot)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    export type DynSelect_form_id = string
    
    // Dropdown of the account's forms.
    export async function form_id(auth: RT.Hubspot) {
      const response = await fetch(
        "https://api.hubapi.com/marketing/v3/forms?limit=100",
        {
          headers: {
            Authorization: `Bearer ${auth.token}`,
            Accept: "application/json",
          },
        }
      )
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
      const { results } = (await response.json()) as {
        results: { id: string; name: string }[]
      }
      return results.map((f) => ({ value: f.id, label: f.name }))
    }
    
    /**
     * Get Form
     * Retrieve a marketing form definition, including its field groups. Requires the forms scope.
     */
    export async function main(auth: RT.Hubspot, form_id: DynSelect_form_id) {
      const url = new URL(`https://api.hubapi.com/marketing/v3/forms/${form_id}`)
    
      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