# Update existing currency.

`PUT /v1/currencies/{code}`

Update existing currency.

Authentication (security requirement alternatives):

```json
[
  {
    "firefly_iii_auth": []
  },
  {
    "local_bearer_auth": []
  }
]
```

- firefly_iii_auth: oauth2. OAuth2 authorization code flow. Create a client on your installation's `/profile` page; it authorizes at `/oauth/authorize` and issues tokens at `/oauth/token` there. The URLs below are the demo site's. [How to use the API](https://sourcey-firefly.pages.dev/how-to/firefly-iii/features/api/index.md) walks through it.
- local_bearer_auth: http (bearer). A Personal Access Token, sent as a bearer token. Create one on your installation under Options > Profile > OAuth > Personal Access Tokens.

Parameters:

- `X-Trace-Id` (header, string, uuid, optional) - Unique identifier associated with this request.
  Type: string, uuid
  
  Example:
  
  ```json
  "40c71bbb-c676-4f24-83cf-cc725d7d7a00"
  ```

- `code` (path, string, string, required) - The currency code.
  Type: string, string
  
  Example:
  
  ```json
  "EUR"
  ```

Request body: application/vnd.api+json (required)

JSON array with updated currency information. See the model for the exact specifications.

Type: object

Schema: [CurrencyUpdate](https://sourcey-firefly.pages.dev/api/models/currencyupdate/index.md)

- `enabled` (optional)
  Type: boolean
  
  If the currency is enabled
  
  Example:
  
  ```json
  true
  ```

- `primary` (optional)
  Type: boolean
  
  If the currency must be the primary for the user. You can only submit TRUE. Submitting FALSE will not drop this currency as the primary currency, because then the system would be without one.
  
  enum: [true]
  
  Example:
  
  ```json
  true
  ```

- `code` (optional)
  Type: string, string
  
  The currency code
  
  Example:
  
  ```json
  "AMS"
  ```

- `name` (optional)
  Type: string, string
  
  The currency name
  
  Example:
  
  ```json
  "Ankh-Morpork dollar"
  ```

- `symbol` (optional)
  Type: string, string
  
  The currency symbol
  
  Example:
  
  ```json
  "AM$"
  ```

- `decimal_places` (optional)
  Type: integer, int32
  
  How many decimals to use when displaying this currency. Between 0 and 16.
  
  Example:
  
  ```json
  2
  ```

Request body: application/x-www-form-urlencoded (required)

JSON array with updated currency information. See the model for the exact specifications.

Type: object

Schema: [CurrencyUpdate](https://sourcey-firefly.pages.dev/api/models/currencyupdate/index.md)

- `enabled` (optional)
  Type: boolean
  
  If the currency is enabled
  
  Example:
  
  ```json
  true
  ```

- `primary` (optional)
  Type: boolean
  
  If the currency must be the primary for the user. You can only submit TRUE. Submitting FALSE will not drop this currency as the primary currency, because then the system would be without one.
  
  enum: [true]
  
  Example:
  
  ```json
  true
  ```

- `code` (optional)
  Type: string, string
  
  The currency code
  
  Example:
  
  ```json
  "AMS"
  ```

- `name` (optional)
  Type: string, string
  
  The currency name
  
  Example:
  
  ```json
  "Ankh-Morpork dollar"
  ```

- `symbol` (optional)
  Type: string, string
  
  The currency symbol
  
  Example:
  
  ```json
  "AM$"
  ```

- `decimal_places` (optional)
  Type: integer, int32
  
  How many decimals to use when displaying this currency. Between 0 and 16.
  
  Example:
  
  ```json
  2
  ```

Responses:

- 200: Updated currency stored, result in response

Content type: application/json

Type: object

Schema: [CurrencySingle](https://sourcey-firefly.pages.dev/api/models/currencysingle/index.md)

- `data` (required)
  Reference: [CurrencyRead](https://sourcey-firefly.pages.dev/api/models/currencyread/index.md); Type: object

- 400: Bad request

Content type: application/json

Type: object

Schema: [BadRequestResponse](https://sourcey-firefly.pages.dev/api/models/badrequestresponse/index.md)

- `message` (optional)
  Type: string, string
  
  Example:
  
  ```json
  "Bad Request"
  ```

- `exception` (optional)
  Type: string, string
  
  Example:
  
  ```json
  "BadRequestHttpException"
  ```

- 401: Unauthenticated

Content type: application/json

Type: object

Schema: [UnauthenticatedResponse](https://sourcey-firefly.pages.dev/api/models/unauthenticatedresponse/index.md)

- `message` (optional)
  Type: string, string
  
  Example:
  
  ```json
  "Unauthenticated"
  ```

- `exception` (optional)
  Type: string, string
  
  Example:
  
  ```json
  "AuthenticationException"
  ```

- 404: Page not found

Content type: application/json

Type: object

Schema: [NotFoundResponse](https://sourcey-firefly.pages.dev/api/models/notfoundresponse/index.md)

- `message` (optional)
  Type: string, string
  
  Example:
  
  ```json
  "Resource not found"
  ```

- `exception` (optional)
  Type: string, string
  
  Example:
  
  ```json
  "NotFoundHttpException"
  ```

- 422: Validation error. The body will have the exact details.

Content type: application/json

Type: object

Schema: [ValidationErrorResponse](https://sourcey-firefly.pages.dev/api/models/validationerrorresponse/index.md)

- `message` (optional)
  Type: string, string
  
  Example:
  
  ```json
  "The given data was invalid."
  ```

- `errors` (optional)
  Type: object
  
  - `email` (optional)
    Type: array
    
    Items:
      Type: string, string
  
  - `force` (optional)
    Type: array
    
    Items:
      Type: string, string
  
  - `blocked` (optional)
    Type: array
    
    Items:
      Type: string, string
  
  - `field` (optional)
    Type: array
    
    Items:
      Type: string, string
  
  - `role` (optional)
    Type: array
    
    Items:
      Type: string, string
  
  - `blocked_code` (optional)
    Type: array
    
    Items:
      Type: string, string
  
  - `name` (optional)
    Type: array
    
    Items:
      Type: string, string
  
  - `type` (optional)
    Type: array
    
    Items:
      Type: string, string
  
  - `iban` (optional)
    Type: array
    
    Items:
      Type: string, string
  
  - `start` (optional)
    Type: array
    
    Items:
      Type: string, string
  
  - `end` (optional)
    Type: array
    
    Items:
      Type: string, string
  
  - `date` (optional)
    Type: array
    
    Items:
      Type: string, string

- 500: Internal exception

Content type: application/json

Type: object

Schema: [InternalExceptionResponse](https://sourcey-firefly.pages.dev/api/models/internalexceptionresponse/index.md)

- `message` (optional)
  Type: string, string
  
  Example:
  
  ```json
  "Internal Exception"
  ```

- `exception` (optional)
  Type: string, string
  
  Example:
  
  ```json
  "InternalException"
  ```

## Examples

### cURL

```bash
curl -X PUT 'https://firefly.example.com/api/v1/currencies/EUR' \
  -H 'X-Trace-Id: 40c71bbb-c676-4f24-83cf-cc725d7d7a00' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Content-Type: application/vnd.api+json' \
  --data-raw '{
  "enabled": true,
  "primary": true,
  "code": "AMS",
  "name": "Ankh-Morpork dollar",
  "symbol": "AM$",
  "decimal_places": 2
}'
```

### JavaScript

```javascript
const body = `{
  "enabled": true,
  "primary": true,
  "code": "AMS",
  "name": "Ankh-Morpork dollar",
  "symbol": "AM$",
  "decimal_places": 2
}`;

const response = await fetch('https://firefly.example.com/api/v1/currencies/EUR', {
  method: 'PUT',
  headers: {
    'X-Trace-Id': '40c71bbb-c676-4f24-83cf-cc725d7d7a00',
    'Authorization': 'Bearer YOUR_TOKEN',
    'Content-Type': 'application/vnd.api+json',
  },
  body,
});

const data = await response.text();
```

### Python

```python
import requests

body = '''{
  "enabled": true,
  "primary": true,
  "code": "AMS",
  "name": "Ankh-Morpork dollar",
  "symbol": "AM$",
  "decimal_places": 2
}'''

response = requests.put(
    'https://firefly.example.com/api/v1/currencies/EUR',
    data=body.encode('utf-8'),
    headers={
        'X-Trace-Id': '40c71bbb-c676-4f24-83cf-cc725d7d7a00',
        'Authorization': 'Bearer YOUR_TOKEN',
        'Content-Type': 'application/vnd.api+json',
    },
)
print(response.text)
```
