# Changelog

All notable changes to this project will be documented in this file.

## [0.6.0] - 2026-06-21

### Fixed
- **OAuth2 authentication**: corrected the credential default Base URL to a real
  regional host (`https://app.ninjaone.com`) instead of the non-existent
  `api.ninjaone.com`, and aligned the OAuth token endpoint to the same host.
  This resolves failures caused by an unreachable API host / mismatched token
  endpoint.
- **Ticket writes returning HTTP 405**: NinjaOne requires the Authorization Code
  (user) OAuth flow to create/update tickets and add comments — Client
  Credentials is rejected. The credential now supports selecting the grant type
  and defaults to Authorization Code, exposing the authorize endpoint and the
  n8n "Connect" button.
- **Update Ticket**: updates are now partial — only the fields you supply are
  sent, instead of overwriting every ticket field with defaults and triggering
  optimistic-locking (version) conflicts.
- **Add Comment**: file attachments are only sent when a binary property is set.

### Changed
- **Breaking (UI)**: ticket Create/Update optional fields are now grouped into
  "Additional Fields" / "Update Fields" collections. Existing Create/Update
  ticket nodes will need their optional fields re-selected after upgrading.
- **Credential grant type is now selectable** (Authorization Code or Client
  Credentials) and defaults to Authorization Code. Existing Client Credentials
  credentials keep working for read/device operations.
- Added a credential **Test** request so OAuth2 credentials can be verified from
  the credential screen.
- Updated README authentication, regional endpoint, and troubleshooting docs.

### Testing
- Added credential tests and extended ticket tests for the partial-update
  routing and corrected credential defaults.

## [0.5.0] - 2025-12-19

### Added
- **Run Script**: Execute PowerShell scripts or built-in actions on devices
  - Support for inline scripts and saved script library
  - Parameter passing to scripts
  - Run as SYSTEM or CURRENT_USER execution context
  - Endpoint: `POST /v2/device/{deviceId}/script/run`

- **Reboot Device**: Remote device restart with multiple modes
  - Normal, Force, and Safe Mode options
  - Configurable delay before reboot
  - Endpoint: `POST /v2/device/{deviceId}/reboot/{mode}`

- **Control Windows Service**: Start, stop, and restart Windows services remotely
  - Service name parameter
  - START, STOP, RESTART actions
  - Endpoint: `POST /v2/device/{deviceId}/windows-service/{serviceId}/control`

- **Get Dashboard URL**: Retrieve direct link to device dashboard
  - Quick access to NinjaOne device management console
  - Endpoint: `GET /v2/device/{deviceId}/dashboard-url`

### Changed
- Updated device operations to include new Windows management capabilities
- Enhanced OAuth2 scope documentation for new operations
- Improved device operation routing configuration

### Security
- All new operations require OAuth2 authentication with "monitoring management" scope
- API calls use HTTPS encryption
- Sensitive data handling follows NinjaOne best practices

### Testing
- Comprehensive test coverage for all new operations
- Jest unit tests for script execution, device reboot, and service control operations
- Integration testing with NinjaOne API endpoints

## [0.4.16] - Previous Release
- Complete ticketing system integration
- Device monitoring and inventory
- Organization management
- Ticket field mapping with real API responses
- Board-based ticket listing

---

## Installation

```bash
npm install @ev1lc0rp/n8n-nodes-ninjaone@0.5.0
```

## Usage Examples

### Execute Script
```json
{
  "resource": "device",
  "operation": "runScript",
  "deviceId": "12345",
  "scriptType": "ACTION",
  "scriptContent": "Get-Service W3SVC | Select-Object Status",
  "runAs": "SYSTEM"
}
```

### Reboot Device
```json
{
  "resource": "device",
  "operation": "rebootDevice",
  "deviceId": "12345",
  "rebootMode": "NORMAL",
  "rebootDelay": 60
}
```

### Control Windows Service
```json
{
  "resource": "device",
  "operation": "controlWindowsService",
  "deviceId": "12345",
  "serviceName": "W3SVC",
  "serviceAction": "RESTART"
}
```

### Get Dashboard URL
```json
{
  "resource": "device",
  "operation": "getDashboardUrl",
  "deviceId": "12345"
}
```

## API Reference

### Device Script Execution
- **Method**: POST
- **Endpoint**: `/v2/device/{deviceId}/script/run`
- **Required Parameters**: deviceId, scriptContent or scriptId
- **Optional Parameters**: parameters, runAs

### Device Reboot
- **Method**: POST
- **Endpoint**: `/v2/device/{deviceId}/reboot/{mode}`
- **Modes**: NORMAL, FORCE, SAFE_MODE
- **Optional Parameters**: delay (seconds)

### Windows Service Control
- **Method**: POST
- **Endpoint**: `/v2/device/{deviceId}/windows-service/{serviceId}/control`
- **Required Parameters**: deviceId, serviceName, serviceAction
- **Actions**: START, STOP, RESTART

### Device Dashboard URL
- **Method**: GET
- **Endpoint**: `/v2/device/{deviceId}/dashboard-url`
- **Returns**: URL to device dashboard in NinjaOne console

## Breaking Changes
None in this release.

## Migration Guide
No migration needed. All new operations are backward compatible additions.

## Known Issues
- None currently identified

## Contributing
See [docs/development/](docs/development/) for contribution guidelines.

## Support
For issues or questions:
1. Check [GitHub Issues](https://github.com/ai-Ev1lC0rP/n8n-nodes-ninjaone/issues)
2. Review [NinjaOne API Documentation](https://resources.ninjarmm.com)
3. Contact maintainer: ai-ev1lc0rp@gmail.com

## License
MIT - See [LICENSE.md](LICENSE.md)
