Composable Frontend 2.0 Learn more 

  • Commerce Cloud/
    Carts/
    Customer Cart Associations API/
    Create an Association

    Create a Customer-Cart Association

    You can create associations between a customer and one or more carts. After cart associations exist for a customer, the customer can access those carts across any device.

    POST Create an association between a customer and a cart

    https://useast.api.elasticpath.com/v2/carts/:cartId/relationships/customers
    

    Creates an association between a cart (:cart_id) and a customer.

    Parameters

    Path parameters

    NameRequiredTypeDescription
    cartIdRequiredstringThe ID for the cart created by the customer. Ensure that you follow the guidelines for Safe Characters.

    Headers

    NameRequiredTypeDescription
    X-Moltin-Customer-TokenRequiredstringA customer token to access a specific customer's carts.
    AuthorizationRequiredstringThe Bearer token required to get access to the API. If there is no customer token, the grant type must be client_credentials.

    Body

    NameRequiredTypeDescription
    data[].typeRequiredstringThe type of related object. Ensure that it is customer.
    data[].idRequiredstringThe id of the customer.

    Request Examples

    With customer token

    Requires an implicit token with a customer token.

    Curl

    curl -X POST https://useast.api.elasticpath.com/v2/carts/:cartId/relationships/customers \
         -H "X-Moltin-Customer-Token: XXXX" \
         -H "Authorization: Bearer XXXX" \
         -H "Content-Type: application/json" \
         -d $ {
          "data": [{
              "type": "customer",
              "id": "b3f2b6de-8fd4-4cdf-a9d9-c5f7cecccdfe"
              }]
          }
    

    JavaScript SDK

    const customerId = "25617d3e-14a6-434c-bfab-3fda87517aaf";
    const customerToken = "xxxx";
    
    
    // Where `EPCC` is an authenticated client
    await EPCC.Carts.AddCustomerAssociation(customerId, customerToken);
    

    Without customer token

    Requires a client_credentials token.

    Curl

    curl -X POST https://useast.api.elasticpath.com/v2/carts/:cartId/relationships/customers \
         -H "Authorization: Bearer XXXX" \
         -H "Content-Type: application/json" \
         -d $ {
          "data": [{
              "type": "customer",
              "id": "b3f2b6de-8fd4-4cdf-a9d9-c5f7cecccdfe"
              }]
          }
    

    JavaScript SDK

    const customerId = "25617d3e-14a6-434c-bfab-3fda87517aaf";
    
    
    // Where `EPCC` is an authenticated client
    await EPCC.Carts.AddCustomerAssociation(customerId);
    

    Response Example

    200 OK

    {
        "data": [
            {
                "type": "customer",
                "id": "b3f2b6de-8fd4-4cdf-a9d9-c5f7cecccdfe"
            }
        ]
    }
    

    204 No Content is sent back in case the customer has already been associated to the cart.

    Previous
    Get a Customerʼs Carts