Use the POST
HTTP method to create new records.
In the following example we’re using curl
to create a new organisation record. The API uses
JSON for the request but it's good practice to make sure that you include Content-type
and Accept
request headers of application/json
as the API in the future may support more content types.
curl -i -X POST -H "Authorization: Bearer {token}" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{
"party": {
"type": "organisation",
"name": "Acme INC"
}
}' https://api.capsulecrm.com/api/v2/parties
When creating a record the response header will contain an HTTP status of 201 Created
and the body will contain the
record stored in Capsule.
Additionally, a Location
response header will contain the URL you can use to retrieve the record over the API.
To include the response headers in Curl add the -i
command line option.
HTTP/1.1 201 Created
Location: https://api.capsulecrm.com/api/v2/parties/100
{
"party": {
"id": 100,
"type": "organisation",
"about": null,
"name": "Acme INC",
"createdAt": "2015-11-30T16:20:05Z",
"updatedAt": "2015-11-30T16:20:05Z",
"lastContactedAt": null,
"pictureURL": "https://capsulecrm.com/theme/default/images/org_avatar_70.png",
"addresses": [],
"phoneNumbers": [],
"websites": [],
"emailAddresses": []
}
}
Use the PUT
HTTP method to update existing records.
In the following example we're using curl
to update an existing organisation record.
To simplify updates on the API, only the details you’re updating need to be included in the payload body of the request you send to the API endpoint.
For example, when creating an organisation record including the name
property is required. However, including name
is optional if you’re
only updating an existing party record's contact details.
Any details that are not included in the request body remain unchanged on the record.
curl -i -X PUT -H "Authorization: Bearer {token}" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{
"party": {
"type": "organisation",
"name": "Acme"
}
}' https://api.capsulecrm.com/api/v2/parties/100
HTTP/1.1 200 OK
{
"party": {
"id": 100,
"type": "organisation",
"about": null,
"name": "Acme",
"createdAt": "2015-11-30T16:20:05Z",
"updatedAt": "2015-11-30T16:20:05Z",
"lastContactedAt": null,
"pictureURL": "https://capsulecrm.com/theme/default/images/org_avatar_70.png",
"addresses": [],
"phoneNumbers": [],
"websites": [],
"emailAddresses": []
}
}
The response from the API request will include the entire record including details that were not including in the body of your request.
Use the DELETE
HTTP method to remove a record from your account.
curl -i -X DELETE -H "Authorization: Bearer {token}" https://api.capsulecrm.com/api/v2/parties/100
HTTP/1.1 204 No content
Next Step: Handling API responses