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"]["UserAttribute"][];
            };
        };
        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"]["AuthBadRequest"];
            401: components["responses"]["Unauthorized"];
            403: components["responses"]["Forbidden"];
            404: components["responses"]["NotFound"];
            500: components["responses"]["InternalServerError"];
            504: components["responses"]["GatewayTimeout"];
        };
    };

Component References ​

ReferenceResolves To
components["schemas"]["UserAttribute"]UserAttribute
components["schemas"]["UserAttributeValue"]UserAttributeValue
components["responses"]["AuthBadRequest"]AuthBadRequest
components["responses"]["Unauthorized"]Unauthorized
components["responses"]["Forbidden"]Forbidden
components["responses"]["NotFound"]NotFound
components["responses"]["InternalServerError"]InternalServerError
components["responses"]["GatewayTimeout"]GatewayTimeout

Parameters ​

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

Request Body ​

Content Types: application/json

Responses ​

200 ​

OK

400 ​

Bad request

401 ​

Authentication failed. Codes include token-required, token-expired and token_not_valid for an invalid or expired token.

403 ​

Access denied. token-required requires an authenticated session; permission-denied means the caller cannot access this resource. On POS, session-expired requires signing in again.

404 ​

Requested resource not found

500 ​

The request failed because of an unexpected error.

504 ​

The request timed out.

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/UserAttribute"
          },
          "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/AuthBadRequest"
    },
    "401": {
      "$ref": "#/components/responses/Unauthorized"
    },
    "403": {
      "$ref": "#/components/responses/Forbidden"
    },
    "404": {
      "$ref": "#/components/responses/NotFound"
    },
    "500": {
      "$ref": "#/components/responses/InternalServerError"
    },
    "504": {
      "$ref": "#/components/responses/GatewayTimeout"
    }
  },
  "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: