๐Ÿ“ฆ directus / v6-archive

๐Ÿ“„ batch-create-items.md ยท 77 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77# Batch Create Items

> **Note:** Table names are case-sensitive

> **Note:** These arguments and attributes are based on the table's custom columns

<span class="request">`POST` **/api/1.1/tables/_[table-name]_/rows/bulk**</span>

<span class="description">Create multiple new items within the specified table</span>

<span class="arguments">Name</span> | Value | Description
--------|-----|------------
**table** _String_ | <span class="required">Required</span> | The table within which the item will be added
<span class="custom">**data**</span> _Object_ | | <span class="custom">This data and its architecture is based on your specific project's schema</span>

### Example Request

```bash
# Using json as data
$ curl -H "Content-Type: application/json" \
        --data '{"rows": [{"active": 1, "title": "Lorem Ipsum"}, {"active":1,"title": "Another Lorem Ipsum"}]}' \
        https://instance--key.directus.io/api/1.1/tables/projects/rows/bulk \
                -u [user-token]:

# Using application/x-www-form-urlencoded
$ curl --data "rows[0][active]=1&rows[0][title]=Lorem+Ipsum&rows[1][active]=1&rows[1][title]=Another+Lorem+Ipsum" \
        https://instance--key.directus.io/api/1.1/tables/projects/rows/bulk \
                -u [user-token]:
```

```javascript
const items = [
  {
    active: 1,
    title: 'Lorem Ipsum'
  },
  {
    active: 1,
    title: 'Another Lorem Ipsum'
  }
];

client.createBulk('projects', items);
```

## Response

<span class="attributes">Attribute</span> | Description
-------|------------
**meta** _object_ | The Directus system metadata object that provides useful information not contained within the dataset itself [**Meta Object**: View Nested Attributes](/overview/objects-model.md#meta-object)
<span class="custom">**data**</span> _object_ | <span class="custom">This data and its architecture is based on your specific project's schema</span>

### Example Response

```json
{
  "meta": {
    "table": "projects",
    "type": "collection",
    "total": 2,
    "total_entries": 2
  },
  "data": [
    {
      "id": 1,
      "active": 1,
      "title": "Lorem Ipsum"
    },
    {
      "id": 2,
      "active": 1,
      "title": "Another Lorem Ipsum"
    }
  ]
}
```