woocommerce-rest-api-docs/source/includes/wp-api-v1/_customers.md
2019-10-18 17:50:03 -03:00

46 KiB

Customers

The customer API allows you to create, view, update, and delete individual, or a batch, of customers.

Customer properties

Attribute Type Description
id integer Unique identifier for the resource. read-only
date_created date-time The date the customer was created, in the site's timezone. read-only
date_modified date-time The date the customer was last modified, in the site's timezone. read-only
email string The email address for the customer. mandatory
first_name string Customer first name.
last_name string Customer last name.
username string Customer login name. Can be generated automatically from the customer's email address if the option woocommerce_registration_generate_username is equal to yes cannot be changed maybe mandatory
password string Customer password. Can be generated automatically with wp_generate_password() if the "Automatically generate customer password" option is enabled, check the index meta for generate_password write-only maybe mandatory
last_order array Last order data. See Customer Last Order properties. read-only
orders_count integer Quantity of orders made by the customer. read-only
total_spent string Total amount spent. read-only
avatar_url string Avatar URL.
billing array List of billing address data. See Billing Address properties.
shipping array List of shipping address data. See Shipping Address properties.

Customer last order properties

Attribute Type Description
id integer Last order ID. read-only
date date-time UTC DateTime of the customer last order. read-only

Billing address properties

Attribute Type Description
first_name string First name.
last_name string Last name.
company string Company name.
address_1 string Address line 1.
address_2 string Address line 2.
city string City name.
state string ISO code or name of the state, province or district.
postcode string Postal code.
country string ISO code of the country.
email string Email address.
phone string Phone number.

Shipping address properties

Attribute Type Description
first_name string First name.
last_name string Last name.
company string Company name.
address_1 string Address line 1.
address_2 string Address line 2.
city string City name.
state string ISO code or name of the state, province or district.
postcode string Postal code.
country string ISO code of the country.

Create a customer

This API helps you to create a new customer.

HTTP request

POST
/wp-json/wc/v1/customers
curl -X POST https://example.com/wp-json/wc/v1/customers \
	-u consumer_key:consumer_secret \
	-H "Content-Type: application/json" \
	-d '{
  "email": "john.doe@example.com",
  "first_name": "John",
  "last_name": "Doe",
  "username": "john.doe",
  "billing": {
    "first_name": "John",
    "last_name": "Doe",
    "company": "",
    "address_1": "969 Market",
    "address_2": "",
    "city": "San Francisco",
    "state": "CA",
    "postcode": "94103",
    "country": "US",
    "email": "john.doe@example.com",
    "phone": "(555) 555-5555"
  },
  "shipping": {
    "first_name": "John",
    "last_name": "Doe",
    "company": "",
    "address_1": "969 Market",
    "address_2": "",
    "city": "San Francisco",
    "state": "CA",
    "postcode": "94103",
    "country": "US"
  }
}'
const data = {
  email: "john.doe@example.com",
  first_name: "John",
  last_name: "Doe",
  username: "john.doe",
  billing: {
    first_name: "John",
    last_name: "Doe",
    company: "",
    address_1: "969 Market",
    address_2: "",
    city: "San Francisco",
    state: "CA",
    postcode: "94103",
    country: "US",
    email: "john.doe@example.com",
    phone: "(555) 555-5555"
  },
  shipping: {
    first_name: "John",
    last_name: "Doe",
    company: "",
    address_1: "969 Market",
    address_2: "",
    city: "San Francisco",
    state: "CA",
    postcode: "94103",
    country: "US"
  }
};

WooCommerce.post("customers", data)
  .then((response) => {
    console.log(response.data);
  })
  .catch((error) => {
    console.log(error.response.data);
  });
<?php
$data = [
    'email' => 'john.doe@example.com',
    'first_name' => 'John',
    'last_name' => 'Doe',
    'username' => 'john.doe',
    'billing' => [
        'first_name' => 'John',
        'last_name' => 'Doe',
        'company' => '',
        'address_1' => '969 Market',
        'address_2' => '',
        'city' => 'San Francisco',
        'state' => 'CA',
        'postcode' => '94103',
        'country' => 'US',
        'email' => 'john.doe@example.com',
        'phone' => '(555) 555-5555'
    ],
    'shipping' => [
        'first_name' => 'John',
        'last_name' => 'Doe',
        'company' => '',
        'address_1' => '969 Market',
        'address_2' => '',
        'city' => 'San Francisco',
        'state' => 'CA',
        'postcode' => '94103',
        'country' => 'US'
    ]
];

