Add Account and Login (Before)

This action manipulates the HTTP request or response before the AddAccountAndLogin operation occurs in Kibo eCommerce.

Action TypeHTTP
Full Action IDhttp.commerce.customer.accounts.addAccountAndLogin.before
Runs multiple custom functions?Yes

JavaScript File Structure

Action files share the following basic structure:

module.exports = function(context, callback) {
   // Your custom code here
   callback();
};

When you code the custom function for an action, you have access to two arguments:

callback—This argument follows the established JavaScript callback pattern: it takes an error as the first argument (or null if there is no error) and a result as the second argument (if required).

context—This argument provides the function access to relevant objects and methods that interface with Kibo eCommerce.

Context: HTTP

The following methods and objects are available to this action through the use of the context argument.

REST API Operation
This action corresponds to the api/commerce/customer/addAccountAndLogin operation.

HTTP Request

POST api/commerce/customer/accounts/Add-Account-And-Login?responseFields={responseFields}

Request Body
Use context.request.body to read/write the HTTP request body using this action.

Response Body
Use context.response.body to write the HTTP response body using this action.

Delegated Authorization
The API operation that this action interacts with uses delegated authorization to verify that the caller has access to the requested API resource. If you use context.response.end() to exit the function early, you must manually specify the authorization of the caller to avoid an authorization error. To specify that the caller is authorized, use context.exec.setAuthorized(true). To specify the caller is not authorized, use context.exec.setAuthorized(false).

Context Objects Available to All HTTP Actions

Context Methods Available to All HTTP Actions

Context Objects Available to All Actions

Context Objects Available to All HTTP Actions

request

Accesses the current HTTP request. In the case of Before actions, updates can be made to the request before Kibo eCommerce processes it.

PropertiesTypeDescription
paramsobjectThe input parameters to the service or webpage.
headersobjectThe request headers.
methodstringThe request method.
urlstringThe request URL.
pathstringThe request path.
cookiesobject

The request cookies.

*Available only for Storefront HTTP actions.

queryobjectThe request query.
hrefstringThe request href.
secureBooleanIndicates whether the request uses HTTPS.
ipstringThe request IP address.
ipsstringThe request secure IP address.
bodyobjectThe request body of the API operation associated with this action.

Example:

context.request.url;

response

Accesses the current HTTP response. For both Before and After actions, updates can be made to the response before Kibo eCommerce processes it.

PropertiesTypeDescription
headerobjectThe response header collection.
viewDataobject

The viewData collection used by the storefront rendering engine.

*Available only for Storefront HTTP actions.

viewNamestring

The response viewName value.

*Available only for Storefront HTTP actions.

bodyobjectThe response body of the API operation associated with this action.
statusintegerThe response status code.
messagestringThe response message.
lengthintegerThe response length.
typestringThe response type.

Example:

context.response.header;

Context Methods Available to All HTTP Actions

request.get

Returns an HTTP header value for the specified header key.

ParametersTypeDescription
keystringThe header key.

Example:

context.request.get(field);

Response:

"object"

response.get

Gets a field from the response.

ParametersTypeDescription
keyobjectThe field to obtain.

Example:

context.response.get(field);

Response:

"string"

response.set

Sets the HTTP headers for the response.

ParametersTypeDescription
valuesobjectThe values for the HTTP headers.

Example:

context.response.set({ myCustomHeader: "howdy" });

Response: N/A

response.set2

Updates a field in the response.

ParametersTypeDescription
keystringThe key of the field.
valuestringThe value of the field.

Example:

context.response.set("name", "stuff");

Response: N/A  

response.remove

Removes an HTTP header from the response.

ParametersTypeDescription
keystringThe HTTP header to remove.

Example:

context.response.remove(header);

Response: N/A  

response.redirect

Redirects the incoming URL.

ParametersTypeDescription
urlstringThe destination URL.

Example:

context.response.redirect("http://someOtherSite/foo");

Response: N/A  

response.end

Ends the response so that other actions or Kibo eCommerce logic can run. Also, signals the callback to complete.

ParametersTypeDescription
N/AN/AN/A

Example:

context.response.end();

Response: N/A

get.resource

Returns the currently persisted value of the requested resource. **Not available for all calls.

ParametersTypeDescription
N/AN/AN/A

Example:

context.get.resource();

Response: N/A  

get.resourceStatus

Gets the HTTP resource status.

ParametersTypeDescription
N/AN/AN/A

Example:

context.get.resourceStatus();

Response: N/A  

items.urlHelper.getUrl

Gets the current URL.

ParametersTypeDescription
type

object

config

Example:

context.items.urlHelper.getUrl(type, object, config);

Context Objects Available to All Actions

apiContext

Accesses Kibo eCommerce tenant information.

PropertiesTypeDescription
baseUrlstringThe base URL for the site.
basePciUrlstringThe base PCI URL for the site.
tenantPodstringThe name of the tenant pod in which the tenant resides.
appClaimsstringThe application claims token.
appKeystringThe application key.
tenantIdintegerUnique identifier for the tenant.
siteIdintegerUnique identifier for the site. This ID is used at all levels of a store, catalog, and tenant to associate objects to a site.
masterCatalogIdintegerUnique identifier for the master catalog.
catalogIdintegerThe unique identifier for the product catalog. Catalogs are part of a master catalog.
currencyCodestringThe default three-letter ISO currency code for monetary amounts.
previewDatedate/timeThe date and time that the content is being viewed. This might be a future date if the content is previewed with an active date range set in the future.
localeCodestringThe locale code per the country code provided. This code determines the localized content to use and display.
correlationIdstringThe unique identifier of the API request associated with the event action, which might contain multiple actions.
isAuthorizedAsAdminBooleanIndicates whether the Dev Account user is authorized as an admin.
userClaimsstringThe user claims token.

Example:

context.apiContext.baseUrl;

configuration

Receives a JSON response that contains information about the configuration data set in the Action Management JSON editor.

PropertiesTypeDescription
VariesobjectCustom fields and values that you can set in the Action Management JSON Editor.

Example:

context.configuration.customData;