Custom attributes in Adobe Commerce as a Cloud Service
Custom attributes can extend the core data model in Adobe Commerce. Since you cannot modify the Cloud Service data model directly, custom attributes allow you to add additional attributes to entities without requiring code or database schema changes.
Consider a situation where you want to modify specify a duns_number
or industry_type
information for a company. Custom attributes make this possible.
The following entities support custom attributes in Adobe Commerce as a Cloud Service:
Quote
QuoteItem
Order
OrderItem
Invoice
InvoiceItem
CreditMemo
CreditMemoItem
NegotiableQuote
Company
All custom attribute values are strings.
Add custom attributes with REST
You can manage custom attributes using existing REST endpoints. For example, you can set custom attributes for credit memos with POST /V1/creditmemo
and retrieve those attributes with GET /V1/creditmemo/:id
.
Request
Copied to your clipboard{"entity": {"order_id": 53,"items": [{"order_item_id": 83,"custom_attributes": [{"attribute_code": "attribute_one","value": "value_one"}]}],"custom_attributes": [{"attribute_code": "attribute_one","value": "value_one"}]}}
Response
Copied to your clipboard{"entity_id": 71,"order_id": 53,"items": [{"order_item_id": 83,"custom_attributes": [{"attribute_code": "attribute_one","value": "value_one"}]}],"custom_attributes": [{"attribute_code": "attribute_one","value": "value_one"}]}
Add custom attributes with GraphQL
You can manage custom attributes using new setCustomAttributesOn
mutations and existing queries. For example, you can add custom attributes to Cart
and CartItem
using the setCustomAttributesOnCart
and setCustomAttributesOnCartItem
mutations.
The following example adds a custom Cart
attribute of code_one
:value_one
:
Copied to your clipboardmutation {setCustomAttributesOnCart(input: {cart_id: "38"custom_attributes: [{ attribute_code: "code_one", value: "value_one" }]}) {cart {idcustom_attributes {attribute_codevalue}}}}
Query
The values are available in the cart
query, or any query that returns a Cart
object:
Copied to your clipboard{cart(cart_id: "38") {items {id}custom_attributes {attribute_codevalue}}}
Response
The response will include the custom attribute:
Copied to your clipboard{"data": {"cart": {"items": [{"id": "24"}],"custom_attributes": [{"attribute_code": "code_one","value": "value_one"}]}}}