"use server"; type CreateClientProps = { group_settings_id: string; address1: string; city: string; state: string; postal_code: string; country_id: string; address2: string; contacts: Contact; }; type Contact = { first_name: string; last_name: string; email: string; phone: string; send_email: boolean; custom_value1: string; custom_value2: string; custom_value3: string; }; export async function CreateClient({ group_settings_id = "", address1 = "", city, state, postal_code = "", country_id = "462", address2, contacts, }: CreateClientProps) { const response = await fetch( "https://finance-staging.baraveli.dev/api/v1/clients", { method: "POST", headers: { "Content-Type": "application/json", "x-api-token": `${process.env.NINJA_API_KEY}`, }, body: JSON.stringify({ group_settings_id, address1, city, state, postal_code, country_id, address2, contacts: [ { first_name: contacts.first_name, last_name: contacts.last_name, email: contacts.email || "", phone: contacts.phone, send_email: contacts.send_email, custom_value1: contacts.custom_value1, custom_value2: contacts.custom_value2, custom_value3: contacts.custom_value3 || "", }, ], }), }, ); const data = await response.json(); console.log(data.data.contacts); return data; }