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",
},
],
}),
},
);
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?
4 Replies
hiimalexok
hiimalexok4mo ago
NOTE: If I just create the company without including opportunities, it works. I've continued playing with the API and I guess a good first question should be if creating a company and an opportunity in the same REST query is an option!
Brendan
Brendan4mo ago
You can't create an opportunity by setting this property in the Post body. Its only availible for gets as a resolved relation. Instead you should create one using the opportunities endpoint and sending the corresponding companyid ... I think the ApiDocs are misleading for this case ...
hiimalexok
hiimalexok4mo ago
Understood. In that case, two separate requests, got it. Yeah, I was having a rough time figuring it out here. Maybe one day we could create both.
charles
charles3mo ago
Yep, supporting this kind of logic in the graphql payload is a bit tricky. Prisma does it though it would be great to support it at some point but will likely be later than 2024
Want results from more Discord servers?
Add your server