|
| 1 | +# Custom Objects |
| 2 | + |
| 3 | +## Table of Contents |
| 4 | + |
| 5 | +1. [Introduction](#custom-objects) |
| 6 | +2. [Quick Start](#quick-start) |
| 7 | + - [Create a Schema and a Custom Object](#create-a-schema-and-a-custom-object) |
| 8 | + - [Get a Custom Object](#get-a-custom-object) |
| 9 | + - [List Custom Objects](#list-custom-objects) |
| 10 | + - [Update a Custom Object](#update-a-custom-object) |
| 11 | + - [Delete a Custom Object](#delete-a-custom-object) |
| 12 | +3. [Key Concepts](#key-concepts) |
| 13 | +4. [Custom Object Lifecycle](#custom-object-lifecycle) |
| 14 | + |
| 15 | +- - - |
| 16 | + |
| 17 | +## Introduction |
| 18 | +Custom objects allow you to extend DevRev's data model beyond the standard use-cases served by the native apps (build, support, etc). |
| 19 | +Custom Objects allow you to create and manage object types tailored to your specific business needs. |
| 20 | + |
| 21 | +## Quick Start |
| 22 | + |
| 23 | +Let's say you want to manage marketing campaigns on DevRev. We'll go through the process of creating a "Campaign" custom object with relevant fields. |
| 24 | + |
| 25 | +All DevRev objects require a schema. So, we'll first create a schema for the "Campaign" custom object. Make sure to replace the `<YOUR_API_TOKEN>` with your actual API token. |
| 26 | + |
| 27 | +### Create a Schema and a Custom Object |
| 28 | + |
| 29 | +``` |
| 30 | +curl --location 'https://api.devrev.ai/schemas.custom.set' \ |
| 31 | +--header 'Content-Type: application/json' \ |
| 32 | +--header 'Accept: application/json' \ |
| 33 | +--header 'Authorization: <YOUR_API_TOKEN>' \ |
| 34 | +--data '{ |
| 35 | + "type": "tenant_fragment", |
| 36 | + "description": "Attributes for Campaign", |
| 37 | + "leaf_type": "campaign", |
| 38 | + "fields": [ |
| 39 | + { |
| 40 | + "name": "name", |
| 41 | + "type": "string", |
| 42 | + "description": "Name of the campaign" |
| 43 | + }, |
| 44 | + { |
| 45 | + "name": "start_date", |
| 46 | + "type": "date", |
| 47 | + "description": "Start date of the campaign" |
| 48 | + }, |
| 49 | + { |
| 50 | + "name": "end_date", |
| 51 | + "type": "date", |
| 52 | + "description": "End date of the campaign" |
| 53 | + }, |
| 54 | + { |
| 55 | + "name": "budget", |
| 56 | + "type": "number", |
| 57 | + "description": "Budget allocated for the campaign" |
| 58 | + }, |
| 59 | + { |
| 60 | + "name": "target_audience", |
| 61 | + "type": "enum", |
| 62 | + "description": "Target audience for the campaign", |
| 63 | + "allowed_values": [ |
| 64 | + "young_adults", |
| 65 | + "seniors", |
| 66 | + "families", |
| 67 | + "professionals", |
| 68 | + "students" |
| 69 | + ] |
| 70 | + } |
| 71 | + ], |
| 72 | + "is_custom_leaf_type": true, |
| 73 | + "id_prefix": "CAMP" |
| 74 | +}' |
| 75 | +``` |
| 76 | + |
| 77 | +Once the schema is created, you can create a custom object of type "Campaign": |
| 78 | + |
| 79 | +``` |
| 80 | +curl --location 'https://api.devrev.ai/custom-objects.create' \ |
| 81 | +--header 'Content-Type: application/json' \ |
| 82 | +--header 'Accept: application/json' \ |
| 83 | +--header 'Authorization: <YOUR_API_TOKEN>' \ |
| 84 | +--data '{ |
| 85 | + "leaf_type": "campaign", |
| 86 | + "custom_fields": { |
| 87 | + "name": "Summer Sale 2023", |
| 88 | + "start_date": "2023-06-01", |
| 89 | + "end_date": "2023-08-31", |
| 90 | + "budget": 10000, |
| 91 | + "target_audience": "Young adults" |
| 92 | + }, |
| 93 | + "unique_key": "CAMP-001" |
| 94 | +}' |
| 95 | +``` |
| 96 | + |
| 97 | +The sections below provide more details on the available API endpoints for Custom Objects. |
| 98 | + |
| 99 | +### Get a Custom Object |
| 100 | + |
| 101 | +To retrieve a specific custom object, use the `custom-objects.get` endpoint: |
| 102 | + |
| 103 | +``` |
| 104 | +curl --location 'https://api.devrev.ai/custom-objects.get' \ |
| 105 | +--header 'Content-Type: application/json' \ |
| 106 | +--header 'Accept: application/json' \ |
| 107 | +--header 'Authorization: <YOUR_API_TOKEN>' \ |
| 108 | +--data '{ |
| 109 | + "leaf_type": "campaign", |
| 110 | + "id": "<OBJECT_ID>" |
| 111 | +}' |
| 112 | +``` |
| 113 | + |
| 114 | +### List Custom Objects |
| 115 | + |
| 116 | +To list custom objects based on specific criteria, use the `custom-objects.list` endpoint: |
| 117 | + |
| 118 | +``` |
| 119 | +curl --location 'https://api.devrev.ai/custom-objects.list' \ |
| 120 | +--header 'Content-Type: application/json' \ |
| 121 | +--header 'Accept: application/json' \ |
| 122 | +--header 'Authorization: <YOUR_API_TOKEN>' \ |
| 123 | +--data '{ |
| 124 | + "leaf_type": "campaign", |
| 125 | + "filter": { |
| 126 | + "eq": ["custom_fields.target_audience", "Young adults"] |
| 127 | + } |
| 128 | +}' |
| 129 | +``` |
| 130 | + |
| 131 | +### Update a Custom Object |
| 132 | + |
| 133 | +To update an existing custom object, use the `custom-objects.update` endpoint. Here's an example of updating the budget of a campaign: |
| 134 | + |
| 135 | +``` |
| 136 | +curl --location 'https://api.devrev.ai/custom-objects.update' \ |
| 137 | +--header 'Content-Type: application/json' \ |
| 138 | +--header 'Accept: application/json' \ |
| 139 | +--header 'Authorization: <YOUR_API_TOKEN>' \ |
| 140 | +--data '{ |
| 141 | + "leaf_type": "campaign", |
| 142 | + "id": "<OBJECT_ID>", |
| 143 | + "custom_fields": { |
| 144 | + "budget": 15000 |
| 145 | + } |
| 146 | +}' |
| 147 | +``` |
| 148 | + |
| 149 | +### Delete a Custom Object |
| 150 | + |
| 151 | +To delete a custom object, use the `custom-objects.delete` endpoint: |
| 152 | + |
| 153 | +``` |
| 154 | +curl --location 'https://api.devrev.ai/custom-objects.delete' \ |
| 155 | +--header 'Content-Type: application/json' \ |
| 156 | +--header 'Accept: application/json' \ |
| 157 | +--header 'Authorization: <YOUR_API_TOKEN>' \ |
| 158 | +--data '{ |
| 159 | + "id": "<OBJECT_ID>" |
| 160 | +} |
| 161 | +``` |
| 162 | + |
| 163 | +## Key Concepts |
| 164 | + |
| 165 | +1. **Leaf Type**: The base type of your custom object (e.g., "campaign"). |
| 166 | +2. **Subtype**: A more specific categorization within a leaf type (e.g., "promotion" or "advertising" for a "campaign" leaf type). |
| 167 | +3. **Custom Fields**: User-defined fields that store specific data for your custom object. |
| 168 | +4. **Unique Key**: A unique identifier for each custom object, useful for maintaining idempotency. |
| 169 | + |
| 170 | +## Custom Object Lifecycle |
| 171 | + |
| 172 | +1. **Creation**: Define the leaf type, subtype (optional), and custom fields for your object. |
| 173 | +2. **Usage**: Create, update, and query custom objects as needed in your workflows. |
| 174 | +3. **Management**: Modify the structure or delete custom objects as your needs evolve. |
0 commit comments