type Datocms = {
apiKey: string
}
export async function main(
resource: Datocms,
modelData: {
name: string
api_key: string
singleton?: boolean
all_locales_required?: boolean
sortable?: boolean
modular_block?: boolean
draft_mode_active?: boolean
tree?: boolean
collection_appearance?: 'compact' | 'table'
hint?: string
inverse_relationships_enabled?: boolean
}
) {
const endpoint = `https://site-api.datocms.com/item-types`
// Construct the request body
const body = {
data: {
type: 'item_type',
attributes: modelData
}
}
const response = await fetch(endpoint, {
method: 'POST',
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