🎤 Builder Talk: The Story Behind Lady Gaga’s Digital Experience – Register now

How to set and add items to an array using HTTP API

3 replies
Last updated: Feb 11, 2025
using the http api how do I set a specific object array using the index?maybe this?

"set": {
  "data": {
    "34" : {
      "field": "value"
    }
  }
}
Feb 10, 2025, 11:46 PM
im also not sure how you add new items to the array using the http api. I assume I get the length of the array and append an item with
"index": object
or is there a shorter way?
Feb 11, 2025, 12:05 AM
ahh I got it working finally:
"set": {
  "data": [{
    "_key": "2134",
    "_type": "bar",
    "field": value
  }]
}
Feb 11, 2025, 12:14 AM
making new entries makes sense now since its formatted like a normal document type.
Feb 11, 2025, 12:22 AM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?