Best way to copy an array from one product to another using Sanity.io API.
Good news - Sanity Studio has built-in copy/paste functionality for array fields that makes this pretty straightforward!
Using Built-in Copy/Paste (Easiest Method)
Sanity Studio supports native copy/paste operations for array fields. Here's how:
- Open the source product in Studio
- Click the Field Actions menu (three dots) next to the array field you want to copy
- Select "Copy" (or use Ctrl/Cmd+C when focused on the field)
- Open the destination product
- Click the Field Actions menu on the target array field and select "Paste" (or Ctrl/Cmd+V)
This works for entire arrays or individual array items. You can even copy items between different document types as long as the field structures are compatible.
Programmatic Approach
If you need to copy arrays between many products or automate the process, you can use the Sanity Client:
import {createClient} from '@sanity/client'
const client = createClient({
projectId: 'your-project-id',
dataset: 'your-dataset',
token: 'your-token-with-write-access',
apiVersion: '2025-02-19'
})
// Get the source product
const sourceProduct = await client.getDocument('source-product-id')
// Copy the array to the destination product
await client
.patch('destination-product-id')
.set({ yourArrayFieldName: sourceProduct.yourArrayFieldName })
.commit()Cross-Dataset Copying
If you need to copy between different datasets or projects, check out the Cross Dataset Duplicator plugin which handles migration of documents and assets between Sanity projects directly from Studio.
The built-in copy/paste is definitely your quickest option for one-off copies!
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.