---
title: "Create a resource for a Copilot Space for a user"
method: POST
path: "/users/{username}/copilot-spaces/{space_number}/resources"
tags: ["copilot-spaces"]
---

# Create a resource for a Copilot Space for a user

`POST /users/{username}/copilot-spaces/{space_number}/resources`

Creates a new resource in a specific Copilot Space owned by a user.
The authenticated user must have write permissions on the space.

The following resource types are supported: `repository`, `github_file`, `free_text`, `github_issue`, `github_pull_request`.
The `uploaded_text_file` and `media_content` types are not supported via this endpoint.

For `github_file` resources, if a resource with the same repository, file path, and SHA already exists, the existing resource is returned with a `200` status.

OAuth app tokens and personal access tokens (classic) need the `write:user` scope to use this endpoint.

## Path parameters

- `username` string, required
- `space_number` integer, required

## Request body

- object
  - `resource_type` 'repository' | 'github_file' | 'free_text' | 'github_issue' | 'github_pull_request', required — The type of resource to create.
  - `metadata` object, required — Resource-specific metadata.

## Response `200`

Duplicate github_file resource already exists

- CopilotSpaceResource — A resource attached to a Copilot Space.
  - `id` integer, required — The unique identifier of the resource.
  - `resource_type` 'repository' | 'github_file' | 'free_text' | 'github_issue' | 'github_pull_request' | 'media_content' | 'uploaded_text_file', required — The type of the resource.
  - `copilot_chat_attachment_id` integer, nullable — The ID of the associated chat attachment, if any.
  - `metadata` object, required — Resource-specific metadata. The keys and values depend on the resource type.
  - `created_at` string, date-time, required — The date and time the resource was created.
  - `updated_at` string, date-time, required — The date and time the resource was last updated.

## Other responses

- `201` — Resource created
- `403` — Forbidden
- `404` — Resource not found
- `422` — Validation failed, or the endpoint has been spammed.

---

[API](https://skmtc.net/github/apis/github-v3-rest-api-3.md) · [All operations](https://skmtc.net/github/apis/github-v3-rest-api-3/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/github/github-v3-rest-api-3/versions/dc0584ac4e13/schema)
