# Memberships

A membership defines the kind of association between a class and a student or teacher

## Get Students in a Class

> This endpoint retrieves all students belonging to a class as specified by class ID.

```json
{"openapi":"3.0.3","info":{"title":"API V2","version":"v2"},"tags":[{"name":"Memberships","description":"A membership defines the kind of association between a class and a student or teacher"}],"servers":[{"url":"https://api.managebac.com","description":"The ManageBac API server."},{"url":"https://api.{server}","variables":{"server":{"default":"managebac.com","enum":["managebac.com","managebac.cn","us.managebac.com"]}}}],"security":[{"authTokenHeader":[]},{"authTokenQuery":[]}],"components":{"securitySchemes":{"authTokenHeader":{"type":"apiKey","name":"auth-token","in":"header","description":"Pass your V2 API authentication in the header for best security."},"authTokenQuery":{"type":"apiKey","name":"auth_token","in":"query","description":"Your V2 API authentication token may be passed as a query parameter. For best security, pass via headers instead."}}},"paths":{"/v2/classes/{class_id}/students":{"get":{"summary":"Get Students in a Class","operationId":"getStudentsForClass","tags":["Memberships"],"description":"This endpoint retrieves all students belonging to a class as specified by class ID.","parameters":[{"name":"class_id","in":"path","description":"Unique identifier for class.","required":true,"schema":{"type":"integer"}}],"responses":{"200":{"description":"Success","content":{"application/json":{}}}}}}}}
```

## Bulk Add or Update Students to a Class

> This endpoint updates students belonging to a class as specified by class ID.

```json
{"openapi":"3.0.3","info":{"title":"API V2","version":"v2"},"tags":[{"name":"Memberships","description":"A membership defines the kind of association between a class and a student or teacher"}],"servers":[{"url":"https://api.managebac.com","description":"The ManageBac API server."},{"url":"https://api.{server}","variables":{"server":{"default":"managebac.com","enum":["managebac.com","managebac.cn","us.managebac.com"]}}}],"security":[{"authTokenHeader":[]},{"authTokenQuery":[]}],"components":{"securitySchemes":{"authTokenHeader":{"type":"apiKey","name":"auth-token","in":"header","description":"Pass your V2 API authentication in the header for best security."},"authTokenQuery":{"type":"apiKey","name":"auth_token","in":"query","description":"Your V2 API authentication token may be passed as a query parameter. For best security, pass via headers instead."}},"schemas":{"BulkUpdateStudents":{"type":"object","required":["students"],"properties":{"students":{"type":"array","description":"An array of student IDs to add or update in the class.","items":{"type":"object","properties":{"id":{"type":"integer","description":"Student ID"},"level":{"type":"string","description":"Student level.","enum":["HL","SL"]}}}}}}}},"paths":{"/v2/classes/{class_id}/students":{"patch":{"summary":"Bulk Add or Update Students to a Class","operationId":"bulkUpdateStudentsFromClass","tags":["Memberships"],"description":"This endpoint updates students belonging to a class as specified by class ID.","parameters":[{"name":"class_id","in":"path","description":"Unique identifier for class.","required":true,"schema":{"type":"integer"}}],"responses":{"200":{"description":"Success","content":{"application/json":{}}}},"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/BulkUpdateStudents"}}}}}}}}
```

## Add Students to a Class

> This endpoint adds students, as specified by student ID/s, to a class as specified by class ID.

```json
{"openapi":"3.0.3","info":{"title":"API V2","version":"v2"},"tags":[{"name":"Memberships","description":"A membership defines the kind of association between a class and a student or teacher"}],"servers":[{"url":"https://api.managebac.com","description":"The ManageBac API server."},{"url":"https://api.{server}","variables":{"server":{"default":"managebac.com","enum":["managebac.com","managebac.cn","us.managebac.com"]}}}],"security":[{"authTokenHeader":[]},{"authTokenQuery":[]}],"components":{"securitySchemes":{"authTokenHeader":{"type":"apiKey","name":"auth-token","in":"header","description":"Pass your V2 API authentication in the header for best security."},"authTokenQuery":{"type":"apiKey","name":"auth_token","in":"query","description":"Your V2 API authentication token may be passed as a query parameter. For best security, pass via headers instead."}}},"paths":{"/v2/classes/{id}/add_students":{"post":{"summary":"Add Students to a Class","operationId":"addStudentsToClass","tags":["Memberships"],"description":"This endpoint adds students, as specified by student ID/s, to a class as specified by class ID.","parameters":[{"name":"id","in":"path","description":"Unique identifier for class.","required":true,"schema":{"type":"integer"}}],"responses":{"200":{"description":"Success","content":{"application/json":{}}}},"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"student_ids":{"description":"An array of student IDs to add to the class.","type":"array","items":{"type":"integer"}}},"required":["student_ids"]}}}}}}}}
```

