T
Twentyβ€’7mo ago
Rob

Programatic way to create a note for a company using REST?

Hi Twenty team πŸ‘‹ Loving the extensibility of twenty! I've had great luck using the api to tidy up my CRM, see for example https://discord.com/channels/1130383047699738754/1244820584723120242/1244899581829845082 I am now trying to create a note via the rest api for a company, but I can't wrap my head around the playground docs. Assuming I have already obtained the company id that i need, e.g. company_id = 1983887e-1c8d-4cc2-a0b4-a747890d182d Do I use https://docs.twenty.com/rest-api/core#/operations/createOneActivity to make a note? Is there a minimal example somewhere of how to create a note via the api? Thanks again!
Welcome | Twenty - Documentation
Twenty is a CRM designed to fit your unique business needs.
15 Replies
charles
charlesβ€’7mo ago
Hi @Rob! There is a morph many to many relation between objects and activities. It is materialized throught the activityTarget table that has the following columns to represent the morph many to many relation: - activityId - companyId - personId - opportunityId - myCustomObject1Id - ... So to create a note through the API, you'll need to create an activity, and then create an activityTarget with your activityId and companyId
Rob
RobOPβ€’7mo ago
Thanks Charles. I am just trying to do this now. As step 1, I am trying to create the activity. Using the web ui the following input fails (code as shown in the api web ui
import requests

url = "https://{redacted}/rest/activities"

payload = {
"title": "Call with Forest Bob",
"body": "Robert had a call with Bob today. The call went well.",
"authorId": "1daffaac-8e46-40b0-9ebc-98037711f924",
"assigneeId": "1daffaac-8e46-40b0-9ebc-98037711f924",
"type": "Note"
}
headers = {
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": "Bearer {redacted}"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
import requests

url = "https://{redacted}/rest/activities"

payload = {
"title": "Call with Forest Bob",
"body": "Robert had a call with Bob today. The call went well.",
"authorId": "1daffaac-8e46-40b0-9ebc-98037711f924",
"assigneeId": "1daffaac-8e46-40b0-9ebc-98037711f924",
"type": "Note"
}
headers = {
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": "Bearer {redacted}"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
with the error
{
"statusCode": 400,
"message": "Variable \"$data\" got invalid value { position: \"first\", title: \"Call with Forest Bob\", body: \"Robert had a call with Bob today. The call went well.\", authorId: \"1daffaac-8e46-40b0-9ebc-98037711f924\", assigneeId: \"1daffaac-8e46-40b0-9ebc-98037711f924\", type: \"Note\" }; Field \"position\" is not defined by type \"ActivityCreateInput\".",
"error": "Bad Request"
}
{
"statusCode": 400,
"message": "Variable \"$data\" got invalid value { position: \"first\", title: \"Call with Forest Bob\", body: \"Robert had a call with Bob today. The call went well.\", authorId: \"1daffaac-8e46-40b0-9ebc-98037711f924\", assigneeId: \"1daffaac-8e46-40b0-9ebc-98037711f924\", type: \"Note\" }; Field \"position\" is not defined by type \"ActivityCreateInput\".",
"error": "Bad Request"
}
Do you have any suggestions what i am doing wrong? I can't see where the value "first" is being created
Rob
RobOPβ€’7mo ago
No description
charles
charlesβ€’7mo ago
@martmull could you take a look, it seems that the REST Api is trying to send a position field to the underlying GraphQL API (it does not exist on Activity as it's not a first class citizen object)
martmull
martmullβ€’7mo ago
ok
charles
charlesβ€’7mo ago
ty!
Rob
RobOPβ€’7mo ago
Thanks!
danemyers
danemyersβ€’7mo ago
Yes! @Rob Thanks for pointing this out. Trying to create the activity and getting a 400 error was driving me notes XD
charles
charlesβ€’7mo ago
I'm going to take a look at this issue today as it seems high priority
martmull
martmullβ€’6mo ago
GitHub
Remove useless api position parameter by martmull Β· Pull Request #6...
remove buggy addition of position parameter check created records are in first position by default
martmull
martmullβ€’6mo ago
deployed on prod @Rob @danemyers
Rob
RobOPβ€’6mo ago
Amazing. Thank you @martmull do we need to run any migrations or any commands to use the new v0.20.2 release to test this? I am getting some errors (see https://discord.com/channels/1130383047699738754/1255117133386354742)
charles
charlesβ€’6mo ago
I believe this is fixed!
Rob
RobOPβ€’6mo ago
@charles I justed tested this, and it is fixed!! Thanks twenty team
charles
charlesβ€’6mo ago
great!
Want results from more Discord servers?
Add your server