Question T4661
Visible to All Users

Example of changeJson Json format?

created 5 years ago

I'm just getting familiarized with SurveyJS through sampling the Survey Creator, and trying to understand what the json code is for. I'm still new with all of this, having been able to successfully create a new survey via Python requests.

I am having trouble with the changeJson post request. I've tried a number of different ways to serialize JSON, and have tried both Python and Javascript, and failing with a vague 500 error,
ie, <meta property="og:url" content="https://surveyjs.io/Error/Index?500;https://surveyjsio:80/api/MySurveys/changeJson?accessKey=

according to the Content body html that comes back in my request - but I cannot see what the error is saying, so I don't know what I'm doing wrong.

I've tried Python's json.dumps(myjson) <-- a copy paste of a different survey json, ie: Survey A's json editor, trying to go into Survey B which has no question data yet.

I've tried both Python's post request via application/json as well as application/xml

I've also tried the same thing with Javascript and Json.stringify, only to see no updates made to the survey.

Can you provide an super simple example of what a complete request looks like (especially for the Json string), and what is the "Text" attribute supposed to be for?

Comments (1)

    Hello,

    We will investigate this issue and write back to this thread immediately

    Thanks, Alex
    SurveyJS Team

    Answers approved by surveyjs Support

    created 5 years ago

    Hello,

    Here is the documentation of the changeJson Web API - https://surveyjs.io/Help/Api/POST-api-MySurveys-changeJson_accessKey?apiType=private&renderType=desktop

    Here is our JavaScript code of calling the changeJson endpoint:

    JavaScript
    creator.saveSurveyFunc = function(saveNo, callback) { $.ajax({ url: "/api/MySurveys/changeJson?accessKey=<YOUR_ACCESS_KEY>", type: "POST", data: { Id: modelData.Id, Text: creator.text, Json : creator.text }, success: function (data) { callback(saveNo, true); } }); }

    Hope this helps

    Thanks, Serge
    SurveyJS Team

      Show previous comments (1)

        Hello,

        We're filling both fields Text and Json with the same value - serialized survey JSON from the creator.text property. These fields are later stored in different fields of our database. We use two fields for the backward compatibility.

        In other words, does this api call update the json in the JSON Editor field for the specified Survey ID that is included in the ajax call?

        This API call updates survey JSON in surveyjs.io surveys database for the given survey ID.

        Thanks, Serge
        SurveyJS Team

          Ah, ok. I played around with the Library version and got more of what I was looking for. I'm still not really able to make this work with the API and I'm not sure what I'm doing wrong. Will keep trying and experimenting until I get a response.

          Just to try to clarify though, what is the JSON Editor for in the Survey Creator interface? I'm really pretty new to this, as I'm sure you can tell! :)

            Hello,

            You can use SurveyCreator's JSON Editor to view the JSON which represent the survey. You can share this JSON, or save it in database and restore the survey later. Also you can edit JSON manually (this is convenient is some cases)

            Thanks, Alex
            SurveyJS Team