skip to Main Content

I have a VBA file that has been working for years with a POST to API function to create products on Shopify. It has suddenly and for non identified reason stopped working around April 15th 2019. It gives the following error:

“error”: “822: unexpected token at [my JSON string]

This is what the JSON string looks like (you can find a more complete one at the end of this post):

{
  "product": {
    "title": "Lunettes",
    "body_html": "some long text",
    "vendor": "Tom Ford",
    "product_type": "lunettes enfant adolescents",
    "published": false,
    "tags": "some tags",
    "variants": [
      {
        "option1": "default title",
        "price": "199",
        "sku": "1",
        "weight_unit": "g"
      }
    ],
    "options": [
      {
        "name": "title",
        "position": 1,
        "values": [
          "default title"
        ]
      }
    ]
  }
}

What I have already tried:

  • check the URL with correct API key and token/password

  • tried adding the latest released Shopify API version to the CURL : 2019-04

  • check the syntax of the JSON string (comas, {, etc)

Basically tried everything I knew. Please help if you have any clue.

the more complete Json_String is :

{"product":{"title":"Lunettes TF5501 ","body_html":"TEXT,<div style="text-align: center;"><img alt="Dimensions Lunettes Varionet TF5501 Argent" src="https://cdn.shopify.com/s/files/1/0855/6878/files/Lunettes.png?15354686291941720795" style="float: none; display: block; margin-left: auto; margin-right: auto;" /></div><div style="overflow-x: auto;"> <table width="100%"> <tbody><tr style="background-color: #98ffaf;"><td style="text-align: center;">140 mm</td><td style="text-align: center;">54 mm</td><td style="text-align: center;">38 mm</td><td style="text-align: center;">18 mm</td><td style="text-align: center;">145 mm</td></tr></tbody></table></div>","vendor":"Brand","product_type":"lunettes anti lumière bleue","published":false,"tags":"meta-filter-Marque-Varionet,meta-filter-Forme-Rectangle,meta-filter-Genre-Unisex,meta-filter-Genre-Homme,meta-filter-Genre-Femme,meta-filter-Couleur-Argent","variants":[{"option1":"default title","price":"199","sku":"tom ford tf5501016","position":1,"grams":"100","inventory_policy":"deny","compare_at_price":"339","fulfillment_service":"logisticien-mavu","inventory_management":"shopify","option_1":"default title","requires_shipping":true,"taxable":true,"inventory_quantity":1,"weight_unit":"g"}],"options":[{"name":"title","position":1,"values":["default title"] }]
}}

Thanks!

Youri

2

Answers


  1. Chosen as BEST ANSWER

    Thanks for your replies

    @David : I've seen the link https://community.shopify.com/c/Shopify-APIs-SDKs/error-gt-822-unexpected-token-at-price-rule/td-p/480430 , but i don't understand where and how i must use the 'X-Shopify-Access-Token' in VBA code, should it be added in the objHTTP.setRequestHeader? This is the API key, the Password or the "shared secret" ?

    @QHarr : my posting parameters are :

    Dim result As String
    Dim objHTTP As Object
    Url = "http://API-KEY:[email protected]/admin/api/2019-04/products.json"
    
    Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
    
    objHTTP.Open "POST", Url, False, "API-KEY", "PASSWORD"
    objHTTP.setRequestHeader "Content-Type", "application/json"
    
    
    objHTTP.send ("json_string")
    
    result = objHTTP.responseText
    

  2. The first JSON you provided (please correct it to a code-block) is correct, but when parsing your more complete Json_string, you’ll see that you have too much curly brackets at the end:

    {
        "product": {
            "title": "Lunettes TF5501 ",
            "body_html": "TEXT,https://cdn.shopify.com/s/files/1/0855/6878/files/Lunettes.png?15354686291941720795" style="float: none; display: block; margin-left: auto; margin-right: auto;" /> 140 mm54 mm38 mm18 mm145 mm",
            "vendor": "Brand",
            "product_type": "lunettes anti lumière bleue",
            "published": false,
            "tags": "meta-filter-Marque-Varionet,meta-filter-Forme-Rectangle,meta-filter-Genre-Unisex,meta-filter-Genre-Homme,meta-filter-Genre-Femme,meta-filter-Couleur-Argent",
            "variants": [{
                "option1": "default title",
                "price": "199",
                "sku": "tom ford tf5501016",
                "position": 1,
                "grams": "100",
                "inventory_policy": "deny",
                "compare_at_price": "339",
                "fulfillment_service": "logisticien-mavu",
                "inventory_management": "shopify",
                "option_1": "default title",
                "requires_shipping": true,
                "taxable": true,
                "inventory_quantity": 1,
                "weight_unit": "g"
            }],
            "options": [{
                "name": "title",
                "position": 1,
                "values": ["default title"]
            }]
        }
    }
    }
    }
    

    Try removing the last 2 curly brackets

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search