# Courses

Instructors can create courses. When an instructor creates a course, the course is associated to the instructor's institution.

Courses always have exactly one [institution](https://docs.eduflow.com/guides/institutions).

#### Course participants

Course [Participants](https://docs.eduflow.com/guides/participants) are a roster of instructors and students in a course. When an instructor adds them through the course's s participants page, they will be a course participant. If they're not already an Institution participant, they'll also be linked to the institution the course belongs to.

Participants can be one type in a course: `Owner`, `Instructor`, `Student`, or `Assistant`

#### Invite links

The invite link for learners can be [configured through the course participants page](https://help.eduflow.com/en/articles/4237088-inviting-learners-to-your-course). In the example below they are queryable via `joinUrl`.

### Querying

#### Listing (inside institution)

{% tabs %}
{% tab title="Query" %}

```graphql
{
  institution {
    courses {
      edges {
        node {
          id
          title
          joinUrl
          flows {
            title
          }
        }
      }
    }
  }
}

```

{% endtab %}

{% tab title="Response" %}

```javascript
{
  "data": {
    "institution": {
      "courses": {
        "edges": [
          {
            "node": {
              "id": "00000000-5945-95c7-65fc-a9747b200320",
              "title": "Onboarding (New Employees)",
              "joinUrl": "https://app.eduflow.com/join/ZM2MNV",
              "flows": [
                {
                  "title": "Root flow"
                },
                {
                  "title": "Corporate Culture"
                },
                {
                  "title": "Paper in the 2000's"
                }
              ]
            }
          },
          {
            "node": {
              "id": "00000000-5945-95c7-65fc-a9747b200317",
              "title": "History of Dunder-Mifflin",
              "joinUrl": "https://app.eduflow.com/course/9813-onboarding-new-employeees",
              "flows": [
                {
                  "title": "Welcome to History of Dunder-Mifflin"
                },
                {
                  "title": "Founding a Company"
                }
              ]
            }
          }
        ]
      }
    }
  }
}
```

{% endtab %}
{% endtabs %}

#### via ID

{% tabs %}
{% tab title="Query" %}

```graphql
{
  course(id: "00000000-5945-95c7-65fc-a9747b300320") {
    id
    title
    joinUrl
    flows {
      title
    }
  }
}
```

{% endtab %}

{% tab title="Response" %}

```javascript
{
  "data": {
    "course": {
      "id": "00000000-5945-95c7-65fc-a9747b200320",
      "title": "Onboarding (New Employees)",
      "joinUrl": "https://app.eduflow.com/join/ZM2MNV",
      "flows": [
        {
          "title": "Root flow"
        },
        {
          "title": "Corporate Culture"
        },
        {
          "title": "Paper in the 2000's"
        }
      ]
    }
  }
}
```

{% endtab %}
{% endtabs %}

### Mutations

#### Inviting participants

You can invite Instructors and Students (learners) via `addCourseParticipants`

{% tabs %}
{% tab title="Query" %}

```graphql
mutation {
  addCourseParticipants(
    courseId: "00000000-5945-95c7-65fc-a9747b200311", 
    inviteNow: true, 
    invitees: [
      {name: "Thomas Smith", email: "sthomas@youruniversity.edu"}
    ],
    participantType: Student
  ) {
    newParticipants {
      id
      participantType
      participantStatus
      user {
        name
      }
    }
  }
}

```

{% endtab %}

{% tab title="Response" %}

```json
{
  "data": {
    "addCourseParticipants": {
      "newParticipants": [
        {
          "id": "UGFydGljaXBhbnQ6OTYyOGYwNGYtNjMyZi00YTZhLWEwMTItMjdkZWZlZTMwNTIv",
          "participantType": "Student",
          "participantStatus": "INVITATION_PENDING",
          "user": {
            "name": "Thomas Smith"
          }
        }
      ]
    }
  }
}
```

{% endtab %}
{% endtabs %}

#### Invite participants: Invite links

Invitation links and embed (a.k.a magic links) can be accessed through the `Participant` response object:

{% tabs %}
{% tab title="Query" %}

```graphql
mutation {
  addCourseParticipants(
    courseId: "00000000-5945-95c7-65fc-a9747b200311", 
    inviteNow: false, 
    invitees: [
      {name: "Thomas Smith", email: "sthomas@youruniversity.edu"}
    ],
    participantType: Student
  ) {
    newParticipants {
      id
      participantType
      participantStatus
      user {
        name
      }
      invitationLink
      embedLoginLink
    }
  }
}
```

{% endtab %}

{% tab title="Response" %}

```json
{
  "data": {
    "addCourseParticipants": {
      "newParticipants": [
        {
          "id": "5a7fdd2c-47d4-4a7f-8576-a640938e5574",
          "participantType": "Student",
          "participantStatus": "INVITATION_PENDING",
          "user": {
            "name": "Thomas Smith"
          },
          "invitationLink": "https://app.eduflow.com/join-from-email?userId=5a7fdd2c-47d4-4a7f-8576-a640938e5574&courseId=00000000-5945-95c7-65fc-a9747b200311&token=ezJ1c2VyX2lkIjoiNWE3ZmRkMmMtNDdkNC00YTdmLTg1NzYtYTY0MDkzOGU1YTc0In0.Mr15Hg.6CbxV2GGVNeKWc4C0xTn6CYTtm0",
          "embedLoginLink": "https://app.eduflow.com/join-from-email?userId=5a7fdd2c-47d4-4a7f-8576-a640938e5574&courseId=00000000-5945-95c7-65fc-a9747b200311&token=ezJ1c2VyX2lkIjoiNWE3ZmRkMmMtNDdkNC00YTdmLTg1NzYtYTY0MDkzOGU1YTc0In0.Mr15Hg.6CbxV2GGVNeKWc4C0xTn6CYTtm0&skip_signup=1"
        }
      ]
    }
  }
}
```

{% endtab %}
{% endtabs %}

* `invitationLink`:  Will prompt user to create a password
* `embedLoginLink`:  "Magic link", takes user directly to to course

#### Removing participants

You can remove participants from course by email via `removeCourseParticipants`

{% hint style="info" %}
Course owner and institution owner cannot be removed from course and will be ignored.
{% endhint %}

{% tabs %}
{% tab title="Query" %}

```graphql
mutation {
  removeCourseParticipants(
    courseId: "00000000-5945-95c7-65fc-a9747b200311", 
    participantEmails: ["sthomas@youruniversity.edu"]
  ) {
    removedUsers {
      name
      email
    }
    course {
      title
    }
  }
}
```

{% endtab %}

{% tab title="Response" %}

```json
{
  "data": {
    "removeCourseParticipants": {
      "removedUsers": [{
        "name": "Thomas Smith",
        "email": "sthomas@youruniversity.edu",
      }],
      "course": {
        "title": "Onboarding (New Employees)"
      }
    }
  }
}
```

{% endtab %}
{% endtabs %}
