Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
240 changes: 112 additions & 128 deletions pages/organizations-and-projects/api-cli/managing-projects.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,137 +13,121 @@ This page explains how to manage Projects using [Scaleway APIs](https://www.scal

<Requirements />

- A Scaleway account logged into the [console](https://console.scaleway.com)
- [Configured your API keys](/iam/how-to/create-api-keys/)
- An API key with the [`IAMManager` or `ProjectManager` permission sets](/iam/reference-content/permission-sets/)

## Creating a Project

You need your secret key and your Organization ID for the step below.

Open a terminal and type the following command to create a Project. If you have not configured your environment in your local machine, make sure you replace `$SCW_SECRET_KEY` with your secret key and `$SCW_DEFAULT_ORGANIZATION_ID` with the ID of your Organization.
```
curl -XPOST https://api.scaleway.com/account/v2/projects -H 'X-Auth-Token: $SCW_SECRET_KEY' -d '{"organization_id":"$SCW_DEFAULT_ORGANIZATION_ID","name":"name-of-project"}'
```
An output similar to the following displays:
```
{
"id":"6170692e-7363-616c-6577-61792e636f6d",
"name":"test-project",
"organization_id":"3e44a89e-1f75-45f5-9b93-422db94165eb",
"created_at":"2022-07-19T15:02:43.455727Z",
"updated_at":"2022-07-19T15:02:43.455727Z",
"description":""
}
```

## Updating Projects

You need your secret key and the ID of the Project you want to update for the step below. For this use case, we are updating the Project created in the step above.
<Message type="note">
You can only update the name and description of your Project.
</Message>
Type the following command into your terminal to update your Project:
```
curl -XPATCH https://api.scaleway.com/account/v2/projects/<SCW_PROJECT_ID> -H 'X-Auth-Token: $SCW_SECRET_KEY' -d '{"name":"new-project", "description": "This is my updated project" }'
```
An output similar to the following displays:
```
{
"id":"6170692e-7363-616c-6577-61792e636f6d",
"name":"new-project",
"organization_id":"3e44a89e-1f75-45f5-9b93-422db94165eb",
"created_at":"2022-07-19T15:02:43.455727Z",
"updated_at":"2022-07-19T15:29:27.762100Z",
"description":"This is my updated project"
}
```

## Listing all your Projects

<Message type="note">
- There is a default Project in all Organizations.
- The default Project's Project ID is the same as the Organization ID.
- The default Project cannot be deleted.
</Message>

You need your secret key and your Organization ID for the step below.

Type the following command into your terminal to list your Projects:
```
curl -XGET https://api.scaleway.com/account/v2/projects\?organization_id\=<SCW_DEFAULT_ORGANIZATION_ID>&page=1&page_size=10&order_by=created_at_asc -H 'X-Auth-Token: $SCW_SECRET_KEY'
```
An output similar to the following displays:
```
{
"total_count":2,
"projects":[
{
"id":"3e44a89e-1f75-45f5-9b93-422db94165eb",
"name":"default",
"organization_id":"3e44a89e-1f75-45f5-9b93-422db94165eb",
"created_at":"2021-07-06T15:15:48.375181Z",
"updated_at":"2021-07-06T15:15:48.375181Z",
"description":""
},
{
"id":"6170692e-7363-616c-6577-61792e636f6d",
"name":"new-project",
"organization_id":"3e44a89e-1f75-45f5-9b93-422db94165eb",
"created_at":"2022-07-19T15:02:43.455727Z",
"updated_at":"2022-07-19T15:29:27.762100Z",
"description":"This is my updated project"
}
]
}
```

## Retrieving a specific Project

You need your secret key and the ID of the Project you want to get for the step below. For this use case, we are getting the Project we have updated in the [updating Projects step](/organizations-and-projects/api-cli/managing-projects/#updating-projects).

Type the following command to list a specific Project.
```
curl -XGET https://api.scaleway.com/account/v2/projects/<SCW_PROJECT_ID> -H 'X-Auth-Token: $SCW_SECRET_KEY'
```
An output similar to the following displays:
```
{
"id":"6170692e-7363-616c-6577-61792e636f6d",
"name":"new-project",
"organization_id":"3e44a89e-1f75-45f5-9b93-422db94165eb",
"created_at":"2022-07-19T15:02:43.455727Z",
"updated_at":"2022-07-19T15:29:27.762100Z",
"description":"This is my updated project"
}
```

## Deleting a Project

You need your secret key and the ID of the Project you want to delete for the step below. For this use case, we are deleting the Project we have created in the [creating a Project step](/organizations-and-projects/api-cli/managing-projects/#creating-a-project).

1. Type the following command to delete a Project.
- A [Scaleway account](https://console.scaleway.com/) and you know your Organization ID
- An [API key](https://www.scaleway.com/en/docs/iam/how-to/create-api-keys/) and that the API key has sufficient [IAM permissions](https://www.scaleway.com/en/docs/iam/reference-content/permission-sets/) to perform the actions described on this page
- Your [Organization ID](https://console.scaleway.com/organization/settings)
- [Installed `curl`](https://curl.se/download.html)

1. Configure your environment variables.

<Message type="note">
This is an optional step that seeks to simplify your usage of the APIs.
</Message>

```bash
export SCW_SECRET_KEY="<API secret key>"
```

2. Edit the **POST** request payload you will use to create a Project.

Replace the parameters in the following example:

```json
'{
"name": "project-name",
"organization_id": "b12d5c3g-c612-5674-c1e9-92627f36c5b9",
"description": "This is the description of my Project",
}'
```
curl -XDELETE https://api.scaleway.com/account/v2/projects/<YOUR_PROJECT_ID> -H 'X-Auth-Token: $SCW_SECRET_KEY'

| Parameter | Description |
| :---------------- | :------------------------------------------------- |
| `name` | Name for the Project you want to create. |
| `organization_id` | ID of the Organization in which to create the Project. It must be in UUID format. |
| `description` | Description for the Project you want to create. |

3. Run the following command to create a Project:

Make sure you include the payload you edited in the previous step.

```bash
curl -X POST \
-H "X-Auth-Token: $SCW_SECRET_KEY" \
-H "Content-Type: application/json" \
"https://api.scaleway.com/account/v3/projects" \
-d '{
"name": "Dis-Iz-My-Projekt",
"organization_id": "b12d5c3g-c612-5674-c1e9-92627f36c5b9",
"type": "This is the description of my Project"
}'
```
2. Run the following command to list your Projects and make sure you have deleted your Project.

You should get a response like the following:

<Message type="note">
This is a response example, the UUIDs displayed are not real.
</Message>

```bash
{
"id": "6170692e-7363-616c-6577-61792e636f6d",
"name": "Dis-Iz-My-Projekt",
"organization_id": "b12d5c3g-c612-5674-c1e9-92627f36c5b9",
"created_at": "2023-03-02T22:00:28.888380Z",
"updated_at": "2023-03-02T22:00:28.888380Z",
"description": "This is the description of my project"
}
```
curl -XGET https://api.scaleway.com/account/v2/projects\?organization_id\=<SCW_DEFAULT_ORGANIZATION_ID> -H "X-Auth-Token: $SCW_SECRET_KEY"

4. Run the following command to list your Projects. Replace the Organization ID in the endpoint with your own Organization ID.

```bash
curl -X GET \
-H "X-Auth-Token: $SCW_SECRET_KEY" \
-H "Content-Type: application/json" \
"https://api.scaleway.com/account/v3/projects?organization_id=b12d5c3g-c612-5674-c1e9-92627f36c5b9"
```

An output similar to the following displays, confirming that you have one Project left:
```
{
"total_count": 1,
"projects": [
{
"id":"3e44a89e-1f75-45f5-9b93-422db94165eb",
"name":"default",
"organization_id":"3e44a89e-1f75-45f5-9b93-422db94165eb",
"created_at":"2021-07-06T15:15:48.375181Z",
"updated_at":"2021-07-06T15:15:48.375181Z",
"description":""
}
You should get a response like the following:

```bash
{
"total_count": "2",
"projects": [
{
"id": "0fe11800-ddbb-4b62-8906-ed08780cdddb",
"name": "default",
"organization_id": "b12d5c3g-c612-5674-c1e9-92627f36c5b9",
"created_at": "2022-08-31T07:45:53.657735Z",
"updated_at": "2022-08-31T07:45:53.657735Z",
"description": "cannot_be_deleted"
},
{
"id":"6170692e-7363-616c-6577-61792e636f6d",
"name":"Dis-Iz-My-Projekt",
"organization_id":"b12d5c3g-c612-5674-c1e9-92627f36c5b9",
"created_at":"2023-03-02T22:00:28.888380Z",
"updated_at":"2023-03-02T22:00:28.888380Z",
"description":"This is the description of my Project"
},
]
}
```
}
```

5. Run the following command to update a Project's name and description.
<Message type="note">
Do not forget to replace the Project ID in the endpoint, and the Organization ID in the payload, with your own. You can retrieve the Project ID from the "List Project" response above.
</Message>

```bash
curl -X PATCH \
-H "X-Auth-Token: $SCW_SECRET_KEY" \
-H "Content-Type: application/json" \
"https://api.scaleway.com/account/v3/projects/6170692e-7363-616c-6577-61792e636f6d" \
-d '{
"name": "Dis-Iz-My-Updated-Projekt",
"organization_id": "b12d5c3g-c612-5674-c1e9-92627f36c5b9",
"description": "This is the updated description of my Project"
}'
```