[WooCommerce] API Healthiness
Table Of Contents
- How QPilot Makes API Requests
- Connecting QPilot to the WooCommerce Rest API
- Common Error Responses
- Advanced Troubleshooting
The Autoship Cloud plugin integrates your WooCommerce site with QPilot using the WooCommerce REST API (version 2).
How QPilot Makes API Requests
Requirements
- Site Title
- Your site must have a title as set in WP-Admin > Settings > General >> Site Title in order to successfully connect to QPilot.
- Ability to make GET / POST / PUT requests over the WooCommerce REST API on your site.
- This setting is found in the WP Admin under WooCommerce > Settings > Advanced (tab) >> REST API.
- To learn more about this, see here: Testing the WooCommerce REST API without Autoship Cloud
GET Request
Used to securely pass (GET) Data from WooCommerce to QPilot to keep data synchronized, including:
- Order Data
- Product Data
- Customer Data
- Tokenized Payment Data
POST Request
Used to securely create data in WooCommerce Orders when processing a Scheduled Order over WooCommerce REST API
PUT Request
Used to securely update WooCommerce Order data when processing a Scheduled Order over the REST API.
Also used to securely update product availability data for WooCommerce Products and add QPilot data to Reports and Notifications in WordPress.
Connecting QPilot to the WooCommerce Rest API
In order to ensure your site is ready to process Scheduled Orders, you need to connect QPilot to the WooCommerce Rest API. See the following article for a step-by-step guide: Connecting the WooCommerce API. When successfully connected you should see a healthy connection as shown below.
Learn more about connecting Autoship Cloud Here: Why and How Do I connect Autoship Cloud to QPilot?
How to Update the URL of a Site Already or Previously Connected to QPilot
This is common during site migrations as outlined here: Migrating Existing Scheduled Orders to a New Site.
- Go to QPilot > Sites > Edit
- Update the site URL in the General Settings tab
- Go to WP-Admin > Autoship Cloud > Settings > Connection Settings and select the "Disconnect" button
- Clear the values for QPilot Client Id & QPilot Client Secret then select "Update"
- Enter your QPilot Client Id and Client Secret from QPilot > My Account > Apps > WooCommerce and select "Connect"
- Go through the connection steps as outlined here: Connecting the WooCommerce API
How to Connect a Site Copied from an Existing QPilot Site
This is common when creating staging sites (which are usually copies of the live environment).
- Go to WP-Admin > Autoship Cloud > Settings > Connection Settings and select the "Disconnect" button
- Clear the values for QPilot Client Id & QPilot Client Secret then select "Update"
- Enter your QPilot Client Id and Client Secret from QPilot > My Account > Apps > WooCommerce and select "Connect"
- Go through the connection steps as outlined here: Connecting the WooCommerce API
Common Error Responses
If your connection is showing as "Unhealthy" or displaying errors, you will need to isolate the issue and resolve it in order to successfully connect. Common errors and the best troubleshooting steps are outlined below.
When reviewing an unhealthy connection status in Autoship Cloud > Settings, you will often see an HTTP error code. If an HTTP error code does not display, check your Autoship Cloud Error Logs for a detailed error message with the HTTP code.
- 400 Bad Request
- 401 Unauthorized / 403 Forbidden
- 401 Sorry You Are Not Allowed To Create Resources
- 404 Error Resources Not Found
- 500 Internal Server Error
- Healthy Connection Result with Errors Displaying
- Site Displaying "Not Connected" After Connecting it to QPilot
400 Bad Request
The 400 error code indicates that the request is invalid, e.g. using an unsupported HTTP method.
The error is most common with staging sites using an insecure URL ("http" instead of "https"). This is error is documented by WooCommerce's REST API docs here: https://woocommerce.github.io/woocommerce-rest-api-docs/#errors.
If this is the case, you may want to ask your hosting provider to enable your staging site to be a secure URL (use " https://mysite.staging.myhost.com" instead of "http"), so you can then connect your site's API without using the secure URL.
401 Unauthorized / 403 Forbidden
- First, make sure that you have met the API requirements as outlined in How QPilot Makes API Requests.
- For example, if you have not set a Site Title in WordPress your site may return a HTTP 401 error.
- You will also get a connection error if the WooCommerce API is not enabled on the site.
- Check that there is a valid WooCommerce API key for "Autoship - QPilot". The API keys are listed under WP-Admin > WooCommerce > Settings > Advanced (tab) >> REST API.
- If there is no API key for "Autoship - QPilot", follow the guide to Connect Autoship Cloud.
- Ensure that the associated user account for this API key is a site administrator with full privileges to manage WooCommerce.
- Ensure you have not password protected access to your site using settings on your WordPress Site or using .htaccess rules. Passwords are problematic for incoming requests and is common on some staging sites.
- Note: In some cases, you can still connect a password-protected site by whitelisting QPilot IP's addresses. Learn more here: Whitelisting QPilot IP Addresses With Firewalls
- Disable any plugins that are blocking access to the site. Some security plugins can block incoming requests to your site and causes connection errors.
- To learn more see here: Deactivating Plugins for WooCommerce Site Troubleshooting
- Learn more about security plugins there: Will My Security Plugin Work With Autoship Cloud?
- Whitelist QPilot IP Addresses in your firewall to ensure you server is not blocking incoming QPilot requests. Learn more here: Whitelisting QPilot IP Addresses With Firewalls
- In some cases, invalid permalinks can cause Http 401 errors. See "Configuring Permalinks" for more information and the best next steps.
You can learn more about 401 errors here.
401 Sorry You Are Not Allowed To Create Resources
If you are receiving this error, please see our documentation for the best next steps and more details: Error 401: Sorry You Are Not Allowed To Create Resources. You can learn more about 401 errors here.
404 Error Resources Not Found
The 404 error indicates that the request reached the server, however, the information requested was not found. If the HTTP error code error does not display on the test results for API Healthiness, it can be found in the Autoship Log.
Examples of common redirects resulting in a 404 Error:
- Secure to insecure site redirect ("https" redirecting to "http" protocol)
- A site URL that redirects to a different URL (configured within your site's .htaccess or DNS).
- Misconfigured Permalinks on your site (See this helpful article from WP-Beginner regarding 404 errors related to Permalinks).
- TLS version for your site's SSL certificate: QPilot supports up to version 1.2). If your site uses TLS version greater than 1.2 for its SSL certificate, you may experience a connection error with QPilot.
Resolving a redirect issue:
- Navigate to your QPilot Merchant Account and edit your connected site's settings.
- Within the "General Settings" tab, edit the url of your connected site to the url your site is redirecting to.
- Select "Update" to confirm your changes.
- After updating your url, within your WordPress Admin, visit WP-Admin > Autoship Cloud > Settings and then select "Test Integration". This will attempt to test your site's connection to QPilot and result in a healthy connection status if the issue is fixed.
500 Internal Server Error
The 500 error indicates a fatal exception has been thrown on the server. This type of error can be caused by many different types of issues, and the source of the error must be tracked down. Often times since the error is on the server, your hosting provider can be used to help with troubleshooting and fixing 500 errors.
Common Causes
- Another plugin or theme
- Database or server errors (such as running out of memory)
- Browser cache
- WordPress Permalinks
- Corrupted core database files
- Invalid site or folder permissions
- Invalid permalinks (usually an HTTP 520 error)
To learn more about HTTP 500 errors see here: How to Fix a 500 Internal Server Error on Your WordPress Site.
How To Resolve an HTTP 500 Error
- Check your Autoship Cloud Error Logs. These logs can be accessed and reviewed in Autoship Cloud > Settings > Logs.
- Check your server error logs for any obvious errors. Contact your site administrator to correct these errors then try again.
- If you don't have access to your server logs, you can ask your hosting provider or site administrator.
- De-activate plugins and then test the API and activate additional plugins one at a time until the source of the error is found.
- If you find a plugin is causing the connection error, contact the plugin author and include the error message.
- Learn more here: Deactivating Plugins for WooCommerce Site Troubleshooting
- Change the current theme to a basic theme (for example: WooCommerce's Storefront) then test the API.
- If the issue is resolved after updating your theme, then contact the theme author for assistance.
- Learn more here: Switch to a "Basic" Theme for WooCommerce Site Troubleshooting
- If you are still getting a 500 error, the issue may be caused by invalid permalinks. See "Configuring Permalinks" for more information and the best next steps.
Learn more about troubleshooting 500 errors here.
Healthy Connection Result with Errors Displaying
Sometimes you may see errors appear within a healthy API test response. See the example screenshot below where a 500 error is returned within a successful API test response:
This means that it is possible to connect with the URLs (the "endpoints") for your site and successfully test your API, but your site is responding to an API request with "other" errors (for example returning a non-standard error message or one that is not a common API response).
This does not necessarily mean that the connection with your site is unhealthy or that Autoship Cloud's connection with QPilot is not working. Instead, it means that your site may have errors within its code. Typically, this type of situation is caused when another plugin installed on your site is causing an unexpected or fatal error.
Suggested Steps to Resolve This Type of Error
- Run the "test connection" action again.
- This helps clear any notices and asks QPilot to retest URLs.
- In some cases, the error message clears on its own. If so, this could be that the cause of this issue was resolved (with a plugin update for example) and is no longer causing the notice.
- If the error persists, you'll want to debug this as you would any error within WordPress. Learn more here: What Are the Best Steps to Troubleshoot Errors With My WooCommerce Site?
- Enable the WP Error log ( https://wordpress.org/support/article/debugging-in-wordpress/ ).
- The Error log can then be used to troubleshoot which file installed on your site might be causing the problematic response to the API Health Check.
- Pro Tip! You may also configure the WP Error Log to not display to customers and provide additional error details.
PHP Warnings and Errors
Sometimes the WooCommerce API can produce PHP error messages in the response instead of properly formatted JSON.
- De-activate all plugins on the site except for WooCommerce and then test the API and activate additional plugins one at a time until the source of the error is found.
- Change the current theme to the default WordPress theme (for example, Storefront or the default "2017" WordPress theme) then test the API. These default themes should not produce any errors.
- These steps are outlined here: What Are the Best Steps to Troubleshoot Errors With My WooCommerce Site?
Product Sync Related Errors
Sometimes your firewall will block HTTP requests to endpoints used by QPilot to update your product availability during product synchronization. If you are having product sync errors regarding product availability, be sure the following HTTP requests and their endpoints are not being blocked:
-
GET: /wp-json/wc/v2/products/<id>
-
PUT: autoshipcloud/v1/product
After Connecting to QPilot, Connection Settings Display "Not Connected"
If the display "Not Connected" is shown after going through the connection process and QPilot redirects you back to your site, this usually indicates there was an error in authenticating your site with QPilot. If our QPilot Client Secret created in QPilot > My Account > Apps > WooCommerce is copied incorrectly or is altered before connecting, your site will fail to be authenticated with QPilot.
How to Verify a QPilot Site Authentication Error
From WP-Admin > Autoship Cloud > Settings > Connection Settings, select the Logs tab and download your Autoship Logs. An Authentication error will look like the entry below if your site failed to authenticate with QPilot.
[12-04-2021 @ 17:01:19] Autoship Oauth Exception - An 401 Exception Occurred when attempting Oauth connection to QPilot. Additional Details: Unauthorized
See the site displaying the "Not Connected" status after going through the connection process in QPilot and where to locate your Autoship Logs in the image below
How to Resolve this Type of Connection Error
As a WordPress Administrator, log in to QPilot Merchant Center > My Account > Apps > WooCommerce, create a new QPilot Client Secret and retry connecting the site using the new QPilot Client Secret copied to its field on the site's Connection Settings page. For detailed steps for how to connect your site to QPilot see our doc Connecting the WooCommerce API.
Advanced Troubleshooting
Testing the WooCommerce REST API
- Navigate to WooCommerce > Settings >> Advanced >> REST API.
- In older versions of WooCommerce, you may need to select "Enable the REST API" and Save Changes before proceeding.
- In the REST API tab, add a new API Key with the settings below:
Description: "Test Key" (or any description you choose)
User: Select a user who has Administrator User privileges for the Wordpress site
Permissions: Read/Write
- Manually test the REST API by Making a Basic Request to test the WooCommerce API with your site.
Manually Testing QPilot Integration with Postman
Sometimes manually testing the API Healthiness with a client like Postman can assist in troubleshooting. Some hosting providers restrict access to sites, preventing site visitors (including HTTP requests from external sources like the QPilot API) from getting appropriate responses (for instance: html log in instead of the expected JSON object). Some hosting providers restrict certain HTTP requests (commonly seen: PUT or update requests). Testing the API Healthiness manually will give additional details to a failed HTTP request including request type, status, and the response body.
This is a similar test to that outlined in WooCommerce's documentation: Making a Basic Request. We use the WooCommerce API keys to authenticate make the following 3 requests:
- GET- {your site url}/wp-json/wc/v3/products/
- POST- {your site url}/wp-json/autoshipcloud/v1/statuscheck/post
- PUT- {your site url}/wp-json/autoshipcloud/v1/statuscheck/put
Any failure response should be recorded to share with your hosting provider.
What if I get a different response?
The response body will vary depending on the request URL and if there are any errors. In the example above, the response body shows a successful request. However, you may also get a response that shows a detailed error message or even code from your site.
- If you get an error response, find the HTTP error above for more information on common causes and troubleshooting steps.
- If the response body contains code from your site, you will need to contact your hosting provider for further assistance. Common causes may include Permalinks or server security.
Configuring Permalinks
Permalinks can cause connection HTTP 400 and 500 errors on your site. If you suspect Permalinks are an issue, please follow and review the following:
- Contact your hosting provider with the error you are experiencing.
- You can learn more about how to format WordPress Permalinks for WooCommerce here.
- To learn more about how Permalinks work with WooCommerce REST API see here.
Common Permalink Structure
A common permalink structure is shown below. If you suspect permalinks are the issue, we recommend attempting this combination and then attempting to reconnect (as outlined here). However, not all sites are the same and you may need a different setup than in this example.
- Set "Common Settings" to "Post Name" (https://yoursite.com/sample-post/)
- Set "Optional" settings to blank values except "Product category base" which can be set to "product-category" and "Product tag base" which can be set to "product-tag"
- Set "Product permalinks" to "Custom base" and then "/shop/"
Clearing Existing Autoship Connection Setting Values & Reconnecting to QPilot
When copying a site to a staging site or when changing an existing connected site's URL, values stored by the Autoship Cloud plugin for its Connection Settings need to be updated to ensure that the site connection in QPilot is correct. Values may need to be reset during troubleshooting common connections errors as well.
Though the steps are similar, when updating a connected site's URL in QPilot, an extra step is needed to ensure the intended connected site is updated (rather than a new site being created). QPilot connects to sites based on unique URLs, so it's important to keep an eye on your connected sites in your QPilot Merchant Center and follow the outlined steps during this process. See here for more details: Connecting QPilot to the WooCommerce Rest API
When to Try Clearing QPilot Connection Values & Reconnecting
- When updating a site's URL
- When a site connected to QPilot is cloned and needs to be connected as a new QPilot site
- When an existing QPilot connected Site Id does not match the Id in the Autoship Settings Connection Settings.