From c435fcd685cc97e98d14f747227eefd39e4d1164 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Tue, 8 Oct 2024 01:27:22 +0300 Subject: [PATCH] Fixed: Error updating providers with ID missing from JSON --- src/Sonarr.Api.V3/ProviderControllerBase.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Sonarr.Api.V3/ProviderControllerBase.cs b/src/Sonarr.Api.V3/ProviderControllerBase.cs index e49e16bdc..04b3c6b73 100644 --- a/src/Sonarr.Api.V3/ProviderControllerBase.cs +++ b/src/Sonarr.Api.V3/ProviderControllerBase.cs @@ -86,9 +86,16 @@ namespace Sonarr.Api.V3 [RestPutById] [Consumes("application/json")] [Produces("application/json")] - public ActionResult UpdateProvider([FromBody] TProviderResource providerResource, [FromQuery] bool forceSave = false) + public ActionResult UpdateProvider([FromRoute] int id, [FromBody] TProviderResource providerResource, [FromQuery] bool forceSave = false) { - var existingDefinition = _providerFactory.Find(providerResource.Id); + // TODO: Remove fallback to Id from body in next API version bump + var existingDefinition = _providerFactory.Find(id) ?? _providerFactory.Find(providerResource.Id); + + if (existingDefinition == null) + { + return NotFound(); + } + var providerDefinition = GetDefinition(providerResource, existingDefinition, true, !forceSave, false); // Compare settings separately because they are not serialized with the definition. @@ -105,7 +112,7 @@ namespace Sonarr.Api.V3 _providerFactory.Update(providerDefinition); } - return Accepted(providerResource.Id); + return Accepted(existingDefinition.Id); } [HttpPut("bulk")]