I'm running into an interesting issue where the API seems to be unhappy when you pass a zero for an integer value instead of a null. For example, when creating a new feed, and passing the below JSON:
{
"name": "internal-chocolatey",
"alternateNames": null,
"feedType": "chocolatey",
"description": null,
"active": true,
"cacheConnectors": true,
"dropPath": null,
"packagePath": null,
"packageStore": null,
"allowUnknownLicenses": true,
"allowedLicenses": null,
"blockedLicenses": null,
"symbolServerEnabled": false,
"stripSymbols": false,
"stripSource": false,
"connectors": null,
"vulnerabilitySources": null,
"retentionRules": [
{
"deletePrereleaseVersions": false,
"deleteCached": true,
"keepVersionsCount": 10,
"keepUsedWithinDays": 0,
"triggerDownloadCount": 0,
"keepPackageIds": null,
"deletePackageIds": null,
"keepVersions": null,
"deleteVersions": null,
"sizeTriggerKb": 102400,
"sizeExclusive": true
}
],
"packageFilters": {},
"packageAccessRules": {},
"replication": {
"clientMode": null,
"serverMode": null,
"clientToken": null,
"serverToken": null,
"sourceUrl": null
},
"variables": {}
}
Results in the following error:
54716
0FeedRetentionRules_CreateOrUpdateRule
37`The INSERT statement conflicted with the CHECK constraint "CK__FeedRetentionRules". The conflict occurred in database "ProGet", table "dbo.FeedRetentionRules", column 'TriggerDownload_Count'.
Transaction count after EXECUTE indicates a mismatching number of BEGIN and COMMIT statements. Previous count = 1, current count = 0.
Notice that in the JSON above that the keepUsedWithinDays
and triggerDownloadCount
are both set to 0. This is what the API appears to be complaining about. If you replace those values with null like so:
...
"retentionRules": [
{
"deletePrereleaseVersions": false,
"deleteCached": true,
"keepVersionsCount": 10,
"keepUsedWithinDays": null,
"triggerDownloadCount": null,
"keepPackageIds": null,
"deletePackageIds": null,
"keepVersions": null,
"deleteVersions": null,
"sizeTriggerKb": 102400,
"sizeExclusive": true
}
],
...
The API has no issues creating the new feed. This is problematic because, behind the scenes, the Powershell API I am developing has defined these two properties as integers and the "zero value" for them is 0, not null.
The only option I have is to manually check for these edge cases and convert the zeroes into nulls before sending off the JSON which seems rather silly. Is there a specific reason the API won't accept a zero in this case?