> ## Documentation Index
> Fetch the complete documentation index at: https://docs.apinizer.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Set Keystore

> Assigns a keystore to a credential. Keystores contain cryptographic keys and certificates used for TLS/SSL connections and digital signatures. The credential is automatically deployed to all environments after the keystore is assigned.

## Endpoint

```
PUT /apiops/projects/{projectName}/credentials/{username}/keystore/{keystoreName}/
```

## Authentication

Requires a Personal API Access Token.

### Header

```
Authorization: Bearer YOUR_TOKEN
```

## Request

### Headers

| Header        | Value          | Required |
| ------------- | -------------- | -------- |
| Authorization | Bearer {token} | Yes      |

### Path Parameters

| Parameter    | Type   | Required | Description                    |
| ------------ | ------ | -------- | ------------------------------ |
| projectName  | string | Yes      | Project name                   |
| username     | string | Yes      | Username of the credential     |
| keystoreName | string | Yes      | Name of the keystore to assign |

### Notes

* Keystore must exist in the project or in the admin project
* Credential must exist
* Only one keystore can be assigned to a credential at a time
* Assigning a new keystore replaces the existing one if present

## Response

### Success Response (200 OK)

```json theme={null}
{
  "success": true,
  "deploymentResult": {
    "success": true,
    "message": "Deployment completed successfully",
    "environmentResults": [
      {
        "environmentName": "production",
        "success": true,
        "message": "Deployed successfully"
      },
      {
        "environmentName": "staging",
        "success": true,
        "message": "Deployed successfully"
      }
    ]
  }
}
```

### Error Response (400 Bad Request)

```json theme={null}
{
  "error": "bad_request",
  "error_description": "Credential (username: api-user) was not found!"
}
```

or

```json theme={null}
{
  "error": "bad_request",
  "error_description": "Keystore (name: my-keystore) is not found!"
}
```

### Error Response (401 Unauthorized)

```json theme={null}
{
  "error": "unauthorized_client",
  "error_description": "Invalid token"
}
```

### Error Response (404 Not Found)

```json theme={null}
{
  "error": "not_found",
  "error_description": "Project(MyProject) was not found or user does not have privilege to access it!"
}
```

## cURL Example

```bash theme={null}
curl -X PUT \
  "https://demo.apinizer.com/apiops/projects/MyProject/credentials/api-user/keystore/my-keystore/" \
  -H "Authorization: Bearer YOUR_TOKEN"
```

## Notes and Warnings

* **Keystore Requirements**:
  * Keystore must exist in the project or admin project
  * Keystore name is case-sensitive

* **Credential Requirements**:
  * Credential must exist
  * Credential must be in the same project or accessible from the project

* **Replacement Behavior**:
  * Assigning a new keystore replaces any existing keystore
  * Previous keystore assignment is automatically removed

* **Automatic Deployment**:
  * Credential is automatically deployed to all environments after keystore assignment
  * Deployment results are returned in the response

## Permissions

* User must have **`IDENTITY` + `MANAGE`** permission in the project
* For automatic deployment, user must also have **`IDENTITY` + `DEPLOY_UNDEPLOY`** permission

## Related Documentation

* [Remove Keystore](/api-reference/credentials/secrets/remove-keystore) - Remove keystore from credential
* [Set Truststore](/api-reference/credentials/secrets/set-truststore) - Assign truststore to credential
* [List Credentials](/api-reference/credentials/crud/list-credentials) - List all credentials
