Details
-
Type:
Bug
-
Status: Open
-
Priority:
Critical
-
Resolution: Unresolved
-
Affects Version/s: 3.7.7, 3.9.1
-
Fix Version/s: None
-
Component/s: Course, Web Services
-
Labels:None
-
Affected Branches:MOODLE_37_STABLE, MOODLE_39_STABLE
Description
Hi Team,
When i'm trying to import a course using the API function core_course_import_course system gives the below moodle exception for some courses;
Please note that all other API calls/functions are working and platform is ASP.NET C#
ERROR MESSAGE:-
"exception":"moodle_exception","errorcode":"backupprecheckerrors"
CODE BELOW:-
MoodleImportCourse import = new MoodleImportCourse();
{{ import.importfrom = HttpUtility.UrlEncode(idimportcourse);}}
{{ import.importto = HttpUtility.UrlEncode(id);}}
{{ import.deletecontent = HttpUtility.UrlEncode("0");}}
{{ import.name = HttpUtility.UrlEncode("activities");}}
{{ import.value = HttpUtility.UrlEncode("1");}}
{{ import.name1 = HttpUtility.UrlEncode("blocks");}}
{{ import.value1 = HttpUtility.UrlEncode("1");}}
{{ import.name2 = HttpUtility.UrlEncode("filters");}}
{{ import.value2 = HttpUtility.UrlEncode("1");}}List<MoodleImportCourse> importList = new List<MoodleImportCourse>();
{{ importList.Add(import);}}Array arrImport = importList.ToArray();
{{ String postImportData = String.Format("importfrom={0}&importto={1}&deletecontent={2}&options[0][name]={3}&options[0][value]={4}&options[0][name]={5}&options[0][value]={6}&options[0][name]={7}&options[0][value]={8}", import.importfrom, import.importto, import.deletecontent, import.name, import.value, import.name1, import.value1, import.name2, import.value2);}}
{{ string createRequestImport = string.Format("https://domainname/webservice/rest/server.php?wstoken={0}&wsfunction={1}&moodlewsrestformat=json", token, "core_course_import_course");}}
{{ // Call Moodle REST Service}}
{{ HttpWebRequest reqImport = (HttpWebRequest)WebRequest.Create(createRequestImport);}}
{{ reqImport.Method = "POST";}}
{{ reqImport.ContentType = "application/x-www-form-urlencoded";}}
{{ // Encode the parameters as form data:}}
{{ byte[] formDataImport =}}
{{ UTF8Encoding.UTF8.GetBytes(postImportData);}}
{{ reqImport.ContentLength = formDataImport.Length;}}// Write out the form Data to the request:
{{ using (Stream postImport = reqImport.GetRequestStream())}}{ postImport.Write(formDataImport, 0, formDataImport.Length); }// Get the Response
{{ HttpWebResponse respImport = (HttpWebResponse)reqImport.GetResponse();}}
{{ Stream resStreamImport = respImport.GetResponseStream();}}
{{ StreamReader readerImport = new StreamReader(resStreamImport);}}
{{ string contentsImport = readerImport.ReadToEnd();}}
{{ // Deserialize}}
{{ JavaScriptSerializer serializerImport = new JavaScriptSerializer();}}
{{ if (contentsImport.Contains("exception"))}}{ // Error MoodleException moodleError = serializerImport.Deserialize<MoodleException>(contentsImport); lbl_results.Text = contentsImport; }
How can i fix this issue ?