uploading new variables.json via the API

Can someone give me an example of variables.json that can be uploaded (PUT or PATCH) via the API. No matter what I try I get the following error:

/api/v2/themes/4/assets/variables.json


{
    "message": "Validation Failed",
    "status": 400,
    "errors": [
        {
            "field": "data",
            "code": "missingField",
            "status": 400,
            "message": "data is required."
        }
    ]
}

Comments

  • Your body needs to be like this:

    {
        "data": "{ \"global\": { \"mainColors\": { \"primary\": \"#444\" }  } "
    }
    

    It's a little awkward do manually for sure.

  • Easiest way to escape the JSON manually is probably like with a tool like this:

    Then set the result as your data property.

  • Thank you.


    It's not the way it's presented when GETting the file. :-)

  • Unknown
    edited May 2020

    @Adam Charron I agree with Rhys here that the API docs on this are very unclear. I got stuck here myself. Any suggestions as to what we can put in our API docs for the theme endpooints to clarify this what is required in the "data" field?

  • Unknown
    edited May 2020

    Simple solution - instead of this:

    {
      "data": "some content"
    }
    

    something like this:

    {
      "data": "[escaped json content]"
    }
    


    A more complication solution would be for the API to accept JSON content directly. That way the PUT/PATCH would accept what the GET gives.

  • {
        "message": "Argument 2 passed to Vanilla\\Models\\ThemeModel::setAsset() must be of the type integer, string given, called in /var/www/frontend-97ba7a1937b120/applications/dashboard/controllers/api/ThemesApiController.php on line 245"
    }
    

    @Adam Charron did something change? Now I'm getting the above error. Same exact API call.

  • I'm not 100% sure, but I believe we'll be taking another look into those endpoints in the next sprint. We might have had a behaviour change of some kind that we didn't properly document, but in any case, the behaviour will be changing significantly for the 2020.011 release.