print_r($woocommerce->post('customers', $data));
?>
data = {
    "email": "john.doe@example.com",
    "first_name": "John",
    "last_name": "Doe",
    "username": "john.doe",
    "billing": {
        "first_name": "John",
        "last_name": "Doe",
        "company": "",
        "address_1": "969 Market",
        "address_2": "",
        "city": "San Francisco",
        "state": "CA",
        "postcode": "94103",
        "country": "US",
        "email": "john.doe@example.com",
        "phone": "(555) 555-5555"
    },
    "shipping": {
        "first_name": "John",
        "last_name": "Doe",
        "company": "",
        "address_1": "969 Market",
        "address_2": "",
        "city": "San Francisco",
        "state": "CA",
        "postcode": "94103",
        "country": "US"
    }
}

print(wcapi.post("customers", data).json())
data = {
  email: "john.doe@example.com",
  first_name: "John",
  last_name: "Doe",
  username: "john.doe",
  billing: {
    first_name: "John",
    last_name: "Doe",
    company: "",
    address_1: "969 Market",
    address_2: "",
    city: "San Francisco",
    state: "CA",
    postcode: "94103",
    country: "US",
    email: "john.doe@example.com",
    phone: "(555) 555-5555"
  },
  shipping: {
    first_name: "John",
    last_name: "Doe",
    company: "",
    address_1: "969 Market",
    address_2: "",
    city: "San Francisco",
    state: "CA",
    postcode: "94103",
    country: "US"
  }
}

woocommerce.post("customers", data).parsed_response

JSON response example:

{
  "id": 2,
  "date_created": "2016-05-03T17:58:35",
  "date_modified": "2016-05-11T21:34:43",
  "email": "john.doe@example.com",
  "first_name": "John",
  "last_name": "Doe",
  "username": "john.doe",
  "last_order": {
    "id": 118,
    "date": "2016-05-03T18:10:43"
  },
  "orders_count": 3,
  "total_spent": "28.00",
  "avatar_url": "https://secure.gravatar.com/avatar/?s=96",
  "billing": {
    "first_name": "John",
    "last_name": "Doe",
    "company": "",
    "address_1": "969 Market",
    "address_2": "",
    "city": "San Francisco",
    "state": "CA",
    "postcode": "94103",
    "country": "US",
    "email": "john.doe@example.com",
    "phone": "(555) 555-5555"
  },
  "shipping": {
    "first_name": "John",
    "last_name": "Doe",
    "company": "",
    "address_1": "969 Market",
    "address_2": "",
    "city": "San Francisco",
    "state": "CA",
    "postcode": "94103",
    "country": "US"
  },
  "_links": {
    "self": [
      {
        "href": "https://example.com/wp-json/wc/v1/customers/2"
      }
    ],
    "collection": [
      {
        "href": "https://example.com/wp-json/wc/v1/customers"
      }
    ]
  }
}

Retrieve a customer

This API lets you retrieve and view a specific customer by ID.

HTTP request

GET
/wp-json/wc/v1/customers/<id>
curl https://example.com/wp-json/wc/v1/customers/2 \
	-u consumer_key:consumer_secret
WooCommerce.get("customers/2")
  .then((response) => {
    console.log(response.data);
  })
  .catch((error) => {
    console.log(error.response.data);
  });
<?php print_r($woocommerce->get('customers/2')); ?>
print(wcapi.get("customers/2").json())
woocommerce.get("customers/2").parsed_response

JSON response example:

{
  "id": 2,
  "date_created": "2016-05-03T17:58:35",
  "date_modified": "2016-05-11T21:34:43",
  "email": "john.doe@example.com",
  "first_name": "John",
  "last_name": "Doe",
  "username": "john.doe",
  "last_order": {
    "id": 118,
    "date": "2016-05-03T18:10:43"
  },
  "orders_count": 3,
  "total_spent": "28.00",
  "avatar_url": "https://secure.gravatar.com/avatar/?s=96",
  "billing": {
    "first_name": "John",
    "last_name": "Doe",
    "company": "",
    "address_1": "969 Market",
    "address_2": "",
    "city": "San Francisco",
    "state": "CA",
    "postcode": "94103",
    "country": "US",
    "email": "john.doe@example.com",
    "phone": "(555) 555-5555"
  },
  "shipping": {
    "first_name": "John",
    "last_name": "Doe",
    "company": "",
    "address_1": "969 Market",
    "address_2": "",
    "city": "San Francisco",
    "state": "CA",
    "postcode": "94103",
    "country": "US"
  },
  "_links": {
    "self": [
      {
        "href": "https://example.com/wp-json/wc/v1/customers/2"
      }
    ],
    "collection": [
      {
        "href": "https://example.com/wp-json/wc/v1/customers"
      }
    ]
  }
}

