Home > database >  Classroom.Courses.Students.create returns error
Classroom.Courses.Students.create returns error

Time:10-07

I'm writing a script to enroll all my students (2,000) each one in his own classroom. referring to the Method page I wrote a simple sentence like this:

Classroom.Courses.Students.create({
    "courseId": "9898688798",
    "profile": {
      "name": {
        "familyName": "Xxxxxx",
        "givenName": "Yyyy"
      },
      "emailAddress": "[email protected]"
    }
  });

but I receive this error: Exception: Invalid number of arguments provided. Expected 2-3 only

Where did I make a mistake?

CodePudding user response:

Issue:

As the error you are getting says, this method requires two or three parameters, and you're only providing one.

Solution:

If you start typing the method you'll see a popup displaying the required parameters for this method:

  • resource: referring to the student resource, which is the request body that has to be provided for the API method.
  • courseId: the identifier of the course to create the student in, which is the path parameter for the API method.
  • optionalArgs: [OPTIONAL] referring to any additional parameters you'd want to add, like enrollmentCode.

Also, for the first parameter, resource, three of the four fields from the student resource are read-only, so you only have to provide the userId, which can be one of the following:

  • the numeric identifier for the user
  • the email address of the user
  • the string literal "me", indicating the requesting user

Code snippet:

So in your example, you could do this:

const resource = {
  "userId": "[email protected]"
}
const courseId = "9898688798";
Classroom.Courses.Students.create(resource, courseId);
  • Related