# Action Action represents a request that the frontend can send to a backend service. Actions can be used to execute custom functions on the API hub such as requesting data from third-party services or updating the session information. Actions are called through custom endpoints known as action extensions. To learn more about action extensions, read the [developing an action extension](/frontend-development/developing-an-action-extension.md) documentation. ## Get data using an action Use the GET method to allow the frontend to fetch data from a backend system. Endpoint: `https://PROJECT_NAME-COMPANY_NAME.frontastic.TLD/frontastic/action/NAMESPACE/ACTION_NAME` Method: `GET` Headers: - `Accept` - `application/json` - Required - `Frontastic-Locale` - [Locale](/frontend-api/types.md#locale) - Required - `Commercetools-Frontend-Extension-Version` - [Extension version](/frontend-development/extensions.md#extension-version) - Required Path parameters: - `PROJECT_NAME` - String - Required - `COMPANY_NAME` - String - Required - `TLD` - String - Required The top-level domain for the environment, which includes `.live`, `.io`, and `.rocks`. For more information, see [Hosts](/frontend-api/general.md#hosts). - `NAMESPACE` - String - Required The namespace where the action to call is located. [Namespaces are used to categorize actions](/frontend-development/developing-an-action-extension.md#1-implement-the-action). - `ACTION_NAME` - String - Required The name of the action to call. Response: we recommend to use standard HTTP response codes and `application/json` encoded content. The response will be structured [as defined by the `body` property of the action](/frontend-development/developing-an-action-extension.md#1-implement-the-action). The [response example](/frontend-api/action.md#response-example) contains information about a cart. ## Write data using an action Use the POST or PUT method to write data to a backend system. Endpoint: `https://PROJECT_NAME-COMPANY_NAME.frontastic.TLD/frontastic/action/NAMESPACE/ACTION_NAME` Method: `POST` or `PUT` Headers: - `Accept` - `application/json` - Required - `Frontastic-Locale` - [Locale](/frontend-api/types.md#locale) - Required - `Commercetools-Frontend-Extension-Version` - [Extension version](/frontend-development/extensions.md#extension-version) - Required Path parameters: - `PROJECT_NAME` - String - Required - `COMPANY_NAME` - String - Required - `TLD` - String - Required The top-level domain for the environment, which includes `.live`, `.io`, and `.rocks`. For more information, see [Hosts](/frontend-api/general.md#hosts). - `NAMESPACE` - String - Required The namespace where the action to call is located. [Namespaces are used to categorize actions](/frontend-development/developing-an-action-extension.md#1-implement-the-action). - `ACTION_NAME` - String - Required The name of the action to call. Request body: any JSON serializable payload is accepted. The [request example](/frontend-api/action.md#request-example) adds a product to a cart. Response: we recommend to use standard HTTP response codes and `application/json` encoded content. [The response will be structured as defined by the `body` property of the action](/frontend-development/developing-an-action-extension.md#1-implement-the-action). The [response example](/frontend-api/action.md#response-example) contains the updated cart information, which includes the added product. ## Examples ### Request example ```json { "variant": { "sku": "M0E200KJ1200DSDJ", "count": 1 } } ``` ### Response example ```json { "cartId": "534a5f86-ea14-4b54-b2da-62a0672707e1", "cartVersion": "15", "lineItems": [ { "lineItemId": "d41690bc-ea20-4254-b10b-8dxeac87c1b0", "productId": "6bgggaf4-c2b8-4ba7-945e-95e2a113a41f", "name": "Casual jacket", "type": "variant", "count": 1, "price": { "fractionDigits": 2, "centAmount": 39900, "currencyCode": "EUR" }, "discountTexts": [], "discounts": [], "totalPrice": { "fractionDigits": 2, "centAmount": 39900, "currencyCode": "EUR" }, "variant": { "id": "1", "sku": "M0E200KJ1200DSDJ", "images": [ "https://your-storage.com/images/casual_jacket.jpg" ], "groupId": "78d95", "attributes": { "articleNumberManufacturer": "621840423 V0065", "articleNumberMax": "78665", "matrixId": "M0E200KJ1200DSDJ", "baseId": "78665", "designer": { "key": "casual", "label": "casual" }, "madeInItaly": { "key": "no", "label": "no" }, "commonSize": { "key": "xxs", "label": "XXS" }, "size": "XXS", "color": { "key": "black", "label": "Black" }, "colorFreeDefinition": "black", "style": { "key": "sporty", "label": "sporty" }, "gender": { "key": "men", "label": "Men" }, "season": "S15" }, "price": { "fractionDigits": 2, "centAmount": 39900, "currencyCode": "EUR" }, "isOnStock": true }, "isGift": false, "_url": "/slug/p/M0E200KJ1200DSDJ" } ], "sum": { "fractionDigits": 2, "centAmount": 39900, "currencyCode": "EUR" }, "shippingAddress": {}, "billingAddress": {}, "payments": [], "discountCodes": [] } ``` ## Related pages - [Area overview page with navigation](/frontend-api.md)