Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON ERROR: Syntax error #55

Open
maab16 opened this issue Oct 28, 2020 · 24 comments
Open

JSON ERROR: Syntax error #55

maab16 opened this issue Oct 28, 2020 · 24 comments
Labels
good first issue Good for newcomers

Comments

@maab16
Copy link
Collaborator

maab16 commented Oct 28, 2020

Sometimes may be you get this error. If you are using it first time then make sure you followed some steps

  1. Enable mod_rewrite in your server
  2. Make sure you have .htaccess file in your WordPress root directory. Contents should look like
<IfModule mod_rewrite.c>
	RewriteEngine On
	RewriteBase /
	RewriteRule ^index\.php$ - [L]
	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteCond %{REQUEST_FILENAME} !-d
	RewriteRule . /index.php [L]
</IfModule>
  1. Make sure your URL permalink is Post name
@Codexshaper Codexshaper added the good first issue Good for newcomers label Oct 28, 2020
@Codexshaper Codexshaper pinned this issue Oct 28, 2020
@alexvolley
Copy link

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?

@SDekkers
Copy link

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.

@maab16
Copy link
Collaborator Author

maab16 commented Dec 15, 2020

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.

@SDekkers
Copy link

SDekkers commented Dec 15, 2020

@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.

@maab16
Copy link
Collaborator Author

maab16 commented Dec 18, 2020

@SDekkers You don't need to use HTTPClient. It already implemented. Can you share your code how yo implement this package?

@SDekkers
Copy link

@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)

@maab16
Copy link
Collaborator Author

maab16 commented Dec 18, 2020

@SDekkers Sounds looks good. But where you get wocommerce_id in above example?

@SDekkers
Copy link

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.

@maab16
Copy link
Collaborator Author

maab16 commented Dec 18, 2020

@SDekkers Yea, you get the point. Go ahead. It's not this package related issue.

@CrawDance
Copy link

Hey there
I still have the similar issue, any advise would be appreciated.
regards
laravel 7 - php 7.4

@maab16
Copy link
Collaborator Author

maab16 commented Jan 3, 2021

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

@CrawDance
Copy link

thanks for the response,
It was working as intended almost a week ago.
no changes no updates, nothing.
Maybe a webhosting related issue ?

@MSufianS
Copy link

MSufianS commented Jan 4, 2021

Faced same issue.

@itsme-francesco
Copy link

itsme-francesco commented Jul 12, 2021

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.

@AIMahn
Copy link

AIMahn commented Jul 19, 2022

Same problem here, new Woocommerce installation set up locally, but can't establish a connection.

@maab16
Copy link
Collaborator Author

maab16 commented Jul 19, 2022

Hello @almahn,

Can you share the error? Thanks

@saqlainkhadim
Copy link

saqlainkhadim commented Oct 31, 2022

@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

@maab16
Copy link
Collaborator Author

maab16 commented Oct 31, 2022

@saqlainkhadimbusiness

Please share your request and response. Thanks

@StanMenten99
Copy link

Changing the store url from https://example.com to https://www.example.com (so adding www) fixed this issue for me.

@gusjara
Copy link

gusjara commented Jan 14, 2023

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.

@outzo
Copy link

outzo commented Feb 1, 2024

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);

@outzo
Copy link

outzo commented Feb 1, 2024

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 wwwe 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

@gusjara
Copy link

gusjara commented Feb 1, 2024

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

@maulik41
Copy link

maulik41 commented May 8, 2024

I was facing same error, i solved by this - stackoverflow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests