# PostgreSQL

`POST /workspaces/:workspace/targets`

Create a new PostgreSQL deployment target

**Required Scopes:** `TARGET_ADD`

## URL Parameters

```typescript
interface URLParameters {
  /** The human-readable ID of the workspace */
  workspace: string; // Example: "my-company"
}
```

## Body Parameters

```typescript
interface BodyParameters {
  /** The type of the target */
  type?: "POSTGRESQL";
  /** A human-readable ID.  Alphanumeric characters, underscores, and hyphens (hyphens cannot appear at the start or end). */
  identifier: string;
  /** The hostname or IP address of the PostgreSQL server */
  host: string;
  /** PostgreSQL authentication credentials */
  auth: PostgresqlAuthView;
  /** The ID of the target */
  id?: string;
  /** The name of the target */
  name?: string;
  /** Short representation of a project */
  project?: ShortProjectView;
  /** Short representation of a pipeline */
  pipeline?: ShortPipelineView;
  /** Short representation of an environment object */
  environment?: ShortEnvironmentView;
  /** Access permissions configuration */
  permissions?: PermissionsView;
  /** Pipelines access level for this target */
  pipelines_access_level?: "DENIED" | "READ_ONLY" | "USE_ONLY" | "BLIND" | "RUN_ONLY" | "READ_WRITE" | "MANAGE" | "DEFAULT" | "ALLOWED" | "STAGE" | "COMMIT";
  /** List of specific pipelines allowed to use this target */
  allowed_pipelines?: AllowedPipelineView[];
  /** Sandboxes access level for this target */
  sandboxes_access_level?: "DENIED" | "READ_ONLY" | "USE_ONLY" | "BLIND" | "RUN_ONLY" | "READ_WRITE" | "MANAGE" | "DEFAULT" | "ALLOWED" | "STAGE" | "COMMIT";
  /** List of specific sandboxes allowed to use this target */
  allowed_sandboxes?: AllowedSandboxView[];
  /** Indicates if this target is disabled (default: `false`) */
  disabled?: boolean;
  /** The list of tags associated with the target */
  tags?: string[];
  /** Defines how the target can be used (as deployment target, proxy, or both) */
  use_as?: UseAsView;
  /** The port of the PostgreSQL server. Default: `5432` */
  port?: string;
  /** The default database name */
  database?: string;
  /** SSH proxy target for tunneling to private PostgreSQL servers */
  proxy?: TargetK8sProxyView;
}
```

## Response Body

```typescript
interface ResponseBody {
  /** The type of the target */
  type?: "POSTGRESQL";
  /** API endpoint to GET this object */
  url?: string;
  /** Web URL to view this object in Buddy.works */
  html_url?: string;
  /** The ID of the target */
  id?: string;
  /** A human-readable ID.  Alphanumeric characters, underscores, and hyphens (hyphens cannot appear at the start or end). */
  identifier: string;
  /** The name of the target */
  name?: string;
  /** Short representation of a project */
  project?: ShortProjectView;
  /** Short representation of a pipeline */
  pipeline?: ShortPipelineView;
  /** Short representation of an environment object */
  environment?: ShortEnvironmentView;
  /** Access permissions configuration */
  permissions?: PermissionsView;
  /** Pipelines access level for this target */
  pipelines_access_level?: "DENIED" | "READ_ONLY" | "USE_ONLY" | "BLIND" | "RUN_ONLY" | "READ_WRITE" | "MANAGE" | "DEFAULT" | "ALLOWED" | "STAGE" | "COMMIT";
  /** List of specific pipelines allowed to use this target */
  allowed_pipelines?: AllowedPipelineView[];
  /** Sandboxes access level for this target */
  sandboxes_access_level?: "DENIED" | "READ_ONLY" | "USE_ONLY" | "BLIND" | "RUN_ONLY" | "READ_WRITE" | "MANAGE" | "DEFAULT" | "ALLOWED" | "STAGE" | "COMMIT";
  /** List of specific sandboxes allowed to use this target */
  allowed_sandboxes?: AllowedSandboxView[];
  /** Indicates if this target is disabled (default: `false`) */
  disabled?: boolean;
  /** The list of tags associated with the target */
  tags?: string[];
  /** Defines how the target can be used (as deployment target, proxy, or both) */
  use_as?: UseAsView;
  /** The hostname or IP address of the PostgreSQL server */
  host: string;
  /** The port of the PostgreSQL server. Default: `5432` */
  port?: string;
  /** The default database name */
  database?: string;
  /** PostgreSQL authentication credentials */
  auth: PostgresqlAuthView;
  /** SSH proxy target for tunneling to private PostgreSQL servers */
  proxy?: TargetK8sProxyView;
}
```

