Error: adding rows with smartsheet API

2019-05-10 18:56发布

问题:

I can't seem to get a add row(s) to work. I get the following error, but I believe the data is formatted correctly. Thanks in advance!

{"errorCode":1008,"message":"Unable to parse request. The following error occurred: Request body must be either a JSON object or JSON array."}

POST https://api.smartsheet.com/1.1/sheet/{sheetId}/rows

ContentType=application/json

[
  {
   "toBottom" : true, 
   "cells" : [
        {"columnId" : "328984295696260", "value" : 888.0},
        {"columnId" : 4832583923066756, "value" : 100.0}
    ]
  },
  {
   "toBottom" : true, 
   "cells": [
      {"columnId" : "328984295696260", "value" : 999.0},
      {"columnId" : 4832583923066756, "value" : 100.0}
    ]
   }
]

回答1:

Looks like you've encountered a bug with the API 1.1 "Add Row(s)" endpoint. I get the same error as you report when attempting a similar request using the API 1.1 endpoint -- but it works fine with the API 2.0 endpoint.

I'd suggest that you try using the API 2.0 "Add Row(s)" endpoint instead:

POST https://api.smartsheet.com/2.0/sheets/{sheetId}/rows

API 1.1 has been deprecated (see announcement here), so you should be using API 2.0 for any new API development. The API 2.0 documentation can be found here.

PS - for good measure (although it's not the cause of your issue) -- I'd suggest that you remove quotation marks from around the first numerical columnId value in each cells collection, as they're not necessary.