List all customers

This API helps you to view all the customers.

HTTP request

GET
/wp-json/wc/v1/customers
curl https://example.com/wp-json/wc/v1/customers \
	-u consumer_key:consumer_secret
WooCommerce.get("customers")
  .then((response) => {
    console.log(response.data);
  })
  .catch((error) => {
    console.log(error.response.data);
  });
<?php print_r($woocommerce->get('customers')); ?>
print(wcapi.get("customers").json())
woocommerce.get("customers").parsed_response

JSON response example:

[
  {
    "id": 5,
    "date_created": "2016-05-11T21:39:01",
    "date_modified": "2016-05-11T21:40:02",
    "email": "joao.silva@example.com",
    "first_name": "João",
    "last_name": "Silva",
    "username": "joao.silva",
    "last_order": {
      "id": null,
      "date": null
    },
    "orders_count": 0,
    "total_spent": "0.00",
    "avatar_url": "https://secure.gravatar.com/avatar/?s=96",
    "billing": {
      "first_name": "João",
      "last_name": "Silva",
      "company": "",
      "address_1": "Av. Brasil, 432",
      "address_2": "",
      "city": "Rio de Janeiro",
      "state": "RJ",
      "postcode": "12345-000",
      "country": "BR",
      "email": "joao.silva@example.com",
      "phone": "(55) 5555-5555"
    },
    "shipping": {
      "first_name": "João",
      "last_name": "Silva",
      "company": "",
      "address_1": "Av. Brasil, 432",
      "address_2": "",
      "city": "Rio de Janeiro",
      "state": "RJ",
      "postcode": "12345-000",
      "country": "BR"
    },
    "_links": {
      "self": [
        {
          "href": "https://example.com/wp-json/wc/v1/customers/5"
        }
      ],
      "collection": [
        {
          "href": "https://example.com/wp-json/wc/v1/customers"
        }
      ]
    }
  },
  {
    "id": 2,
    "date_created": "2016-05-03T17:58:35",
    "date_modified": "2016-05-11T21:34:43",
    "email": "john.doe@example.com",
    "first_name": "John",
    "last_name": "Doe",
    "username": "john.doe",
    "last_order": {
      "id": 118,
      "date": "2016-05-03T18:10:43"
    },
    "orders_count": 3,
    "total_spent": "28.00",
    "avatar_url": "https://secure.gravatar.com/avatar/?s=96",
    "billing": {
      "first_name": "John",
      "last_name": "Doe",
      "company": "",
      "address_1": "969 Market",
      "address_2": "",
      "city": "San Francisco",
      "state": "CA",
      "postcode": "94103",
      "country": "US",
      "email": "john.doe@example.com",
      "phone": "(555) 555-5555"
    },
    "shipping": {
      "first_name": "John",
      "last_name": "Doe",
      "company": "",
      "address_1": "969 Market",
      "address_2": "",
      "city": "San Francisco",
      "state": "CA",
      "postcode": "94103",
      "country": "US"
    },
    "_links": {
      "self": [
        {
          "href": "https://example.com/wp-json/wc/v1/customers/2"
        }
      ],
      "collection": [
        {
          "href": "https://example.com/wp-json/wc/v1/customers"
        }
      ]
    }
  }
]

Available parameters

Parameter Type Description
context string Scope under which the request is made; determines fields present in response. Options: view and edit.
page integer Current page of the collection.
per_page integer Maximum number of items to be returned in result set.
search string Limit results to those matching a string.
exclude string Ensure result set excludes specific ids.
include string Limit result set to specific ids.
offset integer Offset the result set by a specific number of items.
order string Order sort attribute ascending or descending. Default is asc, Options: asc and desc.
orderby string Sort collection by object attribute. Default is name. Options: id, include, name and registered_date.
email string Limit result set to resources with a specific email.
role string Limit result set to resources with a specific role. Default: customer. Options (some plugins can add more user roles): all, administrator, editor, author, contributor, subscriber, customer and shop_manager

