TwentyT
Twenty2y ago
6 replies
hiimalexok

Creating Company & Opportunity Returning 500 On REST API

Hello!

I'm trying to create a company and an opportunity at the same time.

I'm hitting /rest/companies

and passing the following body:
{
"name": "COMPANY NAME",
"opportunities": [
{
"name": "OPPORTUNITY NAME"
}
]
}

Here's my code specifically:

await fetch(
    "https://my-url.com/rest/companies",
    {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        Accept: "application/json",
        Authorization: `Bearer ${process.env.CRM_API_KEY}`,
      },
      body: JSON.stringify({
        name: body.businessName,
        opportunities: [
          {
            name: "Test Opportunity",
          },
        ],
      }),
    },
  );


and it's returning the following:
"error": "AxiosError: Request failed with status code 500. Please check your query."

Am I missing something obvious?
Was this page helpful?