Question T6772
Visible to All Users

Edit a Survey created via API is not possible at the SurveyJS website...

created 4 years ago

Hello,

After reading a lot of documentation, maybe I've found out a "different" behavior when creating surveys using the surveyjs REST API or by using the SurveyCreator's JSON Editor at the surveyjs site.

I'll try to describe the two scenarios:

1 - if you create a survey by using the surveyjs SurveyCreator's at surveyjs website, you can edit, run, get results, etc. Everything works like a charm.

2 - but, if you create a survey (or get a json of a previous defined survey) by using the surveyjs REST API (e.g. JavaScript), for example:

JavaScript
//... var creator = new SurveyCreator.SurveyCreator("creatorElement", creatorOptions); creator.saveSurveyFunc = saveMyQuest; creator.loadSurvey("c826712e-d50b-442f-9dff-bxxxxxxxxxxx"); function saveMyQuest() { bodyofputrequest = { Id: "c826712e-d50b-442f-9dff-bxxxxxxxxxxx", Json: creator.text, Text: "sample any string" } $.ajax({ type: 'PUT', contentType: 'application/json', url: "https://api.surveyjs.io/private/Surveys/changeJson?accessKey=9375be70813442a08xxxxxxxxxx", dataType: 'json', data: JSON.stringify(bodyofputrequest), success: function (data) { console.log("OK"); }, error: function (request, msg, error) { console.log(msg); console.log(request); console.log(error); } }); }

you cannot edit the survey at the surveysjs website.

The code above tries to stores the survey at the surveyjs backend. This way, you are not able to change the survey's design at the surveijs site. You can only run, get results, etc.

I meant, in this case, the "Survey Designer" does not recognize the design of the survey created outside (via API rest).

Any ideas?
Thanks a lot!

Answers approved by surveyjs Support

created 4 years ago

Hello,

We're using the following code:

JavaScript
creator.saveSurveyFunc = function(saveNo, callback) { $.ajax({ url: baseUrl + "changeJson?accessKey=" + accessKey, type: "PUT", data: { Id: modelData.Id, Text: creator.text, Json : creator.text }, success: function (data) { callback(saveNo, true); } }); }

Thanks, Serge
SurveyJS Team

    Comments (1)
    P P
    Prof. Fabio F Silveira 4 years ago

      Thank you, Serge! Now it works like a charm!