Update a customer

This API lets you make changes to a customer.

HTTP request

PUT
/wp-json/wc/v1/customers/<id>
curl -X PUT https://example.com/wp-json/wc/v1/customers/2 \
	-u consumer_key:consumer_secret \
	-H "Content-Type: application/json" \
	-d '{
  "first_name": "James",
  "billing": {
    "first_name": "James"
  },
  "shipping": {
    "first_name": "James"
  }
}'
const data = {
  first_name: "James",
  billing: {
    first_name: "James"
  },
  shipping: {
    first_name: "James"
  }
};

WooCommerce.put("customers/2", data)
  .then((response) => {
    console.log(response.data);
  })
  .catch((error) => {
    console.log(error.response.data);
  });
<?php 
$data = [
    'first_name' => 'James',
    'billing' => [
        'first_name' => 'James'
    ],
    'shipping' => [
        'first_name' => 'James'
    ]
];

print_r($woocommerce->put('customers/2', $data));
?>
data = {
    "first_name": "James",
    "billing": {
        "first_name": "James"
    },
    "shipping": {
        "first_name": "James"
    }
}

print(wcapi.put("customers/2", data).json())
data = {
  first_name: "James",
  billing: {
    first_name: "James"
  },
  shipping: {
    first_name: "James"
  }
}

woocommerce.put("customers/2", data).parsed_response

JSON response example:

{
  "id": 2,
  "date_created": "2016-05-03T17:58:35",
  "date_modified": "2016-05-11T21:43:45",
  "email": "john.doe@example.com",
  "first_name": "James",
  "last_name": "Doe",
  "username": "john.doe",
  "last_order": {
    "id": 118,
    "date": "2016-05-03T18:10:43"
  },
  "orders_count": 3,
  "total_spent": "28.00",
  "avatar_url": "https://secure.gravatar.com/avatar/?s=96",
  "billing": {
    "first_name": "James",
    "last_name": "Doe",
    "company": "",
    "address_1": "969 Market",
    "address_2": "",
    "city": "San Francisco",
    "state": "CA",
    "postcode": "94103",
    "country": "US",
    "email": "john.doe@example.com",
    "phone": "(555) 555-5555"
  },
  "shipping": {
    "first_name": "James",
    "last_name": "Doe",
    "company": "",
    "address_1": "969 Market",
    "address_2": "",
    "city": "San Francisco",
    "state": "CA",
    "postcode": "94103",
    "country": "US"
  },
  "_links": {
    "self": [
      {
        "href": "https://example.com/wp-json/wc/v1/customers/2"
      }
    ],
    "collection": [
      {
        "href": "https://example.com/wp-json/wc/v1/customers"
      }
    ]
  }
}

Delete a customer

This API helps you delete a customer.

HTTP request

DELETE
/wp-json/wc/v1/customers/<id>
curl -X DELETE https://example.com/wp-json/wc/v1/customers/2?force=true \
	-u consumer_key:consumer_secret
WooCommerce.delete("customers/2", {
  force: true
})
  .then((response) => {
    console.log(response.data);
  })
  .catch((error) => {
    console.log(error.response.data);
  });
<?php print_r($woocommerce->delete('customers/2', ['force' => true])); ?>
print(wcapi.delete("customers/2", params={"force": True}).json())
woocommerce.delete("customers/2", force: true).parsed_response

JSON response example:

{
  "id": 2,
  "date_created": "2016-05-03T17:58:35",
  "date_modified": "2016-05-11T21:43:45",
  "email": "john.doe@example.com",
  "first_name": "James",
  "last_name": "Doe",
  "username": "john.doe",
  "last_order": {
    "id": 118,
    "date": "2016-05-03T18:10:43"
  },
  "orders_count": 3,
  "total_spent": "28.00",
  "avatar_url": "https://secure.gravatar.com/avatar/?s=96",
  "billing": {
    "first_name": "James",
    "last_name": "Doe",
    "company": "",
    "address_1": "969 Market",
    "address_2": "",
    "city": "San Francisco",
    "state": "CA",
    "postcode": "94103",
    "country": "US",
    "email": "john.doe@example.com",
    "phone": "(555) 555-5555"
  },
  "shipping": {
    "first_name": "James",
    "last_name": "Doe",
    "company": "",
    "address_1": "969 Market",
    "address_2": "",
    "city": "San Francisco",
    "state": "CA",
    "postcode": "94103",
    "country": "US"
  },
  "_links": {
    "self": [
      {
        "href": "https://example.com/wp-json/wc/v1/customers/2"
      }
    ],
    "collection": [
      {
        "href": "https://example.com/wp-json/wc/v1/customers"
      }
    ]
  }
}