## Remove Students from a Class

> This endpoint removes students from a class, as specified by student ID/s and class ID.\</p>

```json
{"openapi":"3.0.3","info":{"title":"API V2","version":"v2"},"tags":[{"name":"Memberships","description":"A membership defines the kind of association between a class and a student or teacher"}],"servers":[{"url":"https://api.managebac.com","description":"The ManageBac API server."},{"url":"https://api.{server}","variables":{"server":{"default":"managebac.com","enum":["managebac.com","managebac.cn","us.managebac.com"]}}}],"security":[{"authTokenHeader":[]},{"authTokenQuery":[]}],"components":{"securitySchemes":{"authTokenHeader":{"type":"apiKey","name":"auth-token","in":"header","description":"Pass your V2 API authentication in the header for best security."},"authTokenQuery":{"type":"apiKey","name":"auth_token","in":"query","description":"Your V2 API authentication token may be passed as a query parameter. For best security, pass via headers instead."}}},"paths":{"/v2/classes/{id}/remove_students":{"post":{"summary":"Remove Students from a Class","operationId":"removeStudentsFromClass","tags":["Memberships"],"description":"This endpoint removes students from a class, as specified by student ID/s and class ID.</p>","parameters":[{"name":"id","in":"path","description":"Unique identifier for class.","required":true,"schema":{"type":"integer"}}],"responses":{"200":{"description":"Success","content":{"application/json":{}}}},"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"student_ids":{"description":"An array of student IDs to remove from the class.","type":"array","items":{"type":"integer"}}},"required":["student_ids"]}}}}}}}}
```

## Get all Memberships

> This endpoint retrieves all members for each class (students, teachers and admin). It returns for each user the class ID, user ID, user role in the class and other details.

```json
{"openapi":"3.0.3","info":{"title":"API V2","version":"v2"},"tags":[{"name":"Memberships","description":"A membership defines the kind of association between a class and a student or teacher"}],"servers":[{"url":"https://api.managebac.com","description":"The ManageBac API server."},{"url":"https://api.{server}","variables":{"server":{"default":"managebac.com","enum":["managebac.com","managebac.cn","us.managebac.com"]}}}],"security":[{"authTokenHeader":[]},{"authTokenQuery":[]}],"components":{"securitySchemes":{"authTokenHeader":{"type":"apiKey","name":"auth-token","in":"header","description":"Pass your V2 API authentication in the header for best security."},"authTokenQuery":{"type":"apiKey","name":"auth_token","in":"query","description":"Your V2 API authentication token may be passed as a query parameter. For best security, pass via headers instead."}},"schemas":{"Membership":{"type":"object","properties":{"id":{"type":"integer","description":"Unique ID for membership in ManageBac."},"user_id":{"type":"integer","description":"Unique user ID in ManageBac."},"level":{"type":"integer","description":"Class level; 0 is standard-level, 1 is higher-level.","enum":[0,1]},"created_at":{"type":"string","description":"Created date; yyyy-mm-dd."},"updated_at":{"type":"string","description":"Updated date; yyyy-mm-dd."},"class_id":{"type":"integer","description":"Unique class ID in ManageBac."},"user_email":{"type":"string","description":"User email"},"uniq_class_id":{"type":"string","description":"Unique ID in class."},"uniq_student_id":{"type":"string","description":"School’s own unique ID."},"role":{"type":"string","description":"User role."}}},"Meta":{"type":"object","properties":{"current_page":{"type":"integer","description":"Current page."},"total_pages":{"type":"integer","description":"How many pages."},"total_count":{"type":"integer","description":"How many items."},"per_page":{"type":"integer","description":"How many items on page."}}}}},"paths":{"/v2/memberships":{"get":{"summary":"Get all Memberships","operationId":"listMemberships","tags":["Memberships"],"description":"This endpoint retrieves all members for each class (students, teachers and admin). It returns for each user the class ID, user ID, user role in the class and other details.","parameters":[{"name":"class_ids[]","in":"query","required":false,"allowReserved":true,"style":"form","explode":true,"schema":{"type":"array","items":{"type":"integer"}},"description":"The list of class IDs to select membership for"},{"name":"modified_since","in":"query","description":"A timestamp to filter the modification date of results.","required":false,"schema":{"type":"string"}},{"name":"deleted_since","in":"query","description":"A timestamp to filter the deletion date of results.","required":false,"schema":{"type":"string"}},{"name":"page","in":"query","description":"An integer defining which page to display.","required":false,"schema":{"type":"string"}},{"name":"per_page","in":"query","description":"An integer defining the number of records to display per page.","required":false,"schema":{"type":"string"}},{"name":"user_ids[]","in":"query","description":"An integer list of users ids to filter by.","required":false,"schema":{"type":"array","items":{"type":"integer"}},"style":"form","explode":true},{"name":"user_ids","in":"query","description":"An integer list of users ids to filter by.","required":false,"schema":{"type":"array","items":{"type":"integer"}},"style":"form","explode":false},{"name":"class_happens_on","in":"query","description":"A date param to filter by start term and end term date range.","required":false,"schema":{"type":"string","format":"date"}}],"responses":{"200":{"description":"successful","content":{"application/json":{"schema":{"type":"object","properties":{"memberships":{"type":"array","items":{"$ref":"#/components/schemas/Membership"}},"meta":{"$ref":"#/components/schemas/Meta"}}}}}}}}}}}
```

## Get a Student's memberships

> This endpoint retrieves details of all student memberships.

```json
{"openapi":"3.0.3","info":{"title":"API V2","version":"v2"},"tags":[{"name":"Memberships","description":"A membership defines the kind of association between a class and a student or teacher"}],"servers":[{"url":"https://api.managebac.com","description":"The ManageBac API server."},{"url":"https://api.{server}","variables":{"server":{"default":"managebac.com","enum":["managebac.com","managebac.cn","us.managebac.com"]}}}],"security":[{"authTokenHeader":[]},{"authTokenQuery":[]}],"components":{"securitySchemes":{"authTokenHeader":{"type":"apiKey","name":"auth-token","in":"header","description":"Pass your V2 API authentication in the header for best security."},"authTokenQuery":{"type":"apiKey","name":"auth_token","in":"query","description":"Your V2 API authentication token may be passed as a query parameter. For best security, pass via headers instead."}}},"paths":{"/v2/students/{id}/memberships":{"get":{"summary":"Get a Student's memberships","operationId":"getStudentMemberships","tags":["Memberships"],"description":"This endpoint retrieves details of all student memberships.","parameters":[{"name":"id","in":"path","description":"Unique identifier of a student.","schema":{"type":"integer"},"required":true},{"name":"archived","in":"query","description":"Boolean value to filter memberships by archived status.","schema":{"type":"boolean","default":false}}],"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"type":"object","properties":{"memberships":{"type":"object","properties":{"classes":{"type":"array","items":{"allOf":[{"type":"object","properties":{"id":{"type":"integer"},"uniq_id":{"type":"string"},"name":{"type":"string"},"archived":{"type":"boolean"},"start_term_id":{"type":"integer"},"end_term_id":{"type":"integer"}}}]}},"groups":{"type":"array","items":{"allOf":[{"type":"object","properties":{"id":{"type":"integer"},"name":{"type":"string"},"archived":{"type":"boolean"}}}]}},"year_groups":{"type":"array","items":{"allOf":[{"type":"object","properties":{"id":{"type":"integer"},"name":{"type":"string"},"program":{"type":"string"},"archived":{"type":"boolean"}}}]}}}}}}}}}}}}}}
```

## Get Teachers for a Class

> This endpoint retrieves all Teachers belonging to a Class as specified by class ID.

```json
{"openapi":"3.0.3","info":{"title":"API V2","version":"v2"},"tags":[{"name":"Memberships","description":"A membership defines the kind of association between a class and a student or teacher"}],"servers":[{"url":"https://api.managebac.com","description":"The ManageBac API server."},{"url":"https://api.{server}","variables":{"server":{"default":"managebac.com","enum":["managebac.com","managebac.cn","us.managebac.com"]}}}],"security":[{"authTokenHeader":[]},{"authTokenQuery":[]}],"components":{"securitySchemes":{"authTokenHeader":{"type":"apiKey","name":"auth-token","in":"header","description":"Pass your V2 API authentication in the header for best security."},"authTokenQuery":{"type":"apiKey","name":"auth_token","in":"query","description":"Your V2 API authentication token may be passed as a query parameter. For best security, pass via headers instead."}}},"paths":{"/v2/classes/{class_id}/teachers":{"get":{"summary":"Get Teachers for a Class","operationId":"getTeacherMemberships","tags":["Memberships"],"description":"This endpoint retrieves all Teachers belonging to a Class as specified by class ID.","parameters":[{"name":"class_id","in":"path","description":"Unique identifier for class.","required":true,"schema":{"type":"integer"}}],"responses":{"200":{"description":"Success","content":{"application/json":{}}}}}}}}
```

