type Datocms = {
apiKey: string
}
export async function main(
resource: Datocms,
modelId: string,
payload: {
name?: string
api_key?: string
collection_appearance?: 'compact' | 'table'
singleton?: boolean
all_locales_required?: boolean
sortable?: boolean
modular_block?: boolean
draft_mode_active?: boolean
tree?: boolean
hint?: string
inverse_relationships_enabled?: boolean
}
) {
const endpoint = `https://site-api.datocms.com/item-types/${modelId}`
const body = {
data: {
type: 'item_type',
id: modelId,
attributes: payload
}
}
const response = await fetch(endpoint, {
method: 'PUT',
headers: {
Authorization: `Bearer ${resource.apiKey}`,
Accept: 'application/json',
'X-Api-Version': '3',
'Content-Type': 'application/vnd.api+json'
},
body: JSON.stringify(body)
})
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`)
}
const data = await response.json()
return data
}
Submitted by hugo697 621 days ago