javascriptsmartsheet-apismartsheet-api-2.0

How to add a new row to Smartsheet with a column of type Dropdown List and set multiple options as true


I am working with the SmartSheets API and more specifically the "Adding Rows to Sheet" portion as documented Here

My problem is that i am having issues creating a cell object that shows multiple active picklist options when displayed on the sheet.

2 different picklist formats

As seen in the above image there are 2 different formats for the Dropdown List column type.

On top we can clearly see test test2 test3 being separated into their own distinct options. This is the format that is given when you pick/type in an option from smartsheet itself.

Below it is the result i receive when i attempt to use the API as documented to insert values for a Dropdown List.

The documentation from what i can tell fails to mention how to handle different column types. My code appears as follows to obtain the bottom (incorrect) version. (Note Sheet and Column IDs removed)

function SendNewSmartSheetRow(SheetID){
    
        let RequestHeaders = new Headers()
        RequestHeaders.append("Authorization", `Bearer ${SmartSheetAuth}`)
        RequestHeaders.append("Content-Type", "application/json")

        let RequestBody = {
            toBottom: true,
            cells: [
                {
                    columnId: columnId,
                    values: "test test2 test3"
                }
            ],
        }

        let RequestInit = {
            method: "POST",
            headers: RequestHeaders,
            body: JSON.stringify(RequestBody)
        }
        let Request = fetch(`${SmartSheetBaseURL}/sheets/${SheetID}/rows`, RequestInit)
        .then((res)=>{return(res.json())})

        return(Request)

}
let a = await SendNewSmartSheetRow(SheetId)
console.log(a)

In the code above the only part of interest really is the creating of the requestBody. Below is my original version which evidently failed.

let RequestBody = {
            toBottom: true,
            cells: [
                {
                    columnId: columnId,
                    values: "test test2 test3"
                }
            ],
        }

I had also done some googling and attempted a couple of different options. Of interest of these options is the following request body

let RequestBody = {
            toBottom: true,
            cells: [
                {
                    columnId: 8839694736379780,
                    values: "test test2 test3",
                    objectValue:{
                        objectType:"MULTI_PICKLIST",
                        multiPickList:{
                            values:["test","test2","test3"]
                        },
                    },
                }
            ],
        }

Interestingly enough this prompted me with the response error Required object attribute(s) are missing from your request: multiPickList.values[]. but clearly that is seen, so i attempted to add it to the base cell object and not objectValue and was met with the same error.

How am i supposed to add multiple options as true when creating a new row with a Dropdown List column type?


Solution

  • You were on the right track with the final snippet you included in your post, but just not quite there. I agree with you that this scenario is not very well documented in the Smartsheet API documentation.

    The following snippet shows an API request that adds one new row to a sheet and populates one cell in that new row -- a multi-picklist cell -- with 3 values: test, test2, and test3.

    POST https://api.smartsheet.com/2.0/sheets/2702602705784708/rows
    
    [
        {
            "cells": [
                {
                    "columnId": "8429111750905732", 
                    "objectValue": {
                        "objectType": "MULTI_PICKLIST",
                        "values": ["test", "test2", "test3"]
                    }
                }
                
            ]
        }
    ]
    

    Here's the result of that API request in Smartsheet -- which seems to be the outcome you're seeking:

    smartsheet sheet

    Finally, a couple of notes: