Edits history of script submission #8988 for ' Add or update document (dust)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Dust = {
    	apiKey: string
    	workspaceId: string
    }
    
    export async function main(
    	resource: Dust,
    	params: {
    		datasource: string
    		documentId: string
    		content: string
    		sourceUrl?: string
    		tags?: string[]
    	}
    ) {
    	const { datasource, documentId, content, sourceUrl, tags } = params
    	const endpoint = `https://dust.tt/api/v1/w/${resource.workspaceId}/data_sources/${datasource}/documents/${documentId}`
    
    	const body = {
    		text: content,
    		source_url: sourceUrl,
    		tags: tags
    	}
    
    	const response = await fetch(endpoint, {
    		method: 'POST',
    		headers: {
    			accept: 'application/json',
    			'Content-Type': 'application/json',
    			Authorization: `Bearer ${resource.apiKey}`
    		},
    		body: JSON.stringify(body)
    	})
    
    	if (!response.ok) {
    		throw new Error(`HTTP error! status: ${response.status}`)
    	}
    
    	const data = await response.json()
    
    	return data.document
    }
    

    Submitted by hugo697 652 days ago