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

45 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_created_gmt date-time The date the order was created, as GMT. read-only
date_modified date-time The date the customer was last modified, in the site's timezone. read-only
date_modified_gmt date-time The date the customer was last modified, as GMT. read-only
email string The email address for the customer. mandatory
first_name string Customer first name.
last_name string Customer last name.
role string Customer role. read-only
username string Customer login name.
password string Customer password. write-only
billing object List of billing address data. See Customer - Billing properties
shipping object List of shipping address data. See Customer - Shipping properties
is_paying_customer bool Is the customer a paying customer? 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. read-only
meta_data array Meta data. See Customer - Meta data properties

Customer - Billing 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.

Customer - Shipping 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.

Customer - Meta data properties

Attribute Type Description
id integer Meta ID. read-only
key string Meta key.
value string Meta value.

Create a customer

This API helps you to create a new customer.

HTTP request

POST
/wp-json/wc/v2/customers
curl -X POST https://example.com/wp-json/wc/v2/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": 25,
  "date_created": "2017-03-21T16:09:28",
  "date_created_gmt": "2017-03-21T19:09:28",
  "date_modified": "2017-03-21T16:09:30",
  "date_modified_gmt": "2017-03-21T19:09:30",
  "email": "john.doe@example.com",
  "first_name": "John",
  "last_name": "Doe",
  "role": "customer",
  "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"
  },
  "is_paying_customer": false,
  "orders_count": 0,
  "total_spent": "0.00",
  "avatar_url": "https://secure.gravatar.com/avatar/8eb1b522f60d11fa897de1dc6351b7e8?s=96",
  "meta_data": [],
  "_links": {
    "self": [
      {
        "href": "https://example.com/wp-json/wc/v2/customers/25"
      }
    ],
    "collection": [
      {
        "href": "https://example.com/wp-json/wc/v2/customers"
      }
    ]
  }
}

Retrieve a customer

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

HTTP request

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

JSON response example:

{
  "id": 25,
  "date_created": "2017-03-21T16:09:28",
  "date_created_gmt": "2017-03-21T19:09:28",
  "date_modified": "2017-03-21T16:09:30",
  "date_modified_gmt": "2017-03-21T19:09:30",
  "email": "john.doe@example.com",
  "first_name": "John",
  "last_name": "Doe",
  "role": "customer",
  "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"
  },
  "is_paying_customer": false,
  "orders_count": 0,
  "total_spent": "0.00",
  "avatar_url": "https://secure.gravatar.com/avatar/8eb1b522f60d11fa897de1dc6351b7e8?s=96",
  "meta_data": [],
  "_links": {
    "self": [
      {
        "href": "https://example.com/wp-json/wc/v2/customers/25"
      }
    ],
    "collection": [
      {
        "href": "https://example.com/wp-json/wc/v2/customers"
      }
    ]
  }
}

List all customers

This API helps you to view all the customers.

HTTP request

GET
/wp-json/wc/v2/customers
curl https://example.com/wp-json/wc/v2/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": 26,
    "date_created": "2017-03-21T16:11:14",
    "date_created_gmt": "2017-03-21T19:11:14",
    "date_modified": "2017-03-21T16:11:16",
    "date_modified_gmt": "2017-03-21T19:11:16",
    "email": "joao.silva@example.com",
    "first_name": "João",
    "last_name": "Silva",
    "role": "customer",
    "username": "joao.silva",
    "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"
    },
    "is_paying_customer": false,
    "orders_count": 0,
    "total_spent": "0.00",
    "avatar_url": "https://secure.gravatar.com/avatar/be7b5febff88a2d947c3289e90cdf017?s=96",
    "meta_data": [],
    "_links": {
      "self": [
        {
          "href": "https://example.com/wp-json/wc/v2/customers/26"
        }
      ],
      "collection": [
        {
          "href": "https://example.com/wp-json/wc/v2/customers"
        }
      ]
    }
  },
  {
    "id": 25,
    "date_created": "2017-03-21T16:09:28",
    "date_created_gmt": "2017-03-21T19:09:28",
    "date_modified": "2017-03-21T16:09:30",
    "date_modified_gmt": "2017-03-21T19:09:30",
    "email": "john.doe@example.com",
    "first_name": "John",
    "last_name": "Doe",
    "role": "customer",
    "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"
    },
    "is_paying_customer": false,
    "orders_count": 0,
    "total_spent": "0.00",
    "avatar_url": "https://secure.gravatar.com/avatar/8eb1b522f60d11fa897de1dc6351b7e8?s=96",
    "meta_data": [],
    "_links": {
      "self": [
        {
          "href": "https://example.com/wp-json/wc/v2/customers/25"
        }
      ],
      "collection": [
        {
          "href": "https://example.com/wp-json/wc/v2/customers"
        }
      ]
    }
  }
]

Available parameters

Parameter Type Description
context string Scope under which the request is made; determines fields present in response. Options: view and edit. Default is view.
page integer Current page of the collection. Default is 1.
per_page integer Maximum number of items to be returned in result set. Default is 10.
search string Limit results to those matching a string.
exclude array Ensure result set excludes specific IDs.
include array 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. Options: asc and desc. Default is asc.
orderby string Sort collection by object attribute. Options: id, include, name and registered_date. Default is name.
email string Limit result set to resources with a specific email.
role string Limit result set to resources with a specific role. Options: all, administrator, editor, author, contributor, subscriber, customer and shop_manager. Default is customer.

Update a customer

This API lets you make changes to a customer.

HTTP request

PUT
/wp-json/wc/v2/customers/<id>
curl -X PUT https://example.com/wp-json/wc/v2/customers/25 \
	-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/25", 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/25', $data));
?>
data = {
    "first_name": "James",
    "billing": {
        "first_name": "James"
    },
    "shipping": {
        "first_name": "James"
    }
}

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

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

JSON response example:

{
  "id": 25,
  "date_created": "2017-03-21T16:09:28",
  "date_created_gmt": "2017-03-21T19:09:28",
  "date_modified": "2017-03-21T16:12:28",
  "date_modified_gmt": "2017-03-21T19:12:28",
  "email": "john.doe@example.com",
  "first_name": "James",
  "last_name": "Doe",
  "role": "customer",
  "username": "john.doe",
  "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"
  },
  "is_paying_customer": false,
  "orders_count": 0,
  "total_spent": "0.00",
  "avatar_url": "https://secure.gravatar.com/avatar/8eb1b522f60d11fa897de1dc6351b7e8?s=96",
  "meta_data": [],
  "_links": {
    "self": [
      {
        "href": "https://example.com/wp-json/wc/v2/customers/25"
      }
    ],
    "collection": [
      {
        "href": "https://example.com/wp-json/wc/v2/customers"
      }
    ]
  }
}

Delete a customer

This API helps you delete a customer.

HTTP request

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

JSON response example:

{
  "id": 25,
  "date_created": "2017-03-21T16:09:28",
  "date_created_gmt": "2017-03-21T19:09:28",
  "date_modified": "2017-03-21T16:12:28",
  "date_modified_gmt": "2017-03-21T19:12:28",
  "email": "john.doe@example.com",
  "first_name": "James",
  "last_name": "Doe",
  "role": "customer",
  "username": "john.doe",
  "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"
  },
  "is_paying_customer": false,
  "orders_count": 0,
  "total_spent": "0.00",
  "avatar_url": "https://secure.gravatar.com/avatar/8eb1b522f60d11fa897de1dc6351b7e8?s=96",
  "meta_data": [],
  "_links": {
    "self": [
      {
        "href": "https://example.com/wp-json/wc/v2/customers/25"
      }
    ],
    "collection": [
      {
        "href": "https://example.com/wp-json/wc/v2/customers"
      }
    ]
  }
}

Available parameters

Parameter Type Description
force string Required to be true, as resource does not support trashing.
reassign integer User ID to reassign posts to.

Batch update customers

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

HTTP request

POST
/wp-json/wc/v2/customers/batch
curl -X POST https://example.com/wp-json/wc/v2/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": 26,
      "billing": {
        "phone": "(11) 1111-1111"
      }
    }
  ],
  "delete": [
    25
  ]
}'
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: 26,
      billing: {
        phone: "(11) 1111-1111"
      }
    }
  ],
  delete: [
    11
  ]
};

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' => 26,
            'billing' => [
                'phone' => '(11) 1111-1111'
            ]
        ]
    ],
    'delete' => [
        25
    ]
];

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": 26,
            "billing": {
                "phone": "(11) 1111-1111"
            }
        }
    ],
    "delete": [
        25
    ]
}

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: 26,
      billing: {
        phone: "(11) 1111-1111"
      }
    }
  ],
  delete: [
    25
  ]
}

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

JSON response example:

{
  "create": [
    {
      "id": 27,
      "date_created": "2017-03-21T16:13:58",
      "date_created_gmt": "2017-03-21T19:13:58",
      "date_modified": "2017-03-21T16:13:59",
      "date_modified_gmt": "2017-03-21T19:13:59",
      "email": "john.doe2@example.com",
      "first_name": "John",
      "last_name": "Doe",
      "role": "customer",
      "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"
      },
      "is_paying_customer": false,
      "orders_count": 0,
      "total_spent": "0.00",
      "avatar_url": "https://secure.gravatar.com/avatar/6ad0b094bac53a85bb282ccdb3958279?s=96",
      "meta_data": [],
      "_links": {
        "self": [
          {
            "href": "https://example.com/wp-json/wc/v2/customers/27"
          }
        ],
        "collection": [
          {
            "href": "https://example.com/wp-json/wc/v2/customers"
          }
        ]
      }
    },
    {
      "id": 28,
      "date_created": "2017-03-21T16:14:00",
      "date_created_gmt": "2017-03-21T19:14:00",
      "date_modified": "2017-03-21T16:14:01",
      "date_modified_gmt": "2017-03-21T19:14:01",
      "email": "joao.silva2@example.com",
      "first_name": "João",
      "last_name": "Silva",
      "role": "customer",
      "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"
      },
      "is_paying_customer": false,
      "orders_count": 0,
      "total_spent": "0.00",
      "avatar_url": "https://secure.gravatar.com/avatar/ea9ad095f2970f27cbff07e7f5e99453?s=96",
      "meta_data": [],
      "_links": {
        "self": [
          {
            "href": "https://example.com/wp-json/wc/v2/customers/28"
          }
        ],
        "collection": [
          {
            "href": "https://example.com/wp-json/wc/v2/customers"
          }
        ]
      }
    }
  ],
  "update": [
    {
      "id": 26,
      "date_created": "2017-03-21T16:11:14",
      "date_created_gmt": "2017-03-21T19:11:14",
      "date_modified": "2017-03-21T16:14:03",
      "date_modified_gmt": "2017-03-21T19:14:03",
      "email": "joao.silva@example.com",
      "first_name": "João",
      "last_name": "Silva",
      "role": "customer",
      "username": "joao.silva",
      "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"
      },
      "is_paying_customer": false,
      "orders_count": 0,
      "total_spent": "0.00",
      "avatar_url": "https://secure.gravatar.com/avatar/be7b5febff88a2d947c3289e90cdf017?s=96",
      "meta_data": [],
      "_links": {
        "self": [
          {
            "href": "https://example.com/wp-json/wc/v2/customers/26"
          }
        ],
        "collection": [
          {
            "href": "https://example.com/wp-json/wc/v2/customers"
          }
        ]
      }
    }
  ],
  "delete": [
    {
      "id": 25,
      "date_created": "2017-03-21T16:09:28",
      "date_created_gmt": "2017-03-21T19:09:28",
      "date_modified": "2017-03-21T16:12:28",
      "date_modified_gmt": "2017-03-21T19:12:28",
      "email": "john.doe@example.com",
      "first_name": "James",
      "last_name": "Doe",
      "role": "customer",
      "username": "john.doe",
      "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"
      },
      "is_paying_customer": false,
      "orders_count": 0,
      "total_spent": "0.00",
      "avatar_url": "https://secure.gravatar.com/avatar/8eb1b522f60d11fa897de1dc6351b7e8?s=96",
      "meta_data": [],
      "_links": {
        "self": [
          {
            "href": "https://example.com/wp-json/wc/v2/customers/25"
          }
        ],
        "collection": [
          {
            "href": "https://example.com/wp-json/wc/v2/customers"
          }
        ]
      }
    }
  ]
}

Retrieve customer downloads

This API lets you retrieve customer downloads permissions.

HTTP request

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

JSON response example:

[
  {
    "download_id": "91447fd1849316bbc89dfb7e986a6006",
    "download_url": "https://example.com/?download_file=87&order=wc_order_58d17c18352&email=joao.silva%40example.com&key=91447fd1849316bbc89dfb7e986a6006",
    "product_id": 87,
    "product_name": "Woo Album #2",
    "download_name": "Woo Album #2 &ndash; Song 2",
    "order_id": 723,
    "order_key": "wc_order_58d17c18352",
    "downloads_remaining": "3",
    "access_expires": "never",
    "access_expires_gmt": "never",
    "file": {
      "name": "Song 2",
      "file": "http://example.com/wp-content/uploads/woocommerce_uploads/2013/06/Song.mp3"
    },
    "_links": {
      "collection": [
        {
          "href": "https://example.com/wp-json/wc/v2/customers/26/downloads"
        }
      ],
      "product": [
        {
          "href": "https://example.com/wp-json/wc/v2/products/87"
        }
      ],
      "order": [
        {
          "href": "https://example.com/wp-json/wc/v2/orders/723"
        }
      ]
    }
  }
]

Customer downloads properties

Attribute Type Description
download_id string Download ID (MD5). read-only
download_url string Download file URL. read-only
product_id integer Downloadable product ID. read-only
product_name string Product name. 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 Number of downloads remaining. read-only
access_expires string The date when download access expires, in the site's timezone. read-only
access_expires_gmt string The date when download access expires, as GMT. read-only
file object File details. read-only See Customers downloads - File properties

Customer downloads - File properties

Attribute Type Description
name string File name. read-only
file string File URL. read-only