Open maab16 opened 3 years ago
I have changed the .htaccess file to as shown however I'm still getting JSON ERROR: Syntax error, is there a work around for this?
I've found this error to show when trying to use the update call on a product, the root cause is the destination shop not accepting PUT requests (http 405 is thrown) as the server is limited to GET and POST requests.
I'll submit a PR that will show the appropriate HTTP error.
Hello @alexvolley and @SDekkers,
Thanks for creating the issue. If you followed above configuration then it's not configuration issue.
For @alexvolley you can check your API key and secret carefully and make sure have read and write permission. For further information follow this link https://woocommerce.github.io/woocommerce-rest-api-docs/#authentication
For @SDekkers I think you need to check your wocommerce account that you have write access.
@maab16 The key used was able to add products, but not update them.. I was able to reverse-engineer the response given by the API, which resulted in the below
(did a dd()
on $body
in the function processResponse()
in the HttpClient
)
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">\n
<html><head>\n
<title>405 Method Not Allowed</title>\n
</head><body>\n
<h1>Method Not Allowed</h1>\n
<p>The requested method PUT is not allowed for this URL.</p>\n
</body></html>\n
This obviously isn't JSON so the syntax error is technically correct, but the error can be better looking at the http status code.
edit: I see the HTTPClient isn't part of this package, so I shall PR it into the other package.
@SDekkers You don't need to use HTTPClient
. It already implemented. Can you share your code how yo implement this package?
@maab16 Nothing special..
Product::update($product->woocommerce_id, $data);
The PR I will add to the HTTPClient class in the Automattic\WooCommerce
package to improve the error message when the API endpoint throws a HTTP error (i.e. 405 method not allowed)
@SDekkers Sounds looks good. But where you get wocommerce_id
in above example?
Just my database, a separate modal with scraped products from a partner webshop.
The issue here is that my clients webshop hasn't allowed PUT and DELETE requests on its webserver, so the error message (JSON Syntax error) was somewhat vague.
@SDekkers Yea, you get the point. Go ahead. It's not this package related issue.
Hey there I still have the similar issue, any advise would be appreciated. regards laravel 7 - php 7.4
I've tested and it worked for me Laravel 7 and PHP 7.4. I think your issue related to the WordPress not Laravel. If you follow the instruction carefully I hope this issue will fix. Thanks
thanks for the response, It was working as intended almost a week ago. no changes no updates, nothing. Maybe a webhosting related issue ?
Faced same issue.
Hi, I'm facing the same issue.
In my case the issue is related to WP installed in a subfolder.
Is there a solution to apply in this case?
Thanks!
[Edit] I solved the issue by moving the site from subfolder to the root directory.
Same problem here, new Woocommerce installation set up locally, but can't establish a connection.
Hello @AlMahn,
Can you share the error? Thanks
@maab16 When I call the API from the request client it returns JSON and ok. but when I call this form laravel-woocomerce it says the JSON syntax error. maybe it is error in the repo or maybe my configuration fault
@saqlainkhadimbusiness
Please share your request and response. Thanks
Changing the store url from https://example.com
to https://www.example.com
(so adding www) fixed this issue for me.
Hi, i have an implementation with woocommerce version 7.1.0 and I don't have problems. But on a new implementations with woocommerce version 7.3.0 I can't fix the error "JSON ERROR: Syntax error", it's only when run update a product, but when I create I don't have any error.
The error displaying is that:
#message: "JSON ERROR: Syntax error"
#code: 503
#file: "./vendor/automattic/woocommerce/src/WooCommerce/HttpClient/HttpClient.php"
#line: 411
Tried with www
and without.
Any workaround for this?
I'll try to downgrade wc version and comment later.
My best regards.
Senhores me deparei com o mesmo problema, no GET de todas as Categorias, mesma aplicação que estava rodando sem problemas dias atrás Gentlemen, I came across the same problem, in the GET of all Categories, the same application that was running without problems a few days ago
'JSON ERROR: Syntax error',
$params = [
'per_page' => 100,
'page' => $cont,
];
$cat1 = Category::All($params);
Olá, tenho uma implementação com woocommerce versão 7.1.0 e não tenho problemas. Mas em novas implementações com woocommerce versão 7.3.0 não consigo corrigir o erro "JSON ERROR: Syntax error", é só quando executo atualizar um produto, mas quando crio não tenho nenhum erro.
O erro exibido é que:
#message: "JSON ERROR: Syntax error"
#code: 503
#file: "./vendor/automattic/woocommerce/src/WooCommerce/HttpClient/HttpClient.php"
#line: 411
Tentei com
www
e sem.Alguma solução alternativa para isso?
Vou tentar fazer o downgrade da versão wc e comentar mais tarde.
Os meus melhores cumprimentos.
Também tentei esta alternativa sem sucesso
Hi, I use on this way and can get categories Use URL without 'www' only https://domain.com use use Codexshaper\WooCommerce\Facades\Category;
getter $categories = Category::all(['per_page' => 100, 'page' => $page_number]); and in my .env WOOCOMMERCE_VERIFY_SSL=false WOOCOMMERCE_API_VERSION=v3
I was facing same error, i solved by this - stackoverflow
Sometimes may be you get this error. If you are using it first time then make sure you followed some steps
mod_rewrite
in your server.htaccess
file in your WordPress root directory. Contents should look likepermalink
isPost name