Edits history of script submission #14198 for ' Get states by country ID (bamboo_hr)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    /**
     * Get states by country ID
     * Get states/provinces for a specific country. Returns a list of state/province options with ID, label, ISO code, and name.
     */
    export async function main(auth: RT.BambooHr, countryId: string) {
    	const url = new URL(
    		`https://${auth.companyDomain}.bamboohr.com/api/v1/meta/provinces/${countryId}`
    	)
    
    	const response = await fetch(url, {
    		method: 'GET',
    		headers: {
    			Authorization: 'Basic ' + btoa(`${auth.apiKey}:x`)
    		},
    		body: undefined
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.json()
    }
    

    Submitted by hugo697 235 days ago