> ## Documentation Index
> Fetch the complete documentation index at: https://www.commercengine.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# My Account

> This section details the APIs used to build the "My Account" area of your storefront, allowing logged-in customers to manage their profile, view past orders, handle returns or cancellations, update addresses, track loyalty points, and manage their reviews.

<Info>
  **Authentication Required**

  All endpoints described in this section require a **logged-in user's Bearer token** for authentication. The `{user_id}` path parameter in many Customer-related endpoints must correspond to the user associated with the token.
</Info>

<AccordionGroup>
  <Accordion title="Managing User Profile">
    These endpoints allow users to view and update their basic information.

    * **Retrieve User Details:**
      * `GET /auth/user/{id}`: Fetches the complete `User` object, including name, email, phone, verification status, profile image URL, and notification preferences. Use the user's ID obtained after login.
      * Display this information on the profile page.
    * **Update User Details:**
      * `PUT /auth/user/{id}`: Allows users to update fields like `first_name`, `last_name`, `email`, or `phone`. (Note: Changing email/phone might trigger a verification flow using `POST /auth/generate-otp` with `otp_action: update-email` or `update-phone`, followed by `POST /auth/verify-otp`).
    * **Manage Profile Image:**
      * `POST /auth/user/{id}/profile-image`: Upload a new profile picture (`multipart/form-data`).
      * `PUT /auth/user/{id}/profile-image`: Replace the existing profile picture.
      * `DELETE /auth/user/{id}/profile-image`: Remove the profile picture.
      * `GET /auth/user/{id}/profile-image`: Retrieve the current image URL (often included in the main `GET /auth/user/{id}` response anyway).
    * **Manage Notification Preferences:**
      * `GET /auth/user/{id}/notification-preferences`: Retrieve current opt-in/out status for transactional, promotional, and newsletter communications across channels (email, SMS, WhatsApp).
      * `PUT /auth/user/{id}/notification-preferences`: Update these preferences based on user selections.
    * **Password Management (If applicable):**
      * `POST /auth/change-password`: Allows logged-in users to change their existing password.
  </Accordion>

  <Accordion title="Address Book">
    Manage the customer's saved billing and shipping addresses.

    * **List Addresses:**
      * `GET /customers/{user_id}/addresses`: Retrieves a paginated list of all saved addresses for the user. Each address object includes `is_default_billing` and `is_default_shipping` flags.
      * Use this to display the address book.
    * **Retrieve Single Address:**
      * `GET /customers/{user_id}/addresses/{address_id}`: Fetches the details of one specific address.
    * **Create Address:**
      * `POST /customers/{user_id}/addresses`: Adds a new address to the user's address book. The request body includes the `CustomerAddress` fields plus optional `is_default_billing` and `is_default_shipping` flags.
    * **Update Address:**
      * `PUT /customers/{user_id}/addresses/{address_id}`: Modifies an existing address. Allows changing details and default status flags.
    * **Delete Address:**
      * `DELETE /customers/{user_id}/addresses/{address_id}`: Removes an address from the address book. Ensure checks are in place if the address is linked to active subscriptions.

    **Address Management Flow:**

    <Frame caption="Address Management Flow">
      <iframe title="Address Management Flow" allowfullscreen width="100%" height="600" src="https://mermaid.tarkai.dev/embed?definition=sequenceDiagram%0A%20%20%20%20participant%20ClientApp%20as%20Client%20Application%0A%20%20%20%20participant%20User%0A%20%20%20%20participant%20CE_API%20as%20CE%20API%0A%0A%20%20%20%20User-%3E%3EClientApp%3A%20Navigates%20to%20%22My%20Addresses%22%0A%20%20%20%20ClientApp-%3E%3ECE_API%3A%20GET%20%2Fcustomers%2F%7BuserId%7D%2Faddresses%20(Header%3A%20Auth%20Bearer)%0A%20%20%20%20activate%20CE_API%0A%20%20%20%20CE_API--%3E%3EClientApp%3A%20200%20OK%20(List%20of%20Addresses)%0A%20%20%20%20deactivate%20CE_API%0A%20%20%20%20ClientApp-%3E%3EClientApp%3A%20Render%20Address%20Book%20UI%20(List%2C%20Add%2C%20Edit%2C%20Delete%20buttons)%0A%0A%20%20%20%20User-%3E%3EClientApp%3A%20Clicks%20%22Add%20New%20Address%22%0A%20%20%20%20User-%3E%3EClientApp%3A%20Fills%20Address%20Form%0A%20%20%20%20ClientApp-%3E%3ECE_API%3A%20POST%20%2Fcustomers%2F%7BuserId%7D%2Faddresses%0A%20%20%20%20activate%20CE_API%0A%20%20%20%20CE_API--%3E%3EClientApp%3A%20200%20OK%20(New%20Address%20Created)%0A%20%20%20%20deactivate%20CE_API%0A%20%20%20%20ClientApp-%3E%3EClientApp%3A%20Refresh%20Address%20List%0A%0A%20%20%20%20User-%3E%3EClientApp%3A%20Clicks%20%22Delete%22%20on%20an%20Address%0A%20%20%20%20ClientApp-%3E%3ECE_API%3A%20DELETE%20%2Fcustomers%2F%7BuserId%7D%2Faddresses%2F%7BaddressId%7D%0A%20%20%20%20activate%20CE_API%0A%20%20%20%20CE_API--%3E%3EClientApp%3A%20200%20OK%20(Address%20Deleted)%0A%20%20%20%20deactivate%20CE_API%0A%20%20%20%20ClientApp-%3E%3EClientApp%3A%20Refresh%20Address%20List" />
    </Frame>
  </Accordion>

  <Accordion title="Order History & Management">
    Allow customers to view their past orders and perform post-purchase actions.

    * **List Orders:**
      * `GET /orders`: Retrieves a paginated list of the customer's orders.
      * **Query Parameters:**
        * `user_id`: **Required**. The ID of the logged-in customer.
        * `page`, `limit`, `sort_by`: Standard pagination/sorting (e.g., sort by `order_date` descending).
        * `status[]`: Filter orders by specific statuses (e.g., `shipped`, `delivered`, `cancelled`).
      * **Response:** Contains `orders` (array of `OrderList` objects, a summary view) and `pagination`. Display key info like order number, date, status, total amount, and primary item image(s).
    * **Retrieve Order Detail:**
      * `GET /orders/{order_number}`: Fetches the complete details (`OrderDetail` object) for a single order, including all items, addresses, pricing breakdown, payment info, cancellation status, etc. Use this for the detailed order view page.
    * **Retrieve Order Shipments:**
      * `GET /orders/{order_number}/shipments`: Retrieves shipment details associated with an order (tracking number, status, courier, items included in each shipment). An order might have multiple shipments.
      * **Response:** Contains `shipments` (array of `OrderShipment` objects).
    * **Retrieve Order Payments:**
      * `GET /orders/{order_number}/payments`: Lists all payment transactions (successful payments, potentially failed attempts if logged) associated with the order.
      * **Response:** Contains `payments` (array of `OrderPayment` objects).
    * **Retrieve Order Refunds:**
      * `GET /orders/{order_number}/refunds`: Lists any refunds processed for the order.
      * **Response:** Contains `refunds` (array of `OrderRefund` objects).
    * **Cancel Order:**
      * `POST /orders/{order_number}/cancel`: Allows a customer to request cancellation of an entire order.
      * **Availability:** Check the `is_cancellation_allowed` flag returned by `GET /orders/{order_number}` before showing the cancel button. Cancellation might only be possible before the order is processed or shipped.
      * **Request Body:**
        * `cancellation_reason`: Required reason text.
        * `refund_mode`: Required (`original_payment_mode` or `bank_transfer`).
        * `bank_account_id`: Required if `refund_mode` is `bank_transfer`. (Requires separate flow for securely collecting and verifying bank details, potentially using Admin APIs or dedicated UI).
        * `feedback`: Optional additional comments.
      * **Response:** `200 OK` with the updated `OrderDetail` showing status as 'cancelled'.
    * **Retry Payment:**
      * `POST /orders/{order_number}/retry-payment`: Initiates a new payment attempt for an order where the initial payment failed but `is_retry_available` was true (checked via `GET /orders/{order_number}/payment-status`). See Checkout Flow (Step 9/10) for usage.
    * **Returns:**
      * Returns are currently **managed by store administrators** through the Admin Portal. There is no storefront API for customers to initiate returns directly.
      * Customers who need to return items should contact the store's customer support, and the admin will process the return from the Admin Portal.
      * Return APIs for the storefront are under development.

    **Order History / Cancellation Flow:**

    <Frame caption="Order History / Cancellation Flow">
      <iframe title="Order History / Cancellation Flow" allowfullscreen width="100%" height="1000" src="https://mermaid.tarkai.dev/embed?definition=sequenceDiagram%0A%20%20%20%20participant%20ClientApp%20as%20Client%20Application%0A%20%20%20%20participant%20User%0A%20%20%20%20participant%20CE_API%20as%20CE%20API%0A%0A%20%20%20%20User-%3E%3EClientApp%3A%20Navigates%20to%20%22My%20Orders%22%0A%20%20%20%20ClientApp-%3E%3ECE_API%3A%20GET%20%2Forders%3Fuser_id%3D%7BuserId%7D%0A%20%20%20%20activate%20CE_API%0A%20%20%20%20CE_API--%3E%3EClientApp%3A%20200%20OK%20(Paginated%20List%20of%20Order%20Summaries)%0A%20%20%20%20deactivate%20CE_API%0A%20%20%20%20ClientApp-%3E%3EClientApp%3A%20Render%20Order%20History%20List%0A%0A%20%20%20%20User-%3E%3EClientApp%3A%20Clicks%20on%20a%20specific%20Order%0A%20%20%20%20ClientApp-%3E%3ECE_API%3A%20GET%20%2Forders%2F%7BorderNumber%7D%0A%20%20%20%20activate%20CE_API%0A%20%20%20%20CE_API--%3E%3EClientApp%3A%20200%20OK%20(Full%20OrderDetail)%0A%20%20%20%20deactivate%20CE_API%0A%20%20%20%20ClientApp-%3E%3EClientApp%3A%20Render%20Order%20Detail%20Page%0A%20%20%20%20ClientApp-%3E%3EClientApp%3A%20Check%20'is_cancellation_allowed'%20flag%20from%20OrderDetail%0A%0A%20%20%20%20alt%20Cancellation%20Allowed%0A%20%20%20%20%20%20%20%20ClientApp-%3E%3EUser%3A%20Show%20%22Cancel%20Order%22%20Button%0A%20%20%20%20%20%20%20%20User-%3E%3EClientApp%3A%20Clicks%20%22Cancel%20Order%22%0A%20%20%20%20%20%20%20%20User-%3E%3EClientApp%3A%20Provides%20Reason%2C%20Selects%20Refund%20Mode%0A%20%20%20%20%20%20%20%20ClientApp-%3E%3ECE_API%3A%20POST%20%2Forders%2F%7BorderNumber%7D%2Fcancel%0A%20%20%20%20%20%20%20%20activate%20CE_API%0A%20%20%20%20%20%20%20%20CE_API--%3E%3EClientApp%3A%20200%20OK%20(Updated%20OrderDetail%20with%20status%20'cancelled')%0A%20%20%20%20%20%20%20%20deactivate%20CE_API%0A%20%20%20%20%20%20%20%20ClientApp-%3E%3EClientApp%3A%20Update%20UI%20to%20show%20cancelled%20status%0A%20%20%20%20else%20Cancellation%20Not%20Allowed%0A%20%20%20%20%20%20%20%20ClientApp-%3E%3EUser%3A%20Hide%2FDisable%20%22Cancel%20Order%22%20Button%0A%20%20%20%20end" />
    </Frame>
  </Accordion>

  <Accordion title="Loyalty Program Activity">
    If the loyalty program is enabled, users can track their points.

    * **Retrieve Loyalty Summary:**
      * `GET /customers/{user_id}/loyalty`: Fetches the user's current loyalty status, including tier, total earned, redeemed, balance, and redeemable points. Display this in a dedicated loyalty section or user dashboard.
    * **List Loyalty Activity:**
      * `GET /customers/{user_id}/loyalty-points-activity`: Retrieves a paginated list of all transactions where points were earned or redeemed (e.g., points earned from an order, points redeemed in a cart).
      * **Response:** Contains `loyalty_points_activity` (array of `LoyaltyPointActivity` objects) and pagination.
  </Accordion>

  <Accordion title="Review Management">
    Allow users to see reviews they've submitted and potentially items awaiting review.

    * **List User Reviews & Items Ready for Review:**
      * `GET /customers/{user_id}/reviews`: Fetches two lists:
        * `reviews`: An array of `CustomerReview` objects representing reviews already submitted by the user (across all products).
        * `ready_for_review`: An array of `CustomerReadyForReview` objects, listing products from completed orders that the user hasn't reviewed yet.
      * Use `reviews` to show a "My Reviews" history.
      * Use `ready_for_review` to prompt users to submit new reviews, linking them to the product page or a dedicated review submission form (`POST /catalog/products/{product_id}/reviews`).
  </Accordion>
</AccordionGroup>
