Edits history of script submission #13033 for ' Create a Migration (telnyx)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Telnyx = {
    	apiKey: string
    }
    /**
     * Create a Migration
     * Initiate a migration of data from an external provider into Telnyx Cloud Storage. Currently, only S3 is supported.
     */
    export async function main(
    	auth: Telnyx,
    	body: {
    		id?: string
    		source_id: string
    		target_bucket_name: string
    		target_region: string
    		refresh?: false | true
    		last_copy?: string
    		status?: 'pending' | 'checking' | 'migrating' | 'complete' | 'error' | 'stopped'
    		bytes_to_migrate?: number
    		bytes_migrated?: number
    		speed?: number
    		eta?: string
    		created_at?: string
    	}
    ) {
    	const url = new URL(`https://api.telnyx.com/v2/storage/migrations`)
    
    	const response = await fetch(url, {
    		method: 'POST',
    		headers: {
    			'Content-Type': 'application/json',
    			Authorization: 'Bearer ' + auth.apiKey
    		},
    		body: JSON.stringify(body)
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.json()
    }
    

    Submitted by hugo697 428 days ago