php - WooCommerce REST API error: Invalid URL, no WC API found -


i'm trying start out woocommerce rest api client library keep getting error:

invalid url, no wc api found @ http://[my-store].com/wc-api/v2/ -- ensure store url correct , pretty permalinks enabled.

pretty permalinks enabled , set post name, according this thread. manually accessing url via browser gives json output of woocommerce settings, that's why assume store url correct. (it's same domain, i'm working on.) tried insert new consumer , secret keys doesn't help.

a bit of research in code brought me class-wc-api-client.php.

$index = @file_get_contents( $this->api_url );  // check http 404 response (file_get_contents() returns false when encountering 404) // means: // 1) store url not correct (missing sub-directory path, etc) // 2) pretty permalinks disabled if ( false === $index ) {     throw new wc_api_client_exception( sprintf( 'invalid url, no wc api found @ %s -- ensure store url correct , pretty permalinks enabled.', $this->api_url ), 404 ); 

$index indeed equals false, means file_get_contents got 404 response. creating /wc-api/v2/ directory within store's directory didn't help.

i can't find out why file_get_contents gets 404 response while browsing page display non-empty json string. feel i'm missing basic.

any appreciated!


edit: found solution! encountered problem again today , did research on file_get_contents() returning false on json. this thread put me on right track. setting allow_url_fopen = on in php.ini solves case. might useful know if else runs problem.

i had similar issue. problem caused 1 of settings in itheme security. under banned users -> enable hackrepair.com's blacklist feature. if have list enabled, itheme keeps ist of allowed user agents in .htaccess. when using php's file_get_contents, there no user agent, script ends being blocked.

if else having problems this, suggest looking through .htaccess see if there suspicious.


Comments