Skip to content

update-user-attributes ​

Method: PUT
Path: /auth/user/{id}/attributes

Tags: Customer attributes

Summary ​

Set a user's attribute values

Description ​

Sets the customer's values for the given attributes and returns them as UserAttributeValue objects, in request order. All items are applied or none: a 400 lists each refused item's errors under errors.attributes, keyed by its position. Shoppers can set visible, active custom attributes that aren't is_readonly. In a business account every user of the customer sets the same values. With an anonymous token the values are the visitor's: they move to the customer when the visitor signs in or signs up, where the more recent of the visitor's and the customer's values is kept. The id must be the token's own user (signed in), or its visitor's id (anonymous token); any other id gets 404, as an unknown one does.

Storefront SDK Usage ​

SDK Method: sdk.auth.updateUserAttributes()

Example:

typescript
const { data, error } = await sdk.auth.updateUserAttributes(
  { id: "01H9XYZ12345USERID" },
  [
    { slug: "preferred_language", value: "en" },
    { attribute_id: "01H9ATTR12345ABCDE", value: true },
    { slug: "nickname", value: null } // removes the value
  ]
);

if (error) {
  console.error("Failed to update user attributes:", error.message);
} else {
  console.log("Updated attributes:", data.attributes.length);
}

TypeScript Definition ​

typescript
"update-user-attributes": {
        parameters: {
            query?: never;
            header?: never;
            path: {
                /** @description The user's `id`. */
                id: string;
            };
            cookie?: never;
        };
        requestBody: {
            content: {
                "application/json": components["schemas"]["UserAttributeInput"][];
            };
        };
        responses: {
            /** @description OK */
            200: {
                headers: {
                    [name: string]: unknown;
                };
                content: {
                    "application/json": {
                        /** @example Attributes updated successfully. */
                        message: string;
                        success: boolean;
                        content: {
                            attributes: components["schemas"]["UserAttributeValue"][];
                        };
                    };
                };
            };
            400: components["responses"]["BadRequest"];
            401: components["responses"]["Unauthorized"];
            404: components["responses"]["NotFound"];
        };
    };

Component References ​

ReferenceResolves To
components["schemas"]["UserAttributeInput"]UserAttributeInput
components["schemas"]["UserAttributeValue"]UserAttributeValue
components["responses"]["BadRequest"]BadRequest
components["responses"]["Unauthorized"]Unauthorized
components["responses"]["NotFound"]NotFound

Parameters ​

  • id (path): The user's id.

Request Body ​

Content Types: application/json

Responses ​

200 ​

OK

400 ​

Bad request

401 ​

Not authorized for given operation on the Resource

404 ​

Requested resource not found

OpenAPI Definition ​

json
{
  "tags": [
    "Customer attributes"
  ],
  "operationId": "update-user-attributes",
  "summary": "Set a user's attribute values",
  "description": "Sets the customer's values for the given attributes and returns them as `UserAttributeValue` objects, in request order. All items are applied or none: a 400 lists each refused item's errors under `errors.attributes`, keyed by its position. Shoppers can set visible, active `custom` attributes that aren't `is_readonly`. In a business account every user of the customer sets the same values. With an anonymous token the values are the visitor's: they move to the customer when the visitor signs in or signs up, where the more recent of the visitor's and the customer's values is kept. The id must be the token's own user (signed in), or its visitor's id (anonymous token); any other id gets 404, as an unknown one does.",
  "externalDocs": {
    "url": "https://llm-docs.commercengine.io/storefront/operations/update-user-attributes",
    "description": "API reference for the update-user-attributes operation"
  },
  "parameters": [
    {
      "name": "id",
      "in": "path",
      "description": "The user's `id`.",
      "required": true,
      "schema": {
        "type": "string"
      }
    }
  ],
  "requestBody": {
    "required": true,
    "content": {
      "application/json": {
        "schema": {
          "type": "array",
          "items": {
            "$ref": "#/components/schemas/UserAttributeInput"
          },
          "maxItems": 50,
          "minItems": 1
        }
      }
    }
  },
  "responses": {
    "200": {
      "description": "OK",
      "content": {
        "application/json": {
          "schema": {
            "type": "object",
            "required": [
              "message",
              "success",
              "content"
            ],
            "properties": {
              "message": {
                "type": "string",
                "examples": [
                  "Attributes updated successfully."
                ]
              },
              "success": {
                "type": "boolean"
              },
              "content": {
                "properties": {
                  "attributes": {
                    "type": "array",
                    "items": {
                      "$ref": "#/components/schemas/UserAttributeValue"
                    }
                  }
                },
                "required": [
                  "attributes"
                ],
                "type": "object"
              }
            }
          }
        }
      }
    },
    "400": {
      "$ref": "#/components/responses/BadRequest"
    },
    "401": {
      "$ref": "#/components/responses/Unauthorized"
    },
    "404": {
      "$ref": "#/components/responses/NotFound"
    }
  },
  "security": [
    {
      "Authorization": []
    }
  ],
  "x-speakeasy-group": "auth",
  "x-speakeasy-ignore": false,
  "x-speakeasy-name-override": "updateUserAttributes"
}

Auto-generated from OpenAPI spec and TypeScript definitions

Last updated: