Skip to content

FilesApi addFile error: 'Invalid input: file - This field was not expected.', #682

Description

@artem-man
import {Configuration as PipeDriveV1Configuration, FilesApi} from "pipedrive/v1";


const apiConfig = new PipeDriveV1Configuration({apiKey: ####});
const apiInstance = new FilesApi(tmpApiConfig);
const opts = {
  file: 'test.csv',
  activity_id: 123
}

await apiInstance.addFile(opts)

{
success: false,
error: 'Invalid input: file - This field was not expected.',
error_info: 'Please check developers.pipedrive.com for more information about Pipedrive API.',
data: null,
additional_data: null
}

Please provide a valid example

Activity

  1. youssef-saber-3 commented on Feb 5, 2026

    @youssef-saber-3
    Contributor

    Hey , here is an updated example of the file upload, you can find it in our pipedrive file upload tutorial https://developers.pipedrive.com/tutorials/adding-files-via-pipedrive-api?step=7

    // All tutorial Node.js code examples are for reference only and shouldn't be used in production code as is.
    // In production, a new Configuration() instance should be initialised separately for each request.
    const pipedrive = require('pipedrive');
    const fs = require('fs');
    const { File } = require('node:buffer');
    
    // Configure authorization by setting api key
    // PIPEDRIVE_API_KEY is an environment variable that holds real api key
    const defaultClient = new pipedrive.v1.Configuration({
            apiKey: process.env.PIPEDRIVE_API_KEY,
    });
    
    async function addFile() {
            try {
                    console.log('Sending request...');
    
                    const api = new pipedrive.v1.FilesApi(defaultClient);
    
                    // Read the file from disk into a Buffer
                    const filepath = './example.txt';
                    const fileBuffer = fs.readFileSync(filepath);
    
                    // Create a File object from the buffer
                    const fileToUpload = new File([fileBuffer], 'example.txt', {
                            type: 'text/plain',
                    });
    
                    // Upload the file - note the object structure
                    const response = await api.addFile({
                            file: fileToUpload,
                            deal_id: 1,
                            // You can also associate with other entities:
                            // person_id: 1,
                            // org_id: 1,
                            // activity_id: 1,
                            // product_id: 1
                    });
    
                    console.log('File was added successfully!', response);
            } catch (err) {
                    const errorToLog = err.context?.body || err;
    
                    console.log('Adding a file failed', errorToLog);
            }
    }
    
    addFile();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions