# Quickstart

This walkthrough covers the whole lifecycle with `curl` and [`jq`](https://jqlang.org/). Each step saves the IDs it needs into shell variables, so you can paste the commands in order.

```shell
export NIMBUZ_API=https://api.nimbuz.tech
```

<Stepper>

1. **Log in**

   ```shell
   export NIMBUZ_TOKEN=$(curl -s $NIMBUZ_API/user/v1/user/login \
     -H 'Content-Type: application/json' \
     -d '{"username":"jane@example.com","password":"your-password","orgName":"nimbuz"}' \
     | jq -r '.data.token')
   AUTH="Authorization: Bearer $NIMBUZ_TOKEN"
   ```

2. **Create a project and its first environment**

   ```shell
   RESP=$(curl -s $NIMBUZ_API/project/v1/projects -H "$AUTH" -H 'Content-Type: application/json' \
     -d '{"name":"shop-api","description":"Web shop backend","envName":"production","region":"ap-south-1"}')
   PROJECT_ID=$(echo $RESP | jq -r '.data.id')
   ENV_ID=$(echo $RESP | jq -r '.data.environment.id')
   ```

   Add more environments with [Create an environment](/reference/environments).

3. **Deploy from Git**

   `gitUrl` takes the form `https://<host>/<owner>/<repo>.git -b <branch>`.

   ```shell
   DEPLOYMENT_ID=$(curl -s $NIMBUZ_API/deployment/v1/deployments -H "$AUTH" -H 'Content-Type: application/json' -d "{
     \"name\": \"shop-api\", \"projectId\": \"$PROJECT_ID\", \"environmentId\": \"$ENV_ID\",
     \"sourceCode\":  { \"type\": \"vcs\", \"gitUrl\": \"https://github.com/acme/shop-api.git -b main\" },
     \"application\": { \"replicas\": 1, \"instanceType\": \"small.m\" },
     \"network\":     { \"port\": 3000, \"healthEndpoint\": \"/health\" },
     \"config\": {}
   }" | jq -r '.data.id')
   ```

4. **Follow the build**

   ```shell
   curl -s "$NIMBUZ_API/deployment/v1/deployments?deploymentId=$DEPLOYMENT_ID&projectId=$PROJECT_ID&environmentId=$ENV_ID" \
     -H "$AUTH" | jq '{status: .data.status, url: .data.network.appIngressDomain}'
   ```

   Poll until `status` is `SUCCESS`, or subscribe to the [status stream](/streaming).

5. **Stop, start or scale**

   ```shell
   # Stop
   curl -s -X PUT $NIMBUZ_API/deployment/v1/deployments/$DEPLOYMENT_ID -H "$AUTH" -H 'Content-Type: application/json' \
     -d "{\"action\":\"pause\",\"projectId\":\"$PROJECT_ID\",\"environmentId\":\"$ENV_ID\"}"
   # Start
   curl -s -X PUT $NIMBUZ_API/deployment/v1/deployments/$DEPLOYMENT_ID -H "$AUTH" -H 'Content-Type: application/json' \
     -d "{\"action\":\"resume\",\"projectId\":\"$PROJECT_ID\",\"environmentId\":\"$ENV_ID\"}"
   # Scale
   curl -s -X PUT $NIMBUZ_API/deployment/v1/deployments/$DEPLOYMENT_ID -H "$AUTH" -H 'Content-Type: application/json' \
     -d "{\"projectId\":\"$PROJECT_ID\",\"environmentId\":\"$ENV_ID\",\"application\":{\"replicas\":2,\"instanceType\":\"medium.m\"}}"
   ```

6. **Install a tool**

   ```shell
   curl -s $NIMBUZ_API/deployment/v1/tools/supported -H "$AUTH" | jq '.data[] | {name, chart, version}'

   curl -s $NIMBUZ_API/deployment/v1/tools -H "$AUTH" -H 'Content-Type: application/json' -d "{
     \"name\": \"orders-db\", \"chart\": \"postgresql\", \"version\": \"<version from catalog>\",
     \"projectId\": \"$PROJECT_ID\", \"environmentId\": \"$ENV_ID\", \"exposePublicly\": false, \"values\": {}
   }"
   ```

   Stop or start a tool with `PATCH /deployment/v1/tools/pause-resume` and `"action": "pause"` or `"resume"`.

7. **Read metrics and logs**

   ```shell
   FROM=$(date -u -v-1H +%FT%TZ 2>/dev/null || date -u -d '1 hour ago' +%FT%TZ); TO=$(date -u +%FT%TZ)

   curl -s "$NIMBUZ_API/metrics/v1/resources?namespace=$ENV_ID&deploymentId=$DEPLOYMENT_ID&resourceType=cpu&from=$FROM&to=$TO&step=60" \
     -H "$AUTH" | jq '.data.usageRange.data.result[0].values[-5:]'

   curl -s $NIMBUZ_API/logs/v1/logs -H "$AUTH" -H 'Content-Type: application/json' \
     -d "{\"environmentId\":\"$ENV_ID\",\"logType\":\"application\",\"name\":\"shop-api\",\"timeRange\":\"1h\",\"keyword\":\"error\"}" \
     | jq -r '.data.logs[]'
   ```

8. **View invoices**

   ```shell
   ACCOUNT_ID=$(echo $NIMBUZ_TOKEN | cut -d. -f2 | base64 -d 2>/dev/null | jq -r '.properties.nimbuzAccountId')
   curl -s "$NIMBUZ_API/pricing/v1/invoices?account_id=$ACCOUNT_ID&limit=5" -H "$AUTH" \
     | jq '.data.data[] | {id, period, total, currency, status}'

   # PDF: the presigned URL needs no Authorization header
   URL=$(curl -s "$NIMBUZ_API/pricing/v1/invoices/<invoice-id>/presign?download=true" -H "$AUTH" | jq -r '.url')
   curl -s -o invoice.pdf "$URL"
   ```

9. **Clean up**

   Delete deployments and tools first, then the environment, then the project.

   ```shell
   curl -s -X DELETE "$NIMBUZ_API/deployment/v1/deployments?deploymentId=$DEPLOYMENT_ID&projectId=$PROJECT_ID&environmentId=$ENV_ID" -H "$AUTH"
   curl -s -X DELETE "$NIMBUZ_API/project/v1/environments?id=$ENV_ID&projectId=$PROJECT_ID" -H "$AUTH"
   curl -s -X DELETE $NIMBUZ_API/project/v1/projects/$PROJECT_ID -H "$AUTH"
   ```

</Stepper>
