woocommerce / woocommerce/wc-api-php

JSON ERROR: Syntax error

Open
#327 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stale
Dominant language
PHP
Stars
546
Forks
158
Avg merge
3h 21m
Merged PRs (30d)
2

Description

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] => 
	)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with WooCommerce/HttpClient/HttpClient.php at processResponse (lines 378 and 422), then follow the request from Client.php line 82 to the products endpoint. Reproduce the GET request and inspect why it returns an empty text/html body with status 200 instead of JSON. Done means identifying a reproducible library or response-handling problem and documenting the verified cause.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.