API Columns endpoint says isArray when returning non-array

Create two attachments columns in a Coda table. Add a single row. In one of the columns upload a single file. In the other one upload two files.

Now, call the listRows endpoint and the listColumns endpoint.

For the response from listColumns you’ll see something like:

  <snip>
    {
        "id": "c-pi61voPZCW",
        "type": "column",
        "name": "File",
        "href": "https://coda.io/apis/v1/docs/w6a4yfCsS8/tables/grid-D_ggLbyTu2/columns/c-pi61voPZCW",
        "format": {
            "type": "attachments",
            "isArray": true
        }
    },
    {
        "id": "c-iqsqt4e271",
        "type": "column",
        "name": "File Multiple",
        "href": "https://coda.io/apis/v1/docs/w6a4yfCsS8/tables/grid-D_ggLbyTu2/columns/c-iqsqt4e271",
        "format": {
            "type": "attachments",
            "isArray": true
        }
    }
<snip>

As you can see, both of them say that they are an attachment format type, and that they return arrays "isArray": true.

However, if you look at the response from listRows, you’ll be surprised.

The multiple attachment columns is correct, it returns an array:

<snip>
  "c-iqsqt4e271": [
        {
    "@context": "http://schema.org/",
    "@type": "ImageObject",
    "name": "cra.ps",
    "height": "",
    "width": "",
    "url": "https://codahosted.io/docs/w6a4yfCsS8/blobs/bl-mweY1eJZqh/redacted",
    "status": "live"
},
        {
            "@context": "http://schema.org/",
            "@type": "ImageObject",
            "name": "FCounter.mp4",
            "height": "",
            "width": "",
            "url": "https://codahosted.io/docs/w6a4yfCsS8/blobs/bl-WuR_8Wv6B5/redacted",
            "status": "live"
        }
    ]

But the single attachment is incorrect, it returns an object:

<snip>
  "c-pi61voPZCW": {
      "@context": "http://schema.org/",
      "@type": "ImageObject",
      "name": "cra.ps",
      "height": "",
      "width": "",
      "url": "https://codahosted.io/docs/w6a4yfCsS8/blobs/bl-mweY1eJZqh/redacted",
      "status": "live"
  }

This is especially confusing because the rest of the API is quite happy returning single objects as arrays. For example, even though in a Single Select list there can only return one object, the API still returns that single object in an array:

"c-TmORamz3zI": [
                    0
                ]

So this seems to add additional reason why we would expect a single attachment to also be returned as an array.

Is this intentional? I know I can just introspect on whether the returned object is an array. But the inconsistency between getColumns and getRows messes up my ability to rely on getColumns as a way to predict what type of data container I need to be ready to handle.

This seems fresh. Perhaps a regression because it used to work consistently when I was developing my cross-doc.

1 Like

Seems like a mismatch happens with multiple lookups, too. They are arrays, but the columns endpoint lies and says "isArray": false:

"c-QdFDMjcb2M": {
    "name": "Lookup Multiple",
    "format": {
      "type": "lookup",
      "table": {
        "id": "grid-teojUqDHeq",
        "href": "https://coda.io/apis/v1/docs/w6a4yfCsS8/tables/grid-teojUqDHeq",
        "name": "Other Table",
        "type": "table",
        "tableType": "table",
        "browserLink": "https://coda.io/d/_dw6a4yfCsS8#_tugrid-teojUqDHeq"
      },
      "isArray": false
    }
  }

Same with reactions:

 "c-H5BxE7tM-T": {
    "name": "Reaction None",
    "format": {
      "type": "reaction",
      "isArray": true
    }
  }

but the actual returned value:

"c-H5BxE7tM-T": "",

EDIT: ah no sorry, this is only for blank ones. Entries with reactions in them come back as an array like you’d expect. This might not be a discrepancy I’ll see how it plays out

I tried to replicate the original issue with attachments, but it was returning an array in both cases.

{
  "items": [
    {
      "id": "i-uko7O0EYD3",
      "type": "row",
      // ...
      "values": {
        "Name": "```My Row```",
        "File": [
          {
            "@context": "http://schema.org/",
            "@type": "ImageObject",
            "name": "foo.txt",
            // ...
          }
        ],
        "File 2": [
          {
            "@context": "http://schema.org/",
            "@type": "ImageObject",
            "name": "foo.txt",
            // ...
          },
          {
            "@context": "http://schema.org/",
            "@type": "ImageObject",
            "name": "data.csv",
            // ...
          }
        ]
      }
    }
  ],
  // ...
}

What parameters are you passing to the listRows endpoint? Perhaps it only happens with a certain combination?

Shared the test doc that’s causing the error with you in this thread: Coda API Bug: Return string when should return array - #2 by Eric_Koleda

Also, these exact params:

https://coda.io/apis/v1/docs/{{docId}}/tables/{{tableId}}/rows?valueFormat=rich&pageToken=&limit=500&visibleOnly=false

FWIW I never ran into this issue on my builds. Could it happen that column formats don’t match what’s in there? i.e. you’re looking up a list of values into a column of a type Text?

I just don’t think so. It’s the same column in both cases, and they’re both select lists. They should be returning identical data types

Thanks for sharing your original doc, I was able to repro it there and in a copy of that doc. My guess is that the file was uploaded into that row in an uncommon way that resulted in a single value being set instead of an array, and the API is reflecting that. I’ve raised a bug with the engineering team to take a deeper look.

1 Like

Thank you @Eric_Koleda. As a hint for the engineer trying to repro, it might have something to do with copy pasting