registerGuestBuyer(guestBuyerInput)

Registers a guest buyer account against a webstore.

Syntax 

1import { registerGuestBuyer } from 'lightning/commerceRegisterGuestBuyerApi';
2registerGuestBuyer(guestBuyerInput: object): Promise<RegisterGuestBuyerOutput>

Commerce API Resource 

1POST /commerce/webstores/{webstoreId}/accounts/{accountId}/actions/register-guest-buyer

registerGuestBuyer uses this Commerce API resource.

Parameters 

  • webstoreId—(Required) The ID of the webstore. The ID prefix is 0ZE.
  • accountId—(Required) The ID of the account to register as a guest buyer. The ID prefix is 001.
  • version—(Required) The API version for the adapter, for example, v62.0. Without this parameter, the call doesn’t fire.
  • registerGuestBuyerInput—(Optional) The request body. Pass an empty object {} when no fields are required.

Returns 

A Promise that resolves with a RegisterGuestBuyerOutput object with these fields:

  • success—Indicates whether the registration was successful. Check this field even when the Promise resolves, because it can be false without the call throwing an error.
  • errors—A list of errors if the registration failed. Each error has these fields:
    • errorCode—A machine-readable error code.
    • message—A human-readable error message.
    • errorEntityId—The ID of the entity the error relates to, when applicable.

Usage 

registerGuestBuyer is an imperative function, not a @wire adapter. It performs a mutation and must be called in response to a user action.

1import { LightningElement, api } from 'lwc';
2import { registerGuestBuyer } from 'lightning/commerceRegisterGuestBuyerApi';
3
4export default class RegisterGuestBuyerExample extends LightningElement {
5  @api webstoreId;
6  @api accountId;
7
8  async handleRegister() {
9    try {
10      const result = await registerGuestBuyer({
11        webstoreId: this.webstoreId,
12        accountId: this.accountId,
13        version: 'v62.0',
14        registerGuestBuyerInput: {},
15      });
16
17      if (result.success) {
18        console.log('Guest buyer registered successfully');
19      } else {
20        console.error('Registration failed:', result.errors);
21      }
22    } catch (error) {
23      console.error('Error registering guest buyer:', error);
24    }
25  }
26}

Error Handling 

Always check the success field on the resolved value. A resolved Promise doesn’t guarantee a successful registration. If the call itself fails, the Promise rejects with an error.

Release Preview

This release is in preview. Features described here don't become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can't guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.