diff --git a/src/pages/graphql/schema/b2b/company/mutations/create-address.md b/src/pages/graphql/schema/b2b/company/mutations/create-address.md new file mode 100644 index 000000000..7e3f9e91e --- /dev/null +++ b/src/pages/graphql/schema/b2b/company/mutations/create-address.md @@ -0,0 +1,255 @@ +--- +title: createCompanyAddress mutation +description: The createCompanyAddress mutation allows a company admin or user who is assigned a role that contains the Magento_CompanyAddressStorefrontCompatibility::add permission to create a new company address. +keywords: + - B2B +--- + + + +# createCompanyAddress mutation + + + +This mutation is part of the B2B Storefront Compatibility Package and is only available on [Adobe Commerce as a Cloud Service](https://experienceleague.adobe.com/en/docs/commerce/cloud-service/overview). + +The `createCompanyAddress` mutation allows a company admin or user who is assigned a role that contains the `Magento_CompanyAddressStorefrontCompatibility::add` permission to create a new company address. + +This mutation requires a valid [customer authentication token](../../../customer/mutations/generate-token.md). + +## Syntax + +```graphql +mutation { + createCompanyAddress( + input: CompanyAddressInput! + ) { + CompanyAddress + } +} +``` + +## Example usage + +### Create a company address (type: billing) + +The following example creates a company billing address. + +**Request:** + +```graphql +mutation CreateCompanyAddress { + createCompanyAddress( + input: { + nickname: "HQ Billing" + address_type: BILLING + is_default: true + firstname: "John" + lastname: "Doe" + middlename: "Q" + prefix: "Mr." + suffix: "Jr." + company: "Company name" + street: ["123 Main St"] + city: "Austin" + country_code: US + region: { + region_id: 57 + region: "Texas" + region_code: "TX" + } + postcode: "78701" + telephone: "5551234567" + fax: "5551234568" + vat_id: "US123456789" + custom_attributes: [ + { attribute_code: "my_custom_attr", value: "custom value" } + ] + } + ) { + id + nickname + company_id + address_type + is_default + firstname + lastname + middlename + prefix + suffix + company + street + city + country_code + region_id + region { + region_id + region + region_code + } + postcode + telephone + fax + vat_id + custom_attributes { + code + ... on AttributeValue { + value + } + } + } +} +``` + +**Response:** + +```json +{ + "data": { + "createCompanyAddress": { + "id": "MTI=", + "nickname": "HQ Billing", + "company_id": "Mw==", + "address_type": "BILLING", + "is_default": true, + "firstname": "John", + "lastname": "Doe", + "middlename": "Q", + "prefix": "Mr.", + "suffix": "Jr.", + "company": "Company name", + "street": ["123 Main St"], + "city": "Austin", + "country_code": "US", + "region_id": 57, + "region": { + "region_id": 57, + "region": "Texas", + "region_code": "TX" + }, + "postcode": "78701", + "telephone": "5551234567", + "fax": "5551234568", + "vat_id": "US123456789", + "custom_attributes": [] + } + } +} +``` + +### Create a company address (type: shipping) + +The following example creates a company billing address. + +**Request:** + +```graphql +mutation CreateCompanyAddress { + createCompanyAddress( + input: { + nickname: "HQ Shipping" + address_type: SHIPPING + is_default: true + firstname: "John" + lastname: "Doe" + middlename: "Q" + prefix: "Mr." + suffix: "Jr." + company: "Company name" + street: ["123 Main St"] + city: "Austin" + country_code: US + region: { + region_id: 57 + region: "Texas" + region_code: "TX" + } + postcode: "78701" + telephone: "5551234567" + fax: "5551234568" + vat_id: "US123456789" + custom_attributes: [ + { attribute_code: "my_custom_attr", value: "custom value" } + ] + } + ) { + id + nickname + company_id + address_type + is_default + firstname + lastname + middlename + prefix + suffix + company + street + city + country_code + region_id + region { + region_id + region + region_code + } + postcode + telephone + fax + vat_id + custom_attributes { + code + ... on AttributeValue { + value + } + } + } +} +``` + +**Response:** + +```json +{ + "data": { + "createCompanyAddress": { + "id": "MTM=", + "nickname": "HQ Shipping", + "company_id": "Mw==", + "address_type": "SHIPPING", + "is_default": true, + "firstname": "John", + "lastname": "Doe", + "middlename": "Q", + "prefix": "Mr.", + "suffix": "Jr.", + "company": "Company name", + "street": ["123 Main St"], + "city": "Austin", + "country_code": "US", + "region_id": 57, + "region": { + "region_id": 57, + "region": "Texas", + "region_code": "TX" + }, + "postcode": "78701", + "telephone": "5551234567", + "fax": "5551234568", + "vat_id": "US123456789", + "custom_attributes": [] + } + } +} +``` + +## Errors + +| Error | Description | +| --- | --- | +| `Customer is not a company user.` | Not authenticated or not a company user | +| `Company context is required.` | Missing `X-Adobe-Company` header | +| `Company address book is not enabled for this company.` | Address book disabled for company | +| `You do not have authorization to perform this action.` | Missing add or set-default ACL | + + diff --git a/src/pages/graphql/schema/b2b/company/mutations/delete-address.md b/src/pages/graphql/schema/b2b/company/mutations/delete-address.md new file mode 100644 index 000000000..d2c9f50b6 --- /dev/null +++ b/src/pages/graphql/schema/b2b/company/mutations/delete-address.md @@ -0,0 +1,54 @@ +--- +title: deleteCompanyAddress mutation +description: The deleteCompanyAddress mutation allows a company admin or user who is assigned a role that contains the Magento_CompanyAddressStorefrontCompatibility::delete permission to delete an existing company address. +keywords: + - B2B +--- + + + +# deleteCompanyAddress mutation + + + +This mutation is part of the B2B Storefront Compatibility Package and is only available on [Adobe Commerce as a Cloud Service](https://experienceleague.adobe.com/en/docs/commerce/cloud-service/overview). + +The `deleteCompanyAddress` mutation allows a company admin or user who is assigned a role that contains the `Magento_CompanyAddressStorefrontCompatibility::delete` permission to delete an existing company address using a provided company UID. + +This mutation requires a valid [customer authentication token](../../../customer/mutations/generate-token.md). + +## Syntax + +```graphql +mutation { + deleteCompanyAddress( + id: ID! + ) { + Boolean + } +} +``` + +## Example usage + +### Delete a company address + +The following example deletes an existing company address. + +**Request:** + +```graphql +mutation DeleteCompanyAddress { + deleteCompanyAddress(id: "MTI=") +} +``` + +**Response:** + +```json +{ + "data": { + "deleteCompanyAddress": true + } +} +``` diff --git a/src/pages/graphql/schema/b2b/company/mutations/index.md b/src/pages/graphql/schema/b2b/company/mutations/index.md index dfa398391..4a2adca8a 100644 --- a/src/pages/graphql/schema/b2b/company/mutations/index.md +++ b/src/pages/graphql/schema/b2b/company/mutations/index.md @@ -17,3 +17,10 @@ The B2B company mutations allow you to perform the management operations: * Move the position of a company team in the company hierarchy. * Create, update, and delete company roles. * Assign and unassign a company to a company hierarchy. + +# Company Address Book mutations + +The company address book mutations allow you to perform the company address management operations: + +* Create, update and delete a company address. +* Set default company billing or shipping address. \ No newline at end of file diff --git a/src/pages/graphql/schema/b2b/company/mutations/set-default-address.md b/src/pages/graphql/schema/b2b/company/mutations/set-default-address.md new file mode 100644 index 000000000..885451d35 --- /dev/null +++ b/src/pages/graphql/schema/b2b/company/mutations/set-default-address.md @@ -0,0 +1,95 @@ +--- +title: setDefaultCompanyAddress mutation +description: The setDefaultCompanyAddress mutation allows a company admin or user who is assigned a role that contains the Magento_CompanyAddressStorefrontCompatibility::default permission to set a company address based on the provided address UID as the default billing or shipping address for the company. +keywords: + - B2B +--- + + + +# setDefaultCompanyAddress mutation + + + +This mutation is part of the B2B Storefront Compatibility Package and is only available on [Adobe Commerce as a Cloud Service](https://experienceleague.adobe.com/en/docs/commerce/cloud-service/overview). + +The `setDefaultCompanyAddress` mutation allows a company admin or user who is assigned a role that contains the `Magento_CompanyAddressStorefrontCompatibility::default` permission to set a company address based on the provided address UID as the default billing or shipping address for the company. + +This mutation requires a valid [customer authentication token](../../../customer/mutations/generate-token.md). + +## Syntax + +```graphql +mutation { + setDefaultCompanyAddress( + id: ID! + ) { + CompanyAddress + } +} +``` + +## Example usage + +### Set a company address as default (BILLING/SHIPPING) + +The following example sets an existing company address as default. + +**Request:** + +```graphql +mutation SetDefaultCompanyAddress { + setDefaultCompanyAddress(id: "MTI=") { + id + address_type + is_default + nickname + city + country_code + } +} +``` + +**Response (Billing):** + +```json +{ + "data": { + "setDefaultCompanyAddress": { + "id": "MTI=", + "address_type": "BILLING", + "is_default": true, + "nickname": "HQ Billing", + "city": "Austin", + "country_code": "US" + } + } +} +``` +**Response (Shipping):** + +```json +{ + "data": { + "setDefaultCompanyAddress": { + "id": "MTM=", + "address_type": "SHIPPING", + "is_default": true, + "nickname": "Warehouse", + "city": "Austin", + "country_code": "US" + } + } +} +``` + +After setting defaults, you can read them from the Company type: + +```graphql +{ + company { + default_billing_address { id address_type is_default } + default_shipping_address { id address_type is_default } + } +} +``` \ No newline at end of file diff --git a/src/pages/graphql/schema/b2b/company/mutations/update-address.md b/src/pages/graphql/schema/b2b/company/mutations/update-address.md new file mode 100644 index 000000000..c0cb27865 --- /dev/null +++ b/src/pages/graphql/schema/b2b/company/mutations/update-address.md @@ -0,0 +1,102 @@ +--- +title: updateCompanyAddress mutation +description: The updateCompanyAddress mutation allows a company admin or user who is assigned a role that contains the Magento_CompanyAddressStorefrontCompatibility::edit permission to update an existing company address. +keywords: + - B2B +--- + + + +# updateCompanyAddress mutation + + + +This mutation is part of the B2B Storefront Compatibility Package and is only available on [Adobe Commerce as a Cloud Service](https://experienceleague.adobe.com/en/docs/commerce/cloud-service/overview). + +The `updateCompanyAddress` mutation allows a company admin or user who is assigned a role that contains the `Magento_CompanyAddressStorefrontCompatibility::edit` permission to update an existing company address. + +This mutation requires a valid [customer authentication token](../../../customer/mutations/generate-token.md). + +## Syntax + +```graphql +mutation { + updateCompanyAddress( + id: ID! + input: CompanyAddressInput! + ) { + CompanyAddress + } +} +``` + +## Example usage + +### Update a company address + +The following example updates an existing company address. + +**Request:** + +```graphql +mutation UpdateCompanyAddress { + updateCompanyAddress( + id: "MTI=" + input: { + nickname: "Updated Nickname" + address_type: BILLING + is_default: false + firstname: "Jane" + lastname: "Smith" + company: "Updated Corp" + street: ["456 Oak Ave"] + city: "Dallas" + country_code: US + region: { + region_id: 57 + region: "Texas" + region_code: "TX" + } + postcode: "75201" + telephone: "5559876543" + } + ) { + id + nickname + address_type + is_default + firstname + lastname + company + city + street + country_code + postcode + telephone + } +} +``` + +**Response:** + +```json +{ + "data": { + "updateCompanyAddress": { + "id": "MTI=", + "nickname": "Updated Nickname", + "address_type": "BILLING", + "is_default": false, + "firstname": "Jane", + "lastname": "Smith", + "company": "Updated Corp", + "city": "Dallas", + "street": ["456 Oak Ave"], + "country_code": "US", + "postcode": "75201", + "telephone": "5559876543" + } + } +} +``` +Clearing default via `is_default`: false on an address that is currently default requires set-default ACL (same as setDefaultCompanyAddress). \ No newline at end of file diff --git a/src/pages/graphql/schema/b2b/company/queries/company.md b/src/pages/graphql/schema/b2b/company/queries/company.md index 9b6869b1a..cb0c94ca6 100644 --- a/src/pages/graphql/schema/b2b/company/queries/company.md +++ b/src/pages/graphql/schema/b2b/company/queries/company.md @@ -384,3 +384,131 @@ query{ } } ``` + +### Return the company addresses and config + +The following query returns a list of company's addresses and a config object related to addresses. + +**Request:** + +```graphql +query{ + company{ + id + config { + address_book_enabled + address_book_custom_shipping_address_enabled + } + addresses(pageSize: 20, currentPage: 1) { + total_count + page_info { + page_size + current_page + total_pages + } + items { + id + nickname + company_id + address_type + is_default + firstname + lastname + company + street + city + country_code + region_id + region { + region_id + region + region_code + } + postcode + telephone + fax + vat_id + custom_attributes { + code + ... on AttributeValue { + value + } + } + } + } + } +} +``` + +**Response:** + +```json +{ + "data": { + "company": { + "config": { + "address_book_enabled": true, + "address_book_custom_shipping_address_enabled": true + }, + "addresses": { + "total_count": 2, + "page_info": { + "page_size": 20, + "current_page": 1, + "total_pages": 1 + }, + "items": [ + { + "id": "MTI=", + "nickname": "HQ Billing", + "company_id": "Mw==", + "address_type": "BILLING", + "is_default": true, + "firstname": "John", + "lastname": "Doe", + "company": "Acme Corp", + "street": ["123 Main St"], + "city": "Austin", + "country_code": "US", + "region_id": 57, + "region": { + "region_id": 57, + "region": "Texas", + "region_code": "TX" + }, + "postcode": "78701", + "telephone": "5551234567", + "fax": null, + "vat_id": "US123456789", + "custom_attributes": [] + }, + { + "id": "MTM=", + "nickname": "Warehouse", + "company_id": "Mw==", + "address_type": "SHIPPING", + "is_default": false, + "firstname": "Jane", + "lastname": "Smith", + "company": "Acme Corp", + "street": ["456 Oak Ave"], + "city": "Dallas", + "country_code": "US", + "region_id": 57, + "region": { + "region_id": 57, + "region": "Texas", + "region_code": "TX" + }, + "postcode": "75201", + "telephone": "5559876543", + "fax": null, + "vat_id": null, + "custom_attributes": [] + } + ] + } + } + } +} +``` \ No newline at end of file