Upload file/attachment

Options

Hi. I am working with some automation tools that read an outlook email, parse the email, and upload the information to Smartsheet via API. I have completed all those steps and it has been successful. However, I am struggling to upload the attachment, which is in PDF format. I saw the documentation on this, but I keep getting an error because the PDF is stored locally and I do not have the 'URL'. Basically, I would like to know how to upload a pdf attachment stored locally and would like to know the "JSON Query" for that attachment. Thank you so much. I have been struggling for far too long on this portion and threw so much at it.

Answers

  • Leibel S
    Leibel S ✭✭✭✭✭✭
    Options

    @Kuna Sheelan

    try the below setup in the request body

    {

     "$content-type": "application/pdf",

     "$content": "base64string"

    }

  • Kuna Sheelan
    Options

    Hi,


    When I tried that, this is the error I got @Leibel S .


    {

        "errorCode": 1008,

        "message": "Unable to parse request. The following error occurred: Unknown attribute \"$content-type\" found at  line 3, column 20",

        "refId": "jz8dfv"

    }


    These are a few strings I did.


    1. I tried this -- with the URL "https://api.smartsheet.com/2.0/sheets/{sheetId}/attachments",

    attachment Query:

    {

    • "attachmentSubType": "DOCUMENT",
    • "attachmentType": "File",
    • "description": "string",
    • "name": "string",
    • "url": "string" -- (Locally stored file path)

    }


    This doesn't work too.


    THis is the documentation I followed. I hope I can get this fixed. =(


    "https://smartsheet.redoc.ly/tag/attachments#operation/attachments-attachToSheet"

  • Bortyk
    Bortyk ✭✭
    Options

    How to send a file from a client to a smartsheet using api?

  • Bortyk
    Bortyk ✭✭
    Options
    const { Readable } = require('stream');
    var fs = require("fs")
    
    
    const apload = (req, res) => {
        const smartsheet = req.smartsheetClient
        console.log(req.file)
    
        // Создаем поток чтения из Buffer
        const bufferStream = new Readable();
        bufferStream.push(req.file.buffer);
        bufferStream.push(null);
    
    
        // Обработка загруженного файла
        const options = {
            sheetId: 1234567890123456,
            fileSize: req.file.size,
            fileName: encodeURIComponent(req.file.originalname),
            // fileStream: fs.createReadStream(req.file)
            fileStream: bufferStream
        };
    
        // Attach file to sheet
        smartsheet.sheets.addFileAttachment(options)
            .then(function (attachment) {
                console.log(attachment);
                res.send('файл загружен')
            })
            .catch(function (error) {
                console.log(error);
            });
    
    }
    
    exports.apload = apload
    

    router.js:


    const upload = multer({ storage: storage });
    const { apload } = require('./routes/smartsheet/upload');
    const router = express.Router();
    router.post('/upload', upload.single('file'), apload)
    
  • RAMA T
    RAMA T ✭✭
    Options

    @Bortyk - Can you please share the Postman collection? I want to test. I am planning to integrate to the WebMethods.