## Set Teacher Memberships for a Class

> Completely replaces the given class's teacher memberships according to the provided payload. Specifying a payload of an empty array \[] will remove all teachers. In addition to defining memberships, also enables or disables Show on Reports.

```json
{"openapi":"3.0.3","info":{"title":"API V2","version":"v2"},"tags":[{"name":"Memberships","description":"A membership defines the kind of association between a class and a student or teacher"}],"servers":[{"url":"https://api.managebac.com","description":"The ManageBac API server."},{"url":"https://api.{server}","variables":{"server":{"default":"managebac.com","enum":["managebac.com","managebac.cn","us.managebac.com"]}}}],"security":[{"authTokenHeader":[]},{"authTokenQuery":[]}],"components":{"securitySchemes":{"authTokenHeader":{"type":"apiKey","name":"auth-token","in":"header","description":"Pass your V2 API authentication in the header for best security."},"authTokenQuery":{"type":"apiKey","name":"auth_token","in":"query","description":"Your V2 API authentication token may be passed as a query parameter. For best security, pass via headers instead."}},"schemas":{"BulkUpdateTeachers":{"type":"object","required":["teachers"],"properties":{"teachers":{"type":"array","description":"An array of teacher IDs to add or update in the class.","items":{"type":"object","properties":{"id":{"type":"integer","description":"Teacher ID"},"show_on_reports":{"type":"boolean","description":"Show Teacher on Reports"}}}}}}}},"paths":{"/v2/classes/{class_id}/teachers":{"put":{"summary":"Set Teacher Memberships for a Class","operationId":"bulkUpdateTeacherMemberships","tags":["Memberships"],"description":"Completely replaces the given class's teacher memberships according to the provided payload. Specifying a payload of an empty array [] will remove all teachers. In addition to defining memberships, also enables or disables Show on Reports.","parameters":[{"name":"class_id","in":"path","description":"Unique identifier for class.","required":true,"schema":{"type":"integer"}}],"responses":{"200":{"description":"Success","content":{"application/json":{}}},"400":{"description":"Bad Request","content":{"application/json":{}}}},"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/BulkUpdateTeachers"}}}}}}}}
```

## Remove Teachers from a Class

> This endpoint removes teachers, as specified by teacher ID/s, from a class as specified by class ID.

```json
{"openapi":"3.0.3","info":{"title":"API V2","version":"v2"},"tags":[{"name":"Memberships","description":"A membership defines the kind of association between a class and a student or teacher"}],"servers":[{"url":"https://api.managebac.com","description":"The ManageBac API server."},{"url":"https://api.{server}","variables":{"server":{"default":"managebac.com","enum":["managebac.com","managebac.cn","us.managebac.com"]}}}],"security":[{"authTokenHeader":[]},{"authTokenQuery":[]}],"components":{"securitySchemes":{"authTokenHeader":{"type":"apiKey","name":"auth-token","in":"header","description":"Pass your V2 API authentication in the header for best security."},"authTokenQuery":{"type":"apiKey","name":"auth_token","in":"query","description":"Your V2 API authentication token may be passed as a query parameter. For best security, pass via headers instead."}}},"paths":{"/v2/classes/{class_id}/teachers/remove_teachers":{"delete":{"summary":"Remove Teachers from a Class","operationId":"removeTeachersFromClass","tags":["Memberships"],"description":"This endpoint removes teachers, as specified by teacher ID/s, from a class as specified by class ID.","parameters":[{"name":"class_id","in":"path","description":"Unique identifier for class.","required":true,"schema":{"type":"integer"}}],"responses":{"200":{"description":"Success","content":{"application/json":{}}}},"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"teacher_ids":{"description":"An array of teacher IDs to remove from the class.","type":"array","items":{"type":"integer"}}},"required":["teacher_ids"]}}}}}}}}
```