## Type Definitions

```typescript
interface PostgresqlAuthView {
  /** Authentication method. Default: `PASSWORD` */
  method?: "PASSWORD";
  /** The PostgreSQL username */
  username: string;
  /** The PostgreSQL password */
  password: string;
}

interface ShortProjectView {
  /** API endpoint to GET this object */
  url?: string;
  /** Web URL to view this object in Buddy.works */
  html_url?: string;
  /** The human-readable ID of the project */
  name?: string;
  /** The Name of the project */
  display_name: string;
  /** The status of the project */
  status?: string;
  /** Indicates if this is a public project */
  access?: "PRIVATE" | "PUBLIC";
  /** The creation date of the project */
  create_date?: string;
}

interface ShortPipelineView {
  /** API endpoint to GET this object */
  url?: string;
  /** Web URL to view this object in Buddy.works */
  html_url?: string;
  /** The unique identifier of the pipeline */
  id?: number;
  /** A human-readable ID of pipeline */
  identifier?: string;
  /** The name of the pipeline */
  name?: string;
  /** The source of the pipeline definition */
  definition_source?: "LOCAL" | "REMOTE";
  /** The git configuration reference type */
  git_config_ref?: "NONE" | "DYNAMIC" | "FIXED";
  /** Pipeline git context refs. If unset and events is empty, the pipeline counts as codeless */
  refs?: string[];
  /** The list of events that trigger the pipeline run */
  events?: PipelineEventView[];
  /** The loop configuration for the pipeline */
  loop?: string[];
  /** The priority of the pipeline */
  priority?: "LOW" | "NORMAL" | "HIGH";
  /** Indicates if the pipeline is disabled */
  disabled?: boolean;
  /** The reason why the pipeline is disabled */
  disabled_reason?: string;
  /** The status of the last run */
  last_execution_status?: "INPROGRESS" | "ENQUEUED" | "TERMINATED" | "SUCCESSFUL" | "FAILED" | "INITIAL" | "NOT_EXECUTED" | "SKIPPED" | "TERMINATING" | "WAITING_FOR_APPLY" | "WAITING_FOR_VARIABLES" | "WAITING_FOR_SETTABLE_VARIABLES" | "WAITING_FOR_VT_SESSION";
  /** The git revision of the last run */
  last_execution_revision?: string;
  /** The URL to the target site after deployment */
  target_site_url?: string;
  /** The template for commit status messages */
  execution_message_template?: string;
  /** The creation date of the pipeline */
  create_date?: string;
  /** Defines whether to upload everything from scratch on every run */
  always_from_scratch?: boolean;
  /** If set to true, the status of a given pipeline will not impact the project status on the dashboard */
  ignore_fail_on_project_status?: boolean;
  /** If set to true, the pipeline will not skip queued runs to execute the most recent one */
  no_skip_to_most_recent?: boolean;
  /** If set to true, stale runs will be automatically terminated */
  terminate_stale_runs?: boolean;
  /** Defines whether to automatically clear cache before running the pipeline */
  auto_clear_cache?: boolean;
  /** Indicates if the pipeline is paused */
  paused?: boolean;
  /** Defines how many repeated failures are required to pause the pipeline */
  pause_on_repeated_failures?: number;
  /** If set to true, all refs will be fetched from the repository */
  fetch_all_refs?: boolean;
  /** If set to true, LFS files will be fetched from the external repository during pipeline runs */
  fetch_lfs?: boolean;
  /** If set to true, the pipeline will fail on environment preparation warnings */
  fail_on_prepare_env_warning?: boolean;
  /** Defines whether the pipeline can be run concurrently */
  concurrent_pipeline_runs?: boolean;
  /** Defines the depth of the git clone operation for shallow clones */
  clone_depth?: number;
  /** If set to true, commit statuses will not be created in the repository */
  do_not_create_commit_status?: boolean;
  /** Indicates that pipeline definition was probably removed on particular Git ref and pipeline won't be run on events */
  stale?: boolean;
  /** Indicates if the pipeline is waiting for the first push to the repository */
  waiting_for_push?: boolean;
  /** The resource configuration for the pipeline run */
  resources?: "DEFAULT" | "NANO" | "SMALL" | "MEDIUM" | "LARGE" | "XLARGE" | "CUSTOM" | "X2LARGE";
  /** The path to the remote pipeline definition file */
  remote_path?: string;
  /** The ref of the remote pipeline definition */
  remote_ref?: string;
  /** The project name of the remote pipeline definition */
  remote_project_name?: string;
  /** The parameters passed to the remote pipeline definition */
  remote_parameters?: PipelinePropertyView[];
  git_config?: YamlDefinitionView;
  /** The list of tags associated with the pipeline for organization */
  tags?: string[];
  /** The base for git changeset calculation. Determines which changes trigger the pipeline */
  git_changeset_base?: "LATEST_RUN" | "LATEST_RUN_MATCHING_REF" | "PULL_REQUEST";
  /** The base for filesystem changeset calculation. Determines which file changes trigger the pipeline */
  filesystem_changeset_base?: "DATE_MODIFIED" | "CONTENTS";
  /** The CPU architecture for the pipeline run */
  cpu?: "X64" | "ARM" | "X86";
  /** If set to true, a description is required when executing the pipeline manually */
  description_required?: boolean;
  /** The folder name where the pipeline is organized */
  folder?: string;
}

interface ShortEnvironmentView {
  /** API endpoint to GET this object */
  url?: string;
  /** Web URL to view this object in Buddy.works */
  html_url?: string;
  /** The name of the environment */
  name?: string;
  /** The human-readable identifier of the environment */
  identifier?: string;
  /** The ID of the environment */
  id?: number;
  /** The scope level of the environment */
  scope?: "PROJECT" | "WORKSPACE" | "ANY";
}

interface PermissionsView {
  /** Access level for other workspace members */
  others?: "DENIED" | "READ_ONLY" | "USE_ONLY" | "BLIND" | "RUN_ONLY" | "READ_WRITE" | "MANAGE" | "DEFAULT" | "ALLOWED" | "STAGE" | "COMMIT";
  /** List of specific users with their access levels */
  users?: UserPermissionView[];
  /** List of user groups with their access levels */
  groups?: GroupPermissionView[];
}

interface UseAsView {
  /** Whether the target can be used as a deployment target (default: `true`) */
  target?: boolean;
  /** Whether the target can be used as a proxy (default: `true`) */
  proxy?: boolean;
}

```

## Request Example

```bash
curl -X POST "https://api.buddy.works/workspaces/:workspace/targets" \
  -H "Authorization: Bearer <YOUR-TOKEN>" \
  -H "Content-Type: application/json" \
  -d '{
  "type": "POSTGRESQL",
  "identifier": "production-pg",
  "name": "Production PostgreSQL",
  "host": "pg.example.com",
  "port": 5432,
  "database": "myapp",
  "auth": {
    "method": "PASSWORD",
    "username": "deploy_user",
    "password": "secured"
  },
  "tags": [
    "postgresql",
    "production"
  ]
}'
```

## Response Example

**Status:** `201 Created`


---
Original source: https://buddy.works/docs/api/targets/create/postgresql