Edits history of script submission #17880 for ' List formats (phrase)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Phrase = {
    	token: string
    	baseUrl: string
    }
    /**
     * List formats
     * Get a handy list of all localization file formats supported in Phrase.
     */
    export async function main(auth: Phrase) {
    	const url = new URL(`${auth.baseUrl}/formats`)
    
    	const response = await fetch(url, {
    		method: 'GET',
    		headers: {
    			Authorization: 'ApiToken ' + auth.token
    		},
    		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