> Documentation index: [Saleor](/llms.txt) · [This section](/developer/llms.txt)
> Source: https://docs.saleor.io/developer/bulks/bulk-attributes

# Bulk Attribute Import

This guide describes a mutation allowing users to create and update multiple attributes in Saleor. The purpose of these mutations could be to import attributes from other systems.

caution

Mutations use the same data inputs as [`attributeCreate`](/api-reference/attributes/mutations/attribute-create.md) and [`attributeUpdate`](/api-reference/attributes/mutations/attribute-update.md) to keep it consistent between single and bulk mutations, but deprecated fields from [`AttributeCreateInput`](/api-reference/attributes/inputs/attribute-create-input.md), [`AttributeUpdateInput`](/api-reference/attributes/inputs/attribute-update-input.md), [`AttributeValueCreateInput`](/api-reference/attributes/inputs/attribute-value-create-input.md) and [`AttributeValueUpdateInput`](/api-reference/attributes/inputs/attribute-value-update-input.md) are not supported in bulk mutations and using them will result in an error.

Those fields are:

-   `filterableInStorefront`
-   `availableInGrid`
-   `storefrontSearchPosition`
-   `richText`
-   `plainText`

<a id="permissions"></a>

## Permissions

To edit and create attributes, a user needs to have the following permissions, depending on the attribute type:

-   `MANAGE_PRODUCT_TYPES_AND_ATTRIBUTES` if the attribute type is `PRODUCT_TYPE`
-   `MANAGE_PAGE_TYPES_AND_ATTRIBUTES` if the attribute type is `PAGE_TYPE`

<a id="error-policy"></a>

## Error Policy

`attributeBulkCreate` and `attributeBulkUpdate` mutation as well as other new bulk mutations accepts [`errorPolicy`](/developer/bulks/error-policy.md) argument, which determines how to handle errors.

<a id="attributebulkcreate"></a>

## `attributeBulkCreate`

<a id="example-mutation"></a>

### Example Mutation

**Mutation**

```graphql
mutation AttributeBulkCreate(
  $attributes: [AttributeCreateInput!]!
  $errorPolicy: ErrorPolicyEnum
) {
  attributeBulkCreate(attributes: $attributes, errorPolicy: $errorPolicy) {
    results {
      errors {
        path
        message
        code
      }
      attribute {
        id
        name
        externalReference
        slug
        choices(first: 10) {
          edges {
            node {
              id
              name
              externalReference
              slug
              value
              file {
                url
                contentType
              }
            }
          }
        }
      }
    }
    count
  }
}
```

**Variables**

```json
{
  "attributes": [
    {
      "name": "Attribute 1",
      "externalReference": "attribute-1-external-reference",
      "type": "PRODUCT_TYPE",
      "inputType": "DROPDOWN",
      "values": [
        {
          "name": "Value 1",
          "externalReference": "value-1-external-reference"
        },
        { "name": "Value 2", "externalReference": "value-2-external-reference" }
      ]
    },
    {
      "name": "Attribute 2",
      "externalReference": "attribute-2-external-reference",
      "type": "PRODUCT_TYPE",
      "inputType": "DROPDOWN",
      "values": [
        { "name": "Value 3", "externalReference": "value-3-external-reference" }
      ]
    }
  ]
}
```

**Result**

```json
{
  "data": {
    "attributeBulkCreate": {
      "results": [
        {
          "errors": [],
          "attribute": {
            "id": "QXR0cmlidXRlOjQ4",
            "name": "Attribute 1",
            "externalReference": "attribute-1-external-reference",
            "slug": "attribute-1",
            "choices": {
              "edges": [
                {
                  "node": {
                    "id": "QXR0cmlidXRlVmFsdWU6MTQ4",
                    "name": "Value 1",
                    "externalReference": "value-1-external-reference",
                    "slug": "value-1",
                    "value": "",
                    "file": null
                  }
                },
                {
                  "node": {
                    "id": "QXR0cmlidXRlVmFsdWU6MTQ5",
                    "name": "Value 2",
                    "externalReference": "value-2-external-reference",
                    "slug": "value-2",
                    "value": "",
                    "file": null
                  }
                }
              ]
            }
          }
        },
        {
          "errors": [],
          "attribute": {
            "id": "QXR0cmlidXRlOjQ5",
            "name": "Attribute 2",
            "externalReference": "attribute-2-external-reference",
            "slug": "attribute-2",
            "choices": {
              "edges": [
                {
                  "node": {
                    "id": "QXR0cmlidXRlVmFsdWU6MTUw",
                    "name": "Value 3",
                    "externalReference": "value-3-external-reference",
                    "slug": "value-3",
                    "value": "",
                    "file": null
                  }
                }
              ]
            }
          }
        }
      ],
      "count": 2
    }
  },
  "extensions": {
    "cost": {
      "requestedQueryCost": 10,
      "maximumAvailable": 50000
    }
  }
}
```

