createCustomerAddress mutation

Use the createCustomerAddress mutation to create the customer’s address.

To return or modify information about a customer, Magento recommends you use customer tokens in the header of your GraphQL calls. However, you also can use session authentication.

Syntax

mutation: {createCustomerAddress(input: CustomerAddressInput!) {CustomerAddress}}

Example usage

The following call creates an address for the specified customer.

Request

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
mutation {
  createCustomerAddress(input: {
    region: {
      region: "Arizona"
      region_id: 4
      region_code: "AZ"
    }
    country_id: US
    street: ["123 Main Street"]
    telephone: "7777777777"
    postcode: "77777"
    city: "Phoenix"
    firstname: "Bob"
    lastname: "Loblaw"
    default_shipping: true
    default_billing: false
  }) {
    id
    customer_id
    region {
      region
      region_id
      region_code
    }
    country_id
    street
    telephone
    postcode
    city
    default_shipping
    default_billing
  }
}

Response

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{
  "data": {
    "createCustomerAddress": {
      "id": 4,
      "customer_id": 5,
      "region": {
        "region": "Arizona",
        "region_id": 4,
        "region_code": "AZ"
      },
      "country_id": "US",
      "street": [
        "123 Main Street"
      ],
      "telephone": "7777777777",
      "postcode": "77777",
      "city": "Phoenix",
      "default_shipping": true,
      "default_billing": false
    }
  }
}

Input attributes

Attribute Data Type Description
id Int The ID assigned to the address object
CustomerAddressInput CustomerAddress An array containing the customer’s shipping and billing addresses

CustomerAddress input

The CustomerAddress input can contain the following attributes:

Attribute Data Type Description
city String The city or town
company String The customer’s company
country_id String The customer’s country
custom_attributes CustomerAddressAttribute Address custom attributes
customer_id Int The customer ID
default_billing Boolean Indicates whether the address is the default billing address
default_shipping Boolean Indicates whether the address is the default shipping address
extension_attributes CustomerAddressAttribute Address extension attributes
fax String The fax number
firstname String The first name of the person associated with the shipping/billing address
id Int The ID assigned to the address object
lastname String The family name of the person associated with the shipping/billing address
middlename String The middle name of the person associated with the shipping/billing address
postcode String The customer’s ZIP or postal code
prefix String An honorific, such as Dr., Mr., or Mrs.
region CustomerAddressRegion An object that defines the customer’s state or province
region_id Int A number that uniquely identifies the state, province, or other area
street [String] An array of strings that define the street number and name
suffix String A value such as Sr., Jr., or III
telephone String The telephone number
vat_id String The customer’s Tax/VAT number (for corporate customers)

CustomerAddressAttribute input

The CustomerAddressAttribute input can contain the following attributes:

Attribute Data Type Description
attribute_code String Attribute code
value String Attribute value

CustomerAddressRegion input

The customerAddressRegion input can contain the following attributes:

Attribute Data Type Description
region_code String The address region code
region String The state or province name
region_id Int Uniquely identifies the region

Output attributes

The createCustomerAddress mutation returns the following attributes:

CustomerAddress output

The values assigned to attributes such as firstname and lastname in this object may be different from those defined in the Customer object.

The CustomerAddress output returns the following attributes:

Attribute Data Type Description
city String The city or town
company String The customer’s company
country_id String The customer’s country
custom_attributes CustomerAddressAttribute Address custom attributes
customer_id Int The customer ID
default_billing Boolean Indicates whether the address is the default billing address
default_shipping Boolean Indicates whether the address is the default shipping address
extension_attributes CustomerAddressAttribute Address extension attributes
fax String The fax number
firstname String The first name of the person associated with the shipping/billing address
id Int The ID assigned to the address object
lastname String The family name of the person associated with the shipping/billing address
middlename String The middle name of the person associated with the shipping/billing address
postcode String The customer’s ZIP or postal code
prefix String An honorific, such as Dr., Mr., or Mrs.
region CustomerAddressRegion An object that defines the customer’s state or province
region_id Int A number that uniquely identifies the state, province, or other area
street [String] An array of strings that define the street number and name
suffix String A value such as Sr., Jr., or III
telephone String The telephone number
vat_id String The customer’s Tax/VAT number (for corporate customers)

CustomerAddressAttribute output

The CustomerAddressAttribute output returns the following attributes:

Attribute Data Type Description
attribute_code String Attribute code
value String Attribute value

CustomerAddressRegion output

The customerAddressRegion output returns the following attributes:

Attribute Data Type Description
region_code String The address region code
region String The state or province name
region_id Int Uniquely identifies the region