Managing order references in Sanity schema for API integration.

5 replies
Last updated: Nov 1, 2021
user M
and
user A
i have a 2 category like logo and web but my problem during the checkout 2 different form fields on conditional base see my form fields below link can you elaborate me how to manage in order schemalink1
https://logozila.com/logo-questionnaire/?id=6964&customer_email=test%40gmail.com&customer_name=test&amount=60&package=Start+Project&currency=USD link 2
https://logozila.com/logo-questionnaire/?id=6965&customer_email=test%40gmail.com&customer_name=test&amount=169&package=Start+Project&currency=USD
Oct 17, 2021, 3:27 PM
yes i have 2 order form in 4 site but problem how i mange the order reference for the schemaexport default {
title: 'Order',
name: 'order',
type: 'document',
__experimental_actions: ['create', 'update', /*'delete',*/ 'publish'],
fields: [
{
name: 'order_item_name',
title: 'Order Item Name',
type: 'string',
},
{
name: 'order_item_type',
title: 'Order Item Type',
type: 'string',
},
{
name: 'order_id',
type: 'reference',
to: [{type: 'order_item'}]
},
],
preview: {
select: {
title: 'order_item_name',
},

},
}
Oct 24, 2021, 2:41 PM
yes i have 2 order form in 4 site but problem how i mange the order reference for the schemaexport default {
title: 'Order',
name: 'order',
type: 'document',
__experimental_actions: ['create', 'update', /*'delete',*/ 'publish'],
fields: [
{
name: 'order_item_name',
title: 'Order Item Name',
type: 'string',
},
{
name: 'order_item_type',
title: 'Order Item Type',
type: 'string',
},
{
name: 'order_id',
type: 'reference',
to: [{type: 'order_item'}]
},
],
preview: {
select: {
title: 'order_item_name',
},

},
}
Oct 24, 2021, 2:41 PM
Hey User, so to clarify, are you trying to create a reference using the API based off of the input from this form on your frontend?
Nov 1, 2021, 7:15 PM
yes
user M
Nov 1, 2021, 7:16 PM
Ok, thanks for clarifying. I was finally able to wrap my brain around this. Using the API, you need to set up a reference object. This takes two properties:
_type
and
_ref
.
_type
will always be 'reference' and
_ref
will be the document you're referencing. In your case, you would have to add this:
order_id: {
  _type: 'reference',
  _ref: '<id-of-the-order-item-document>'
}
Nov 1, 2021, 7:19 PM

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?