Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon how do I generate API keys for WooCommerce REST API
    WooCommerce REST API API keys generate API key revoke API key WordPress troubleshooting legacy API non-interactive setup


how do I generate API keys for WooCommerce REST API


To generate API keys for the WooCommerce REST API, follow these steps:

Step-by-Step Guide

1. Sign in to WordPress:
- Log in to your WordPress dashboard.

2. Go to WooCommerce Settings:
- Navigate to WooCommerce > Settings > Advanced.

3. Click on REST API:
- Click on the REST API tab.

4. Add Key:
- Click the Add Key button.

5. Add Description:
- Enter a memorable description for the key.

6. Select User:
- Choose the WordPress user you want to generate the key for from the dropdown.

7. Select Permissions:
- Choose the level of access for this API key:
- Read access
- Write access
- Read/Write access

8. Generate API Key:
- Click Generate API Key.

9. View Keys:
- You will see the Consumer Key and Consumer Secret. These keys can be used to authenticate with the WooCommerce REST API.

Additional Tips

- Ensure that your server is passing the auth headers to WordPress.
- If you are experiencing issues, try passing the consumer key and secret via URL rather than headers to confirm the issue.

Legacy REST API

- If you are using the Legacy REST API, ensure it is enabled in WooCommerce settings.
- Note that the Legacy REST API will be deprecated in future versions and should be replaced with the new REST API.

Troubleshooting

- If you encounter issues, check your server configuration to ensure it is not blocking the API requests.
- If you are using caching plugins, try disabling them to see if they are causing the issue.

Additional Resources

- For more detailed information on the WooCommerce REST API, refer to the official documentation: [1].
- For technical documentation, visit the WooCommerce REST API GitHub page: [3].
- For a step-by-step guide on testing the REST API, refer to the WooCommerce REST API documentation: [1].

Non-Interactive Setup

- For non-interactive setup, you can use the following command in your terminal:

bash
   cd /var/www/html/ && sudo -u www-data wp eval 'global $wpdb;echo $wpdb->insert($wpdb->prefix . "woocommerce_api_keys", array("user_id" => 1,"description" => "mykey","permissions" => "read_write","consumer_key"=> "ck_79c7d49f6897af872045a07eccdd9b256be11c9b","consumer_secret" => "cs_c39a85a79410a975d55b8e940d8134e31620c4dc","truncated_key" => substr("cs_c39a85a79410a975d55b8e940d8134e31620c4dc", -7)));'
   

This command will create a new API key with read-write permissions for the user with ID 1[5].

Citations:
[1] https://woocommerce.com/document/woocommerce-rest-api/
[2] https://www.godaddy.com/help/generate-a-woocommerce-api-key-41368
[3] https://woocommerce.github.io/woocommerce-rest-api-docs/
[4] https://developer.woocommerce.com/docs/getting-started-with-the-woocommerce-rest-api/
[5] https://wordpress.org/support/topic/how-to-noninteractively-create-woocommerce-rest-api-key/

Revoke an API key


To revoke an existing WooCommerce REST API key:

The WooCommerce REST API uses API keys to authenticate access to your store's data. If you need to revoke an existing API key, you can do so through the WooCommerce admin interface.[1][3]

1. Go to WooCommerce > Settings > Advanced > REST API in your WordPress admin dashboard.
2. Locate the API key you want to revoke and hover over it.
3. Click the "Revoke" link to revoke that API key.[1]

Once revoked, that API key will no longer be able to access your store's data through the REST API.[1]

If you need to create a new API key to replace the revoked one, you can do so by clicking the "Add Key" button in the REST API settings.[1][3] This will allow you to generate a new set of API keys with the desired permissions (read, write, or read/write access).[1][3]

It's important to note that revoking an API key will immediately disable any future access using that key. However, any existing integrations or applications using that key will stop working until you provide them with the new API key credentials.[1]

In summary, to revoke an existing WooCommerce REST API key, you can do so through the WooCommerce admin settings, and then create a new replacement key as needed.[1][3]

Citations:
[1] https://support.brandchamp.io/article/112-woocommerce-revoking-and-creating-a-new-api-key
[2] https://woocommerce.github.io/woocommerce-rest-api-docs/
[3] https://woocommerce.com/document/woocommerce-rest-api/
[4] https://10web.io/blog/how-to-use-woocommerce-api/
[5] https://wordpress.org/support/topic/how-can-i-reset-the-rest-api-i-revoked-before/