Note: ‘WooCommerce Store API‘ and ‘WooCommerce REST API‘ will be used synonymously.
Activate WooCommerce REST API #
Path: WooCommerce > Settings > Advanced > REST API.
Our postcode checker plugin uses the WooCommerce REST API in order to provide address validation functionality via REST API.
- Generate a REST API key at WooCommerce > Settings > Advanced > REST API > Add key button.
- Set the user of the key to an admin account.
- After the key is created, it is important to remember the Consumer key and Consumer secret – since those 2 credentials are used in order to perform authentication (via Oauth).
Samples #
Compatible software | File |
Insomnia , Postman | rest-collection-v1.3.json |
Check address #
GET
http://wpovernight.local/wp-json/wc/wpo/wcpc/v1/wc-postcode-checker?house_number=30&postcode=2012ES
JSON response example:
{ "address": { "postcode": "2012ES", "housenumber": "30", "housenumber_suffix": "", "street": "Julianastraat", "city": "Haarlem", "data": { "street": "Julianastraat", "city": "Haarlem" } } }
Body form data:
Parameter | Type | Description |
---|---|---|
house_number | string | House number |
postcode | string | Postcode number |
Check address using Postman #
In order to set this up via Postman, follow this Postman tutorial.
Postman collection example:
{ "info": { "_postman_id": "f4da27fd-38ab-4b3b-b65f-344660878dc3", "name": "WooCommerce Postcode Checker API", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", "_exporter_id": "4754164" }, "item": [ { "name": "Check postcode", "request": { "auth": { "type": "oauth1", "oauth1": [ { "key": "consumerSecret", "value": "", "type": "string" }, { "key": "consumerKey", "value": "", "type": "string" }, { "key": "signatureMethod", "value": "HMAC-SHA1", "type": "string" }, { "key": "version", "value": "1.0", "type": "string" }, { "key": "addParamsToHeader", "value": false, "type": "boolean" }, { "key": "addEmptyParamsToSign", "value": false, "type": "boolean" } ] }, "method": "GET", "header": [], "url": { "raw": "http://wpovernight.local/wp-json/wc/wpo/wcpc/v1/wc-postcode-checker?house_number=30&postcode=2012ES", "protocol": "http", "host": [ "wpovernight", "local" ], "path": [ "wp-json", "wc", "wpo", "wcpc", "v1", "wc-postcode-checker" ], "query": [ { "key": "house_number", "value": "30" }, { "key": "postcode", "value": "2012ES" } ] } }, "response": [] } ] }