> For the complete documentation index, see [llms.txt](https://docs.stellic.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.stellic.com/stellic-partner-api/student/link-a-student-to-a-department.md).

# Link a student to a department

Use this endpoint to add one department to a student without sending their whole profile. `{dept_id}` is the department's short name, matched exactly. A student can belong to several departments, and linking one that's already linked returns 200 with no change. Linking a department doesn't link its school. The response is the student's profile, with their schools and departments.

## POST /student/{student\_username}/department/{dept\_id}

>

```json
{"openapi":"3.0.0","info":{"title":"Stellic for Developers","version":"1.0"},"tags":[{"name":"Student"}],"servers":[{"url":"https://{institution}.stellic.com/partnerapi/v1","variables":{"institution":{"default":"{institution}","description":"Your institution's Stellic subdomain: the part before `.stellic.com` in the URL you use to sign in. It becomes the host in every request, as in `https://{institution}.stellic.com/partnerapi/v1/...`. Replace the `{institution}` placeholder with your subdomain before sending."}}}],"security":[{"bearerAuth":[]}],"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","description":"Personal Access Token issued by your Stellic integration partner. Send it as `Authorization: Bearer <token>` on every request. One token per institution; do not share across environments."}},"schemas":{"StudentLinkResponseSuccess":{"type":"object","properties":{"status":{"type":"string"},"state":{"type":"object","properties":{"username":{"type":"string"},"first_name":{"type":"string"},"last_name":{"type":"string"},"photo_url":{"type":"string","nullable":true},"level":{"type":"integer"},"year_begin":{"type":"integer"},"campus":{"type":"string","nullable":true,"description":"The student's primary campus name, or `null` if no campus is set."},"schools":{"type":"array","items":{"type":"object","properties":{"campus":{"type":"object","nullable":true,"description":"The campus the school belongs to, or `null` if the school has no campus.","properties":{"id":{"type":"integer"},"name":{"type":"string"},"screen_name":{"type":"string"}}},"name":{"type":"string"},"short_name":{"type":"string"}}}},"departments":{"type":"array","description":"The student's departments. Each one carries its name and code but not its short name.","items":{"type":"object","properties":{"name":{"type":"string"},"code":{"type":"string","nullable":true,"description":"The department's first registered code, or `null` if the department has no codes."},"school":{"type":"object","properties":{"campus":{"type":"object","nullable":true,"description":"The campus the parent school belongs to, or `null` if the school has no campus.","properties":{"id":{"type":"integer"},"name":{"type":"string"},"screen_name":{"type":"string"}}},"name":{"type":"string"},"short_name":{"type":"string"}}}}}}}}}},"StudentLinkResponseFailure":{"allOf":[{"$ref":"#/components/schemas/GenericResponseFailure"},{"type":"object","properties":{"identifiers":{"type":"object","properties":{"student_username":{"type":"string"}}}}}]},"GenericResponseFailure":{"type":"object","properties":{"status":{"type":"string"},"message":{"type":"string"}}}}},"paths":{"/student/{student_username}/department/{dept_id}":{"post":{"tags":["Student"],"parameters":[{"name":"student_username","in":"path","required":true,"description":"The student's username, matched exactly (not lowercased). Archived students and test accounts return `400`.","schema":{"type":"string"}},{"name":"dept_id","in":"path","required":true,"description":"The department's short name, matched exactly (case- and whitespace-sensitive). Unknown and deleted departments return `400`.","schema":{"type":"string"}}],"responses":{"200":{"description":"Department linked, or was already linked (no change). Linking a department doesn't link its school. Each school in `state.schools` appears once, even if linked for multiple terms.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/StudentLinkResponseSuccess"}}}},"400":{"description":"Validation failure on the student or the department.\n\nCommon causes:\n- Student not found - returns `No student exists with username: {student_username}`\n- Student is archived and isn't a test account - returns `Student with username {student_username} is archived`\n- Student is a test account, including an archived test account - returns the same `No student exists with username: {student_username}` as a missing user. Some students converted to staff are marked as test accounts, depending on how Stellic has set up your institution.\n- No department, or only a deleted one, has this short name - returns `No department exists with short_name: {dept_id}`","content":{"application/json":{"schema":{"allOf":[{"$ref":"#/components/schemas/StudentLinkResponseFailure"},{"type":"object","properties":{"identifiers":{"type":"object","properties":{"student_username":{"type":"string"},"dept_id":{"type":"string"}}}}}]}}}},"401":{"description":"Missing or invalid Bearer token."},"403":{"description":"Your IP address isn't on the allowlist for this endpoint. Contact Stellic to add it; the response includes the `client_ip` Stellic saw.","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"},"message":{"type":"string"},"client_ip":{"type":"string"}}}}}},"500":{"description":"Unhandled error while saving the link change; the change wasn't saved. Body is `{\"identifiers\": {...}, \"errors\": [{\"message\": \"Stellic couldn't process your request\"}]}`, with no `status` key (unlike the school endpoints) and `errors[]` in place of `message`."}}}}}}
```

#### What happens after the call

* The department is linked and a search refresh is attempted during the call. A failed refresh doesn't undo the link or fail the call.
* General requirements and pathways aren't recalculated. If they apply by department, send `department_ids` with [`PUT /student/{student_username}/profile/`](/stellic-partner-api/student/upsert-a-student-profile.md) instead.

#### Notes

* **Advisor access doesn't depend on this link.** Access by department comes from the departments of the student's programs.
* **The first department linked is the student's primary department.**
* **Your data sync can change departments linked here.** If your data sync sends student departments, the next run replaces them.
* **Usernames must match exactly** and aren't lowercased. Archived students who aren't test accounts return `Student with username {student_username} is archived`.

#### Related APIs

* [`DELETE /student/{student_username}/department/{dept_id}`](/stellic-partner-api/student/unlink-a-student-from-a-department.md) to unlink the department.
* [`POST /student/{student_username}/school/{school_id}`](/stellic-partner-api/student/link-a-student-to-a-school.md) to link the department's school.
