Edits history of script submission #10183 for ' Creates one or more new statements (xero)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Xero = {
    	token: string
    }
    /**
     * Creates one or more new statements
     *
     */
    export async function main(
    	auth: Xero,
    	Xero_Tenant_Id: string,
    	Idempotency_Key: string,
    	body: {
    		pagination?: {
    			page?: number
    			pageSize?: number
    			pageCount?: number
    			itemCount?: number
    		}
    		items?: {
    			id?: string
    			feedConnectionId?: string
    			status?: 'PENDING' | 'REJECTED' | 'DELIVERED'
    			startDate?: string
    			endDate?: string
    			startBalance?: {
    				amount?: number
    				creditDebitIndicator?: 'CREDIT' | 'DEBIT'
    			}
    			endBalance?: {
    				amount?: number
    				creditDebitIndicator?: 'CREDIT' | 'DEBIT'
    			}
    			statementLines?: {
    				postedDate?: string
    				description?: string
    				amount?: number
    				creditDebitIndicator?: 'CREDIT' | 'DEBIT'
    				transactionId?: string
    				payeeName?: string
    				reference?: string
    				chequeNumber?: string
    				transactionType?: string
    			}[]
    			errors?: {
    				title?: string
    				status?: number
    				detail?: string
    				type?:
    					| 'invalid-request'
    					| 'invalid-application'
    					| 'invalid-feed-connection'
    					| 'duplicate-statement'
    					| 'invalid-end-balance'
    					| 'invalid-start-and-end-date'
    					| 'invalid-start-date'
    					| 'internal-error'
    					| 'feed-already-connected-in-current-organisation'
    					| 'invalid-end-date'
    					| 'statement-not-found'
    					| 'feed-connected-in-different-organisation'
    					| 'feed-already-connected-in-different-organisation'
    					| 'bank-feed-not-found'
    					| 'invalid-country-specified'
    					| 'invalid-organisation-bank-feeds'
    					| 'invalid-organisation-multi-currency'
    					| 'invalid-feed-connection-for-organisation'
    					| 'invalid-user-role'
    					| 'account-not-valid'
    					| 'feed-not-found-or-already-deleted'
    			}[]
    			statementLineCount?: number
    		}[]
    	}
    ) {
    	const url = new URL(`https://api.xero.com/bankfeeds.xro/1.0/Statements`)
    
    	const response = await fetch(url, {
    		method: 'POST',
    		headers: {
    			Accept: 'application/json',
    			'Xero-Tenant-Id': Xero_Tenant_Id,
    			'Idempotency-Key': Idempotency_Key,
    			'Content-Type': 'application/json',
    			Authorization: 'Bearer ' + auth.token
    		},
    		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 515 days ago