Available parameters

Parameter Type Description
force string Required to be true, as resource does not support trashing.

Batch update customers

This API helps you to batch create, update and delete multiple customers.

HTTP request

POST
/wp-json/wc/v1/customers/batch
curl -X POST https://example.com/wp-json/wc/v1/customers/batch \
	-u consumer_key:consumer_secret \
	-H "Content-Type: application/json" \
	-d '{
  "create": [
    {
      "email": "john.doe2@example.com",
      "first_name": "John",
      "last_name": "Doe",
      "username": "john.doe2",
      "billing": {
        "first_name": "John",
        "last_name": "Doe",
        "company": "",
        "address_1": "969 Market",
        "address_2": "",
        "city": "San Francisco",
        "state": "CA",
        "postcode": "94103",
        "country": "US",
        "email": "john.doe@example.com",
        "phone": "(555) 555-5555"
      },
      "shipping": {
        "first_name": "John",
        "last_name": "Doe",
        "company": "",
        "address_1": "969 Market",
        "address_2": "",
        "city": "San Francisco",
        "state": "CA",
        "postcode": "94103",
        "country": "US"
      }
    },
    {
      "email": "joao.silva2@example.com",
      "first_name": "João",
      "last_name": "Silva",
      "username": "joao.silva2",
      "billing": {
        "first_name": "João",
        "last_name": "Silva",
        "company": "",
        "address_1": "Av. Brasil, 432",
        "address_2": "",
        "city": "Rio de Janeiro",
        "state": "RJ",
        "postcode": "12345-000",
        "country": "BR",
        "email": "joao.silva@example.com",
        "phone": "(55) 5555-5555"
      },
      "shipping": {
        "first_name": "João",
        "last_name": "Silva",
        "company": "",
        "address_1": "Av. Brasil, 432",
        "address_2": "",
        "city": "Rio de Janeiro",
        "state": "RJ",
        "postcode": "12345-000",
        "country": "BR"
      }
    }
  ],
  "update": [
    {
      "id": 5,
      "billing": {
        "phone": "(11) 1111-1111"
      }
    }
  ],
  "delete": [
    2
  ]
}'
const data = {
  create: [
    {
      email: "john.doe2@example.com",
      first_name: "John",
      last_name: "Doe",
      username: "john.doe2",
      billing: {
        first_name: "John",
        last_name: "Doe",
        company: "",
        address_1: "969 Market",
        address_2: "",
        city: "San Francisco",
        state: "CA",
        postcode: "94103",
        country: "US",
        email: "john.doe@example.com",
        phone: "(555) 555-5555"
      },
      shipping: {
        first_name: "John",
        last_name: "Doe",
        company: "",
        address_1: "969 Market",
        address_2: "",
        city: "San Francisco",
        state: "CA",
        postcode: "94103",
        country: "US"
      }
    },
    {
      email: "joao.silva2@example.com",
      first_name: "João",
      last_name: "Silva",
      username: "joao.silva2",
      billing: {
        first_name: "João",
        last_name: "Silva",
        company: "",
        address_1: "Av. Brasil, 432",
        address_2: "",
        city: "Rio de Janeiro",
        state: "RJ",
        postcode: "12345-000",
        country: "BR",
        email: "joao.silva@example.com",
        phone: "(55) 5555-5555"
      },
      shipping: {
        first_name: "João",
        last_name: "Silva",
        company: "",
        address_1: "Av. Brasil, 432",
        address_2: "",
        city: "Rio de Janeiro",
        state: "RJ",
        postcode: "12345-000",
        country: "BR"
      }
    }
  ],
  update: [
    {
      id: 5,
      billing: {
        phone: "(11) 1111-1111"
      }
    }
  ],
  delete: [
    2
  ]
};

WooCommerce.post("customers/batch", data)
  .then((response) => {
    console.log(response.data);
  })
  .catch((error) => {
    console.log(error.response.data);
  });
