
import CustomerFields from "../../../src/reference/subbly-sdk/types/SubblyCustomer.mdx";

<SdkPage group="customers" />

Every method here needs a signed-in customer. Sign one in with the
[authentication methods](/reference/subbly-sdk/auth) first.

<Method id="me" signature="subbly.customers.me()">

Gets the profile of the signed-in customer. `subbly.auth.checkAuthenticated`
calls it behind the scenes, so a failure here means the token no longer works.

<Returns type="Promise<SubblyCustomer>">
The customer profile.
<Properties label="customer">
  <CustomerFields />
</Properties>
</Returns>

<Example>

```js title="Get the customer profile"
const customer = await subbly.customers.me()
```

</Example>

</Method>

<Method id="update" signature="subbly.customers.update(payload)">

Changes the profile of the signed-in customer. Send only the fields you change.

<Params>
  <Param name="payload" required type="CustomerUpdatePayload">
    The fields to change. Every one is optional.

    <Properties label="payload">
      <Param name="firstName" optional type="string">
      Given name.
      </Param>
      <Param name="lastName" optional type="string">
      Family name.
      </Param>
      <Param name="marketingConsent" optional type="boolean">
      Whether the customer agreed to marketing email.
      </Param>
      <Param name="tosConsent" optional type="boolean">
      Whether the customer accepted the terms. Sending `true` stamps
      `tosConsentAt` with the current time.
      </Param>
      <Param name="externalId" optional type="string | null">
      Your own ID for this customer.
      </Param>
    </Properties>
  </Param>
</Params>

<Returns type="Promise<SubblyCustomer>">
The updated profile.
<Properties label="customer">
  <CustomerFields />
</Properties>
</Returns>

<Example>

```js title="Update the customer"
const customer = await subbly.customers.update({
  firstName: 'Ada',
  marketingConsent: true,
})
```

</Example>

</Method>

<Method id="referral" signature="subbly.customers.referral()">

Gets the referral link of the signed-in customer, to show on a "refer a friend"
page. Referrals must be switched on for the shop; check
`subbly.shop.referralSettings.enabled` first.

<Returns type="Promise<CustomersReferralResponse>">
The referral link.
<Properties label="response">
  <Param name="referralLink" type="string">
  The URL the customer shares.
  </Param>
</Properties>
</Returns>

<Example>

```js title="Get the referral link"
const { referralLink } = await subbly.customers.referral()
```

</Example>

</Method>