<a id="webhooks"></a>

### Webhooks

The mutation will emit `ATTRIBUTE_CREATED` event for every successfully created attribute.

<a id="attributebulkupdate"></a>

## `attributeBulkUpdate`

To update attributes one of the following fields is required: `id` or `externalReference`.

<a id="example-mutation-1"></a>

### Example Mutation

**Mutation**

```graphql
mutation AttributeBulkUpdate(
  $attributes: [AttributeBulkUpdateInput!]!
  $errorPolicy: ErrorPolicyEnum
) {
  attributeBulkUpdate(attributes: $attributes, errorPolicy: $errorPolicy) {
    results {
      errors {
        path
        message
        code
      }
      attribute {
        id
        name
        externalReference
        slug
        choices(first: 10) {
          edges {
            node {
              id
              name
              externalReference
              slug
              value
              file {
                url
                contentType
              }
            }
          }
        }
      }
    }
    count
  }
}
```

**Variables**

```json
{
  "attributes": [
    {
      "id": "QXR0cmlidXRlOjQ4",
      "fields": {
        "name": "Attribute 1 New Name",
        "removeValues": ["QXR0cmlidXRlVmFsdWU6MTQ5"]
      }
    },
    {
      "externalReference": "attribute-2-external-reference",
      "fields": {
        "addValues": [
          {
            "name": "Value 4",
            "externalReference": "value-4-external-reference"
          }
        ]
      }
    }
  ]
}
```

**Result**

```json
{
  "data": {
    "attributeBulkUpdate": {
      "results": [
        {
          "errors": [],
          "attribute": {
            "id": "QXR0cmlidXRlOjQ4",
            "name": "Attribute 1 New Name",
            "externalReference": "attribute-1-external-reference",
            "slug": "attribute-1",
            "choices": {
              "edges": [
                {
                  "node": {
                    "id": "QXR0cmlidXRlVmFsdWU6MTQ4",
                    "name": "Value 1",
                    "externalReference": "value-1-external-reference",
                    "slug": "value-1",
                    "value": "",
                    "file": null
                  }
                }
              ]
            }
          }
        },
        {
          "errors": [],
          "attribute": {
            "id": "QXR0cmlidXRlOjQ5",
            "name": "Attribute 2",
            "externalReference": "attribute-2-external-reference",
            "slug": "attribute-2",
            "choices": {
              "edges": [
                {
                  "node": {
                    "id": "QXR0cmlidXRlVmFsdWU6MTUw",
                    "name": "Value 3",
                    "externalReference": "value-3-external-reference",
                    "slug": "value-3",
                    "value": "",
                    "file": null
                  }
                },
                {
                  "node": {
                    "id": "QXR0cmlidXRlVmFsdWU6MTUx",
                    "name": "Value 4",
                    "externalReference": "value-4-external-reference",
                    "slug": "value-4",
                    "value": "",
                    "file": null
                  }
                }
              ]
            }
          }
        }
      ],
      "count": 2
    }
  },
  "extensions": {
    "cost": {
      "requestedQueryCost": 10,
      "maximumAvailable": 50000
    }
  }
}
```

<a id="webhooks-1"></a>

### Webhooks

The mutation will emit `ATTRIBUTE_UPDATED` event for every successfully updated attribute or when value is added or removed. Optionally `ATTRIBUTE_VALUE_CREATED` and `ATTRIBUTE_VALUE_DELETED` will be emitted when value is added or removed.