<?php 
$data = [
    'create' => [
        [
            'email' => 'john.doe2@example.com',
            'first_name' => 'John',
            'last_name' => 'Doe',
            'username' => 'john.doe2',
            'billing' => [
                'first_name' => 'John',
                'last_name' => 'Doe',
                'company' => '',
                'address_1' => '969 Market',
                'address_2' => '',
                'city' => 'San Francisco',
                'state' => 'CA',
                'postcode' => '94103',
                'country' => 'US',
                'email' => 'john.doe@example.com',
                'phone' => '(555) 555-5555'
            ],
            'shipping' => [
                'first_name' => 'John',
                'last_name' => 'Doe',
                'company' => '',
                'address_1' => '969 Market',
                'address_2' => '',
                'city' => 'San Francisco',
                'state' => 'CA',
                'postcode' => '94103',
                'country' => 'US'
            ]
        ],
        [
            'email' => 'joao.silva2@example.com',
            'first_name' => 'João',
            'last_name' => 'Silva',
            'username' => 'joao.silva2',
            'billing' => [
                'first_name' => 'João',
                'last_name' => 'Silva',
                'company' => '',
                'address_1' => 'Av. Brasil, 432',
                'address_2' => '',
                'city' => 'Rio de Janeiro',
                'state' => 'RJ',
                'postcode' => '12345-000',
                'country' => 'BR',
                'email' => 'joao.silva@example.com',
                'phone' => '(55) 5555-5555'
            ],
            'shipping' => [
                'first_name' => 'João',
                'last_name' => 'Silva',
                'company' => '',
                'address_1' => 'Av. Brasil, 432',
                'address_2' => '',
                'city' => 'Rio de Janeiro',
                'state' => 'RJ',
                'postcode' => '12345-000',
                'country' => 'BR'
            ]
        ]
    ],
    'update' => [
        [
            'id' => 5,
            'billing' => [
                'phone' => '(11) 1111-1111'
            ]
        ]
    ],
    'delete' => [
        2
    ]
];

print_r($woocommerce->post('customers/batch', $data));
?>
data = {
    "create": [
        {
            "email": "john.doe2@example.com",
            "first_name": "John",
            "last_name": "Doe",
            "username": "john.doe2",
            "billing": {
                "first_name": "John",
                "last_name": "Doe",
                "company": "",
                "address_1": "969 Market",
                "address_2": "",
                "city": "San Francisco",
                "state": "CA",
                "postcode": "94103",
                "country": "US",
                "email": "john.doe@example.com",
                "phone": "(555) 555-5555"
            },
            "shipping": {
                "first_name": "John",
                "last_name": "Doe",
                "company": "",
                "address_1": "969 Market",
                "address_2": "",
                "city": "San Francisco",
                "state": "CA",
                "postcode": "94103",
                "country": "US"
            }
        },
        {
            "email": "joao.silva2@example.com",
            "first_name": "João",
            "last_name": "Silva",
            "username": "joao.silva2",
            "billing": {
                "first_name": "João",
                "last_name": "Silva",
                "company": "",
                "address_1": "Av. Brasil, 432",
                "address_2": "",
                "city": "Rio de Janeiro",
                "state": "RJ",
                "postcode": "12345-000",
                "country": "BR",
                "email": "joao.silva@example.com",
                "phone": "(55) 5555-5555"
            },
            "shipping": {
                "first_name": "João",
                "last_name": "Silva",
                "company": "",
                "address_1": "Av. Brasil, 432",
                "address_2": "",
                "city": "Rio de Janeiro",
                "state": "RJ",
                "postcode": "12345-000",
                "country": "BR"
            }
        }
    ],
    "update": [
        {
            "id": 5,
            "billing": {
                "phone": "(11) 1111-1111"
            }
        }
    ],
    "delete": [
        2
    ]
}

