//native
/**
* Create Deal
* Create a deal from the common fields. `pipeline` and `dealstage` take internal IDs (see List Pipelines and Stages); `closedate` is an ISO 8601 date. Use Create CRM Object for any other property.
*/
export async function main(
auth: RT.Hubspot,
amount: string | undefined,
closedate: string | undefined,
dealname: string | undefined,
dealstage: string | undefined,
hubspot_owner_id: string | undefined,
pipeline: string | undefined
) {
const properties: { [key: string]: string } = {}
const fields = {
amount,
closedate,
dealname,
dealstage,
hubspot_owner_id,
pipeline,
}
for (const [key, value] of Object.entries(fields)) {
if (value != null && value !== "") properties[key] = value
}
const response = await fetch("https://api.hubapi.com/crm/v3/objects/deals", {
method: "POST",
headers: {
Authorization: `Bearer ${auth.token}`,
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify({ properties }),
})
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 15 days ago