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 #327

Open
iw0100 opened this issue Jun 7, 2022 · 7 comments
Open

JSON ERROR: Syntax error #327

iw0100 opened this issue Jun 7, 2022 · 7 comments

Comments

@iw0100
Copy link

iw0100 commented Jun 7, 2022

I tried get product using API call but i got below error
i check this and many other blog. Also i changes as per recommendation on the server as per suggestion but I didn't find the solution for this error :- JSON ERROR: Syntax error
I am Using 3.0.0 Version
Working Fine in Postman

	Automattic\WooCommerce\HttpClient\HttpClientException Object
	(
	    [request:Automattic\WooCommerce\HttpClient\HttpClientException:private] => Automattic\WooCommerce\HttpClient\Request Object
	        (
	            [url:Automattic\WooCommerce\HttpClient\Request:private] => https://www.website.com/wp-json/wc/v3/products?status=publish
	            [method:Automattic\WooCommerce\HttpClient\Request:private] => GET
	            [parameters:Automattic\WooCommerce\HttpClient\Request:private] => Array
	                (
	                    [status] => publish
	                    [per_page] => 1
	                    [stock_status] => instock
	                    [orderby] => date
	                )

	            [headers:Automattic\WooCommerce\HttpClient\Request:private] => Array
	                (
	                    [Accept] => application/json
	                    [User-Agent] => WooCommerce API Client-PHP/3.0.0
	                )

	            [body:Automattic\WooCommerce\HttpClient\Request:private] => 
	        )

	    [response:Automattic\WooCommerce\HttpClient\HttpClientException:private] => Automattic\WooCommerce\HttpClient\Response Object
	        (
	            [code:Automattic\WooCommerce\HttpClient\Response:private] => 200
	            [headers:Automattic\WooCommerce\HttpClient\Response:private] => Array
	                (
	                    [Date] => Mon, 06 Jun 2022 12:56:00 GMT
	                    [Content-Type] => text/html
	                    [Transfer-Encoding] => chunked
	                    [Connection] => keep-alive
	                    [last-modified] => Monday, 06-Jun-2022 12:56:00 GMT
	                    [Cache-Control] => private, no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0, s-maxage=0
	                    [cf-edge-cache] => no-cache
	                    [CF-Cache-Status] => DYNAMIC
	                    [Expect-CT] => max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
	                    [Report-To] => {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=PlYSeCqCLScJndCR5WtftcnAH3Vi2twyTa6oaQ7b6t31U2CSDoHoxTDJLJs%2FvQhHiNOmoZLZWlo2lw9m%2Fe9HoyHbilpzHupYr4mArCv74VqKNA%2BfNNhZyA1QATtUCJx7FMiRdaV6508DkH0zVA%3D%3D"}],"group":"cf-nel","max_age":604800}
	                    [NEL] => {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
	                    [Server] => cloudflare
	                    [CF-RAY] => 71714e3bdae06368-ORD
	                    [alt-svc] => h3=":443"; ma=86400, h3-29=":443"; ma=86400
	                )

	            [body:Automattic\WooCommerce\HttpClient\Response:private] =>

	        )

	    [message:protected] => JSON ERROR: Syntax error
	    [string:Exception:private] => 
	    [code:protected] => 200
	    [file:protected] => /var/www/html/sidecart/woocommerce/vendor/automattic/woocommerce/src/WooCommerce/HttpClient/HttpClient.php
	    [line:protected] => 378
	    [trace:Exception:private] => Array
	        (
	            [0] => Array
	                (
	                    [file] => /var/www/html/sidecart/woocommerce/vendor/automattic/woocommerce/src/WooCommerce/HttpClient/HttpClient.php
	                    [line] => 422
	                    [function] => processResponse
	                    [class] => Automattic\WooCommerce\HttpClient\HttpClient
	                    [type] => ->
	                    [args] => Array
	                        (
	                        )

	                )

	            [1] => Array
	                (
	                    [file] => /var/www/html/sidecart/woocommerce/vendor/automattic/woocommerce/src/WooCommerce/Client.php
	                    [line] => 82
	                    [function] => request
	                    [class] => Automattic\WooCommerce\HttpClient\HttpClient
	                    [type] => ->
	                    [args] => Array
	                        (
	                            [0] => products
	                            [1] => GET
	                            [2] => Array
	                                (
	                                )

	                            [3] => Array
	                                (
	                                    [status] => publish
	                                    [per_page] => 1
	                                    [stock_status] => instock
	                                    [orderby] => date
	                                )

	                        )

	                )

	            [2] => Array
	                (
	                    [file] => /var/www/html/sidecart/woocommerce.php
	                    [line] => 19
	                    [function] => get
	                    [class] => Automattic\WooCommerce\Client
	                    [type] => ->
	                    [args] => Array
	                        (
	                            [0] => products
	                            [1] => Array
	                                (
	                                    [status] => publish
	                                    [per_page] => 1
	                                    [stock_status] => instock
	                                    [orderby] => date
	                                )

	                        )

	                )

	            [3] => Array
	                (
	                    [file] => /var/www/html/sidecart/woocommerce.php
	                    [line] => 710
	                    [function] => woocommerce_call
	                    [args] => Array
	                        (
	                            [0] => www.website.com
	                            [1] => "consumer_key"
	                            [2] => "consumer_secret"
	                            [3] => products
	                            [4] => GET
	                            [5] => Array
	                                (
	                                    [status] => publish
	                                    [per_page] => 1
	                                    [stock_status] => instock
	                                )

	                        )

	                )

	            [4] => Array
	                (
	                    [file] => /var/www/html/sidecart/woocommerce.php
	                    [line] => 60
	                    [function] => get_graphql_api_list
	                    [class] => Base_Function
	                    [type] => ->
	                    [args] => Array
	                        (
	                            [0] => products
	                            [1] => Array
	                                (
	                                    [status] => publish
	                                    [per_page] => 1
	                                    [stock_status] => instock
	                                    [orderby] => date
	                                )

	                        )

	                )

	        )

	    [previous:Exception:private] => 
	)
@tomektomczuk
Copy link

I'm getting the same error. Although when I user URL with ck & cs as a query string I get all the records

$woocommerce = new Client( 'http://retherun.test/', '***HIDDEN***', '***HIDDEN***', [ 'wp_api' => true, 'version' => 'wc/v3', 'verify_ssl' => false ] );

Here is the error from the client. I'm using it on local env and I have SSL.
`JSON ERROR: Syntax error
Automattic\WooCommerce\HttpClient\Request Object
(
[url:Automattic\WooCommerce\HttpClient\Request:private] => http://retherun.test/wp-json/wc/v3/products/attributes?oauth_consumer_key=***HIDDEN***&oauth_nonce=***HIDDEN***&oauth_signature_method=HMAC-SHA256&oauth_timestamp=1654672428&signature=***HIDDEN***
[method:Automattic\WooCommerce\HttpClient\Request:private] => GET
[parameters:Automattic\WooCommerce\HttpClient\Request:private] => Array
(
[oauth_consumer_key] => HIDDEN
[oauth_nonce] => HIDDEN
[oauth_signature_method] => HMAC-SHA256
[oauth_timestamp] => 1654672428
[signature] => HIDDEN
)

[headers:Automattic\WooCommerce\HttpClient\Request:private] => Array
    (
        [Accept] => application/json
        [User-Agent] => WooCommerce API Client-PHP/3.1.0
    )

[body:Automattic\WooCommerce\HttpClient\Request:private] => 

)
Automattic\WooCommerce\HttpClient\Response Object
(
[code:Automattic\WooCommerce\HttpClient\Response:private] => 301
[headers:Automattic\WooCommerce\HttpClient\Response:private] => Array
(
[Server] => nginx
[Date] => Wed, 08 Jun 2022 07:13:48 GMT
[Content-Type] => text/html
[Content-Length] => 162
[Connection] => keep-alive
[Location] => https://retherun.test/wp-json/wc/v3/products/attributes?oauth_consumer_key=ck_***HIDDEN***&oauth_nonce=***HIDDEN***&oauth_signature_method=HMAC-SHA256&oauth_timestamp=1654672428&signature=***HIDDEN***
)

[body:Automattic\WooCommerce\HttpClient\Response:private] => 

301 Moved Permanently

nginx

)`

@WillieHuizing
Copy link

Have you tried adding 'follow_redirects'?

$options = [
            'wp_api'           => true,
            'version'          => 'wc/v3',
            'verify_ssl'       => false,
            'timeout'          => 180,
            'follow_redirects' => true,
        ];

$client = new Client($url, $consumerKey, $consumerSecret, $options);

@iw0100
Copy link
Author

iw0100 commented Nov 2, 2022

Hello @WillieHuizing. I have tried but I face the same issue.

@StanMenten99
Copy link

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

@umairtipu
Copy link

Hi Everyone!

I have almost 300 products that needs to exported and all of them are having images, the images are in high resolution which means each image is almost 5 or more then 5MBs. The error is very weird and it is so long I am trying to fix this but nothing helpful material founded yet.

When I export products without images, it works fine and products imported successfully in the WP.

Screenshot from 2023-01-31 19-28-34

@jigzstar
Copy link

jigzstar commented Apr 6, 2023

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

This worked for me but had to remove the 'www'. So it looks like a configuration issue on the woocommerce server's end

@DoctorGuidance
Copy link

Have you tried adding 'follow_redirects'?

$options = [
            'wp_api'           => true,
            'version'          => 'wc/v3',
            'verify_ssl'       => false,
            'timeout'          => 180,
            'follow_redirects' => true,
        ];

$client = new Client($url, $consumerKey, $consumerSecret, $options);

this one worked for me.

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

No branches or pull requests

7 participants