print(wcapi.post("customers/batch", data).json())
data = {
  create: [
    {
      email: "john.doe2@example.com",
      first_name: "John",
      last_name: "Doe",
      username: "john.doe2",
      billing: {
        first_name: "John",
        last_name: "Doe",
        company: "",
        address_1: "969 Market",
        address_2: "",
        city: "San Francisco",
        state: "CA",
        postcode: "94103",
        country: "US",
        email: "john.doe@example.com",
        phone: "(555) 555-5555"
      },
      shipping: {
        first_name: "John",
        last_name: "Doe",
        company: "",
        address_1: "969 Market",
        address_2: "",
        city: "San Francisco",
        state: "CA",
        postcode: "94103",
        country: "US"
      }
    },
    {
      email: "joao.silva2@example.com",
      first_name: "João",
      last_name: "Silva",
      username: "joao.silva2",
      billing: {
        first_name: "João",
        last_name: "Silva",
        company: "",
        address_1: "Av. Brasil, 432",
        address_2: "",
        city: "Rio de Janeiro",
        state: "RJ",
        postcode: "12345-000",
        country: "BR",
        email: "joao.silva@example.com",
        phone: "(55) 5555-5555"
      },
      shipping: {
        first_name: "João",
        last_name: "Silva",
        company: "",
        address_1: "Av. Brasil, 432",
        address_2: "",
        city: "Rio de Janeiro",
        state: "RJ",
        postcode: "12345-000",
        country: "BR"
      }
    }
  ],
  update: [
    {
      id: 5,
      billing: {
        phone: "(11) 1111-1111"
      }
    }
  ],
  delete: [
    2
  ]
}

woocommerce.post("customers/batch", data).parsed_response

JSON response example:

{
  "create": [
    {
      "id": 6,
      "date_created": "2016-05-11T22:06:32",
      "date_modified": "2016-05-11T22:07:31",
      "email": "john.doe2@example.com",
      "first_name": "John",
      "last_name": "Doe",
      "username": "john.doe2",
      "last_order": {
        "id": null,
        "date": null
      },
      "orders_count": 0,
      "total_spent": "0.00",
      "avatar_url": "https://secure.gravatar.com/avatar/?s=96",
      "billing": {
        "first_name": "John",
        "last_name": "Doe",
        "company": "",
        "address_1": "969 Market",
        "address_2": "",
        "city": "San Francisco",
        "state": "CA",
        "postcode": "94103",
        "country": "US",
        "email": "john.doe@example.com",
        "phone": "(555) 555-5555"
      },
      "shipping": {
        "first_name": "John",
        "last_name": "Doe",
        "company": "",
        "address_1": "969 Market",
        "address_2": "",
        "city": "San Francisco",
        "state": "CA",
        "postcode": "94103",
        "country": "US"
      },
      "_links": {
        "self": [
          {
            "href": "https://example.com/wp-json/wc/v1/customers/6"
          }
        ],
        "collection": [
          {
            "href": "https://example.com/wp-json/wc/v1/customers"
          }
        ]
      }
    },
    {
      "id": 7,
      "date_created": "2016-05-11T22:07:33",
      "date_modified": "2016-05-11T22:07:37",
      "email": "joao.silva2@example.com",
      "first_name": "João",
      "last_name": "Silva",
      "username": "joao.silva2",
      "last_order": {
        "id": null,
        "date": null
      },
      "orders_count": 0,
      "total_spent": "0.00",
      "avatar_url": "https://secure.gravatar.com/avatar/?s=96",
      "billing": {
        "first_name": "João",
        "last_name": "Silva",
        "company": "",
        "address_1": "Av. Brasil, 432",
        "address_2": "",
        "city": "Rio de Janeiro",
        "state": "RJ",
        "postcode": "12345-000",
        "country": "BR",
        "email": "joao.silva@example.com",
        "phone": "(55) 5555-5555"
      },
      "shipping": {
        "first_name": "João",
        "last_name": "Silva",
        "company": "",
        "address_1": "Av. Brasil, 432",
        "address_2": "",
        "city": "Rio de Janeiro",
        "state": "RJ",
        "postcode": "12345-000",
        "country": "BR"
      },
      "_links": {
        "self": [
          {
            "href": "https://example.com/wp-json/wc/v1/customers/7"
          }
        ],
        "collection": [
          {
            "href": "https://example.com/wp-json/wc/v1/customers"
          }
        ]
      }
    }
  ],
  "update": [
    {
      "id": 5,
      "date_created": "2016-05-11T21:39:01",
      "date_modified": "2016-05-11T22:04:36",
      "email": "joao.silva@example.com",
      "first_name": "João",
      "last_name": "Silva",
      "username": "joao.silva",
      "last_order": {
        "id": null,
        "date": null
      },
      "orders_count": 0,
      "total_spent": "0.00",
      "avatar_url": "https://secure.gravatar.com/avatar/?s=96",
      "billing": {
        "first_name": "João",
        "last_name": "Silva",
        "company": "",
        "address_1": "Av. Brasil, 432",
        "address_2": "",
        "city": "Rio de Janeiro",
        "state": "RJ",
        "postcode": "12345-000",
        "country": "BR",
        "email": "joao.silva@example.com",
        "phone": "(11) 1111-1111"
      },
      "shipping": {
        "first_name": "João",
        "last_name": "Silva",
        "company": "",
        "address_1": "Av. Brasil, 432",
        "address_2": "",
        "city": "Rio de Janeiro",
        "state": "RJ",
        "postcode": "12345-000",
        "country": "BR"
      },
      "_links": {
        "self": [
          {
            "href": "https://example.com/wp-json/wc/v1/customers/5"
          }
        ],
        "collection": [
          {
            "href": "https://example.com/wp-json/wc/v1/customers"
          }
        ]
      }
    }
  ],
  "delete": [
    {
      "id": 2,
      "date_created": "2016-05-03T17:58:35",
      "date_modified": "2016-05-11T21:43:45",
      "email": "john.doe@example.com",
      "first_name": "James",
      "last_name": "Doe",
      "username": "john.doe",
      "last_order": {
        "id": 118,
        "date": "2016-05-03T18:10:43"
      },
      "orders_count": 3,
      "total_spent": "28.00",
      "avatar_url": "https://secure.gravatar.com/avatar/?s=96",
      "billing": {
        "first_name": "James",
        "last_name": "Doe",
        "company": "",
        "address_1": "969 Market",
        "address_2": "",
        "city": "San Francisco",
        "state": "CA",
        "postcode": "94103",
        "country": "US",
        "email": "john.doe@example.com",
        "phone": "(555) 555-5555"
      },
      "shipping": {
        "first_name": "James",
        "last_name": "Doe",
        "company": "",
        "address_1": "969 Market",
        "address_2": "",
        "city": "San Francisco",
        "state": "CA",
        "postcode": "94103",
        "country": "US"
      },
      "_links": {
        "self": [
          {
            "href": "https://example.com/wp-json/wc/v1/customers/2"
          }
        ],
        "collection": [
          {
            "href": "https://example.com/wp-json/wc/v1/customers"
          }
        ]
      }
    }
  ]
}

Retrieve customer downloads

This API lets you retrieve customer downloads permissions.

HTTP request

GET
/wp-json/wc/v1/customers/<id>/downloads
curl https://example.com/wp-json/wc/v1/customers/2/downloads \
	-u consumer_key:consumer_secret
WooCommerce.get("customers/2/downloads")
  .then((response) => {
    console.log(response.data);
  })
  .catch((error) => {
    console.log(error.response.data);
  });
<?php print_r($woocommerce->get('customers/2/downloads')); ?>
print(wcapi.get("customers/2/downloads").json())
woocommerce.get("customers/2/downloads").parsed_response

JSON response example:

[
  {
    "download_url": "https://example.com/?download_file=96&order=wc_order_571a7260c0da5&email=john.dow@xanmple.com&key=1789931e0c14ad9909a50c826f10c169",
    "download_id": "1789931e0c14ad9909a50c826f10c169",
    "product_id": 96,
    "download_name": "Woo Album #4 &ndash; Testing",
    "order_id": 105,
    "order_key": "wc_order_571a7260c0da5",
    "downloads_remaining": "unlimited",
    "access_expires": "never",
    "file": {
      "name": "Testing",
      "file": "http://example.com/wp-content/uploads/2013/06/cd_5_angle.jpg"
    },
    "_links": {
      "collection": [
        {
          "href": "https://example.com/wp-json/wc/v1/customers/1/downloads"
        }
      ],
      "product": [
        {
          "href": "https://example.com/wp-json/wc/v1/products/96"
        }
      ],
      "order": [
        {
          "href": "https://example.com/wp-json/wc/v1/orders/105"
        }
      ]
    }
  }
]

Customer downloads properties

Attribute Type Description
download_url string Download file URL. read-only
download_id string Download ID (MD5). read-only
product_id integer Downloadable product ID. read-only
download_name string Downloadable file name. read-only
order_id integer Order ID. read-only
order_key string Order key. read-only
downloads_remaining string Amount of downloads remaining. read-only
access_expires string The date when the download access expires, in the site's timezone. read-only
file array File details with name (file name) and file (file URL) attributes. read-only