Projects

Learn and practice the functionalities of projects in GitHub API.

Overview

Github allows projects for planning and managing work. Projects are customizable spreadsheets integrated with pull requests or issues. Whenever a change is made to the pull request or an issue, the project is automatically updated. We can also focus on specific aspects of our project by sorting, grouping, or filtering pull requests or issues. In addition to this, we can add custom fields for tracking metadata like complexity and priority.

Create a repository project

First, we'll look into how we can create a project in the specified repository. The name of the project to be created is provided as the API parameter.

Let's specify the project name in the place of <project-name>. We can see this in line 7 in the code below. Run the code to create a repository project.

Press + to interact
headers = {
'Authorization': 'token {{ACCESS_TOKEN}}',
'Accept': 'application/vnd.github.v3+json'
}
data = json.dumps({
'name': '<project-name>'
})
url='https://api.github.com/repos/{{USERNAME}}/{{REPOSITORY}}/projects'
response = requests.post(url, headers=headers, data=data)
print(json.dumps(response.json(), indent=4))

List repository projects

Next, we'll look into listing all the projects in a repository of a user by using the HTTP GET request method.

Press + to interact
headers = {
'Authorization': 'token {{ACCESS_TOKEN}}',
'Accept': 'application/vnd.github.v3+json'
}
url='https://api.github.com/repos/{{USERNAME}}/{{REPOSITORY}}/projects'
response = requests.get(url, headers=headers)
print(json.dumps(response.json(), indent=4))

Create user project

This endpoint creates a user project board. The name of the project is provided as the API parameter.

Specify the project name in the place of <project-name>. We can see this in line 7 in the code below. Run the code to create a user project.

Press + to interact
headers = {
'Authorization': 'token {{ACCESS_TOKEN}}',
'Accept': 'application/vnd.github.v3+json'
}
data = json.dumps({
'name': '<project-name>'
})
url='https://api.github.com/user/projects'
response = requests.post(url, headers=headers, data=data)
print(json.dumps(response.json(), indent=4))

List user projects

Now that we’ve created a user project, let’s list the user projects and see whether our project exists. Don't forget to specify the user’s username in the place of <username>. We can find this in line 6.

Press + to interact
headers = {
'Authorization': 'token {{ACCESS_TOKEN}}',
'Accept': 'application/vnd.github.v3+json'
}
url = 'https://api.github.com/users/<username>/projects'
response = requests.get(url, headers=headers)
print(json.dumps(response.json(), indent=4))