• Resolved k4mr4n

    (@k4mr4n)


    I have a problem with Rest Api, I am using Automattic Woocommerce Rest Api to search categories, I am getting this error:

    PHP Fatal error:  Uncaught Automattic\WooCommerce\HttpClient\HttpClientException: JSON ERROR: Syntax error
    
    

    This is my configuration for api

    $woocommerce = new Client(
        'https://url',
        'ck_xxxxxxxxxxxxxx',
        'cs_xxxxxxxxxxxxx',
        [
            'version' => 'wc/v3',
            'timeout' => 0
        ]
    );

    I am sending GET Request $woocommerce->get('products/categories?search=E?itim Hizmeti');
    it returs json syntax error,the problem is it returns error for specific search string for example if i use above string it will return error but if i will use this $woocommerce->get('products/categories?search=Acil Durum & Güvenlik Ekipman');
    it will give perfect response without error, for the first request I get body as html 400 bad request cloudflare, I tried to close cloudflare and it still gives me the same error, I checked permalinks and it is okay, I deactivated some plugins still get this error, I tested both request in postman it works perfectly, then I tested with different server and url both request works.
    If someone has solution I would be appreciative, I spend almost 2 days to find a problem where does it come from.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter k4mr4n

    (@k4mr4n)

    I figured out that cloudflare some how sees my request as malformed, when I am sendiing query search string with space and cappital H like this “E?itim Hizmeti” it returns 400 bad request error, for any another string it return json response

    Thread Starter k4mr4n

    (@k4mr4n)

    I stiil need help because I dont know what can this cause?

    @k4mr4n We are unable to help troubleshoot custom code and the REST API ourselves as it’s outside the scope of support we offer. However, I will leave this thread open in case anyone from the community would like to weigh in.

    Sorry I can’t be of more help here!

    Hi @k4mr4n

    We’ve not heard back from you in a while, so I’m marking this thread as resolved. If you have any other questions, please feel free to open a new topic.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Woocommerce REST API JSON Error URGENT’ is closed to new replies.