• Hello,

    I’m trying to develop a rest client with api v2. I can get products, categories, etc, but I can’t post or put anything. The error I get is this:

    {“code”:”rest_invalid_json”,”message”:”El cuerpo JSON no v\u00e1lido pas\u00f3.”
    ,”data”:{“status”:400,”json_error_code”:4,”json_error_message”:”Syntax error”}}c
    url: (3) [globbing] unmatched close brace/bracket in column 8

    and this is the curl command:

    D:\Instaladores\curl>curl -X POST https://rcsoftware.test/wp-json/wc/v2/products
    /categories -u ck…:cs…. -H “Content-Type: application/json” -d ‘{“name”: “Test Category”}’ –insecure

    Any help?

    Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The error means that your request is not formed correctly. Check your json format. According to the message, you have an unmatched close bracket.

    Thread Starter cregonat

    (@cregonat)

    I know, but I get the same response no matter what json data is sent to the server. For example, this happens with the json I take from the docs.:

    ‘{
    “name”: “Clothing”,
    “image”: {
    “src”: “http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg”
    }
    }’

    thanks

    Thread Starter cregonat

    (@cregonat)

    well, after some time of trial and error, I’ve found that if I send the json with the ” escaped, and without spaces, it works ok.

    ej:

    {\”name\”:\”CategoryOne\”} —> Ok
    {\”name\”:\”Category One\”} —> Fail
    {“name”:”CategoryOne”} —> Fail

    Any ideas?

    How are you generating your JSON data? Try using consistent generation may be json_encode an array and send it then. The API runs a json_decode on the body, so if the json_encode is used for the encoding you should pass the validation.

    Thread Starter cregonat

    (@cregonat)

    I’ve generated the json with delphi, but I forgot to convert to utf-8 before send it to the server. Usin curl for test, seems that I copied the json text bad encoded.
    Now it works ok.

    Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘problem with REST Api’ is closed to new replies.