Edits history of script submission #13185 for ' Edit a porting order (telnyx)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Telnyx = {
    	apiKey: string
    }
    /**
     * Edit a porting order
     * Edits the details of an existing porting order.
    
    Any or all of a porting orders attributes may be included in the resource object included in a PATCH request.
    
    If a request does not include all of the attributes for a resource, the system will interpret the missing attributes as if they were included with their current values. To explicitly set something to null, it must be included in the request with a null value.
     */
    export async function main(
    	auth: Telnyx,
    	id: string,
    	body: {
    		misc?: {
    			type?: 'full' | 'partial'
    			remaining_numbers_action?: 'keep' | 'disconnect'
    			new_billing_phone_number?: string
    		}
    		end_user?: {
    			admin?: {
    				entity_name?: string
    				auth_person_name?: string
    				billing_phone_number?: string
    				account_number?: string
    				tax_identifier?: string
    				pin_passcode?: string
    				business_identifier?: string
    			}
    			location?: {
    				street_address?: string
    				extended_address?: string
    				locality?: string
    				administrative_area?: string
    				postal_code?: string
    				country_code?: string
    			}
    		}
    		documents?: { loa?: string; invoice?: string }
    		activation_settings?: { foc_datetime_requested?: string }
    		phone_number_configuration?: {
    			billing_group_id?: string
    			connection_id?: string
    			messaging_profile_id?: string
    			emergency_address_id?: string
    			tags?: string[]
    		}
    		requirement_group_id?: string
    		requirements?: { field_value: string; requirement_type_id: string }[]
    		user_feedback?: { user_rating?: number; user_comment?: string }
    		webhook_url?: string
    		customer_reference?: string
    		messaging?: { enable_messaging?: false | true }
    	}
    ) {
    	const url = new URL(`https://api.telnyx.com/v2/porting_orders/${id}`)
    
    	const response = await fetch(url, {
    		method: 'PATCH',
    		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