# Create sync job template

> Source: https://truto.one/docs/api-reference/admin/sync-job-templates/create/

`POST /sync-job-template`

Resource: **Sync Job Templates**

## Request body

- **`integration_name`** _(string)_
  The integration name for the template.
- **`args_schema`** _(object, required)_
  JSON schema defining the structure of the arguments that can be passed to the sync job. Same shape as `JsonSchemaObject` (top-level `{ type: "object", properties }`).
  - **`type`** _(string)_
    Allowed: `object`
  - **`$ref`** _(string)_
  - **`properties`** _(object)_
    Map of property name → `JsonSchemaObjectProperties`.
  - **`description`** _(string)_
  - **`required`** _(boolean)_
  - **`default`** _(unknown)_
  - **`additionalProperties`** _(boolean)_
- **`resources`** _(array<object>)_
  - **`resource`** _(string)_
    The name of the resource to sync. For Unified APIs, it should be in the format `unified_api_name/resource_name`. For Proxy API, it can just be `resource_name`.
  - **`method`** _(string)_
    The method to call on the resource.
  - **`id`** _(string)_
    The ID of the resource to sync. This is optional and can be used to sync a single resource. It also supports placeholders.
  - **`query`** _(object)_
    The query parameters to pass to the resource method. It supports placeholders for values.
  - **`loop_on`** _(string)_
    When a particular placeholder argument is an array and you want to repeat the request for each element in that array, you can set this parameter. For example, if you accept an argument called `user_ids` which is an array of strings, and you want to fetch each user's details, you can set this parameter to `user_ids` and the request will be repeated for each element in the `user_ids` array.
  - **`depends_on`** _(string)_
    The resource that this resource depends on (parent resource). This is optional and can be used to sync a resource only after another resource has been synced. Each object synced for the parent resource is available as the resources object in placeholders for the child resource, e.g. `{{resources.crm.contacts.id}}` if depends on is `crm/contacts` resource.
  - **`persist`** _(boolean)_
    Whether to persist the resource in the database or not in case of a Daemon sync job run or send as a payload in case of RapidBridge sync job run. The Proxy API resources are by default NOT persisted and this parameter can be set to `true` to persist them. Unified API resources are always persisted.
- **`default_runtime_version`** _(number)_
  The default runtime version for sync jobs using this template.
- **`label`** _(string)_
  A short descriptor for this template that helps in idnetifying the template better
- **`description`** _(string)_
  Optional longer description of what this template does.
- **`sharing`** _(string)_
  Allowed: `allow`, `ask`, `deny`

## Response body

- **`id`** _(string)_
  The unique ID of the sync job template.
- **`integration_name`** _(string)_
  The integration name to which this template applies. Is null for default_runtime_version > 4.
- **`label`** _(string)_
  A short descriptor for the template.
- **`description`** _(string)_
  Optional longer description of what this template does.
- **`args_schema`** _(object, required)_
  Optional JSON schema describing arguments for the sync job.
  - **`type`** _(string)_
    Allowed: `object`
  - **`$ref`** _(string)_
  - **`properties`** _(object)_
    Map of property name → `JsonSchemaObjectProperties`.
  - **`description`** _(string)_
  - **`required`** _(boolean)_
  - **`default`** _(unknown)_
  - **`additionalProperties`** _(boolean)_
- **`resources`** _(array<object>)_
  A list of sync job resources that define the steps. If empty, no default resources are set.
  - **`resource`** _(string)_
    The name of the resource to sync. For Unified APIs, it should be in the format `unified_api_name/resource_name`. For Proxy API, it can just be `resource_name`.
  - **`method`** _(string)_
    The method to call on the resource.
  - **`id`** _(string)_
    The ID of the resource to sync. This is optional and can be used to sync a single resource. It also supports placeholders.
  - **`query`** _(object)_
    The query parameters to pass to the resource method. It supports placeholders for values.
  - **`loop_on`** _(string)_
    When a particular placeholder argument is an array and you want to repeat the request for each element in that array, you can set this parameter. For example, if you accept an argument called `user_ids` which is an array of strings, and you want to fetch each user's details, you can set this parameter to `user_ids` and the request will be repeated for each element in the `user_ids` array.
  - **`depends_on`** _(string)_
    The resource that this resource depends on (parent resource). This is optional and can be used to sync a resource only after another resource has been synced. Each object synced for the parent resource is available as the resources object in placeholders for the child resource, e.g. `{{resources.crm.contacts.id}}` if depends on is `crm/contacts` resource.
  - **`persist`** _(boolean)_
    Whether to persist the resource in the database or not in case of a Daemon sync job run or send as a payload in case of RapidBridge sync job run. The Proxy API resources are by default NOT persisted and this parameter can be set to `true` to persist them. Unified API resources are always persisted.
- **`default_runtime_version`** _(number)_
  The runtime version for any sync job that uses this template.
- **`team_id`** _(string)_
  The team that owns this template.
- **`sharing`** _(string)_
  The sharing policy of the template.
  Allowed: `allow`, `ask`, `deny`
- **`created_at`** _(string)_
  When the template was created.
- **`updated_at`** _(string)_
  When the template was last updated.

## Code examples

### curl

```bash
curl -X POST 'https://api.truto.one/sync-job-template' \
  -H 'Authorization: Bearer <your_api_token>' \
  -H 'Content-Type: application/json' \
  -d '{
  "integration_name": "your_integration_name",
  "args_schema": "{\n  \"type\": \"object\",\n  \"properties\": {\n    \"project_slug\": {\n      \"type\": \"string\",\n      \"description\": \"The project slug of the project on CircleCI. Its in the format vcs_provider/org_name/repo_name.\",\n      \"required\": true\n    }\n  }\n}\n",
  "resources": [],
  "default_runtime_version": 0,
  "label": "your_label",
  "description": "Fetches contacts from Zendesk",
  "sharing": "allow"
}'
```

### JavaScript

```javascript
const body = {
  "integration_name": "your_integration_name",
  "args_schema": "{\n  \"type\": \"object\",\n  \"properties\": {\n    \"project_slug\": {\n      \"type\": \"string\",\n      \"description\": \"The project slug of the project on CircleCI. Its in the format vcs_provider/org_name/repo_name.\",\n      \"required\": true\n    }\n  }\n}\n",
  "resources": [],
  "default_runtime_version": 0,
  "label": "your_label",
  "description": "Fetches contacts from Zendesk",
  "sharing": "allow"
};

const response = await fetch('https://api.truto.one/sync-job-template', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer <your_api_token>',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify(body),
});

const data = await response.json();
console.log(data);
```

### Python

```python
import requests

url = "https://api.truto.one/sync-job-template"
headers = {
    "Authorization": "Bearer <your_api_token>",
    "Content-Type": "application/json",
}
params = {
}
payload = {
    "integration_name": "your_integration_name",
    "args_schema": "{\n  \"type\": \"object\",\n  \"properties\": {\n    \"project_slug\": {\n      \"type\": \"string\",\n      \"description\": \"The project slug of the project on CircleCI. Its in the format vcs_provider/org_name/repo_name.\",\n      \"required\": True\n    }\n  }\n}\n",
    "resources": [],
    "default_runtime_version": 0,
    "label": "your_label",
    "description": "Fetches contacts from Zendesk",
    "sharing": "allow"
}

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