All, I have since tweaked the CURL command to look like the following. Note that the GCert and GKey are env variables that contain the Cert and PrivKey.
On the Truenas host, the logs show the following. Any ideas? The cert and privkey can be imported with no issues via the WebUI.
Error
[EINVAL] certificate_create.certificate: Not a valid certificate
[EINVAL] certificate_create.privatekey: A valid private key is required, with a passphrase if one has been set.
[EINVAL] certificate_create.certificate: Unable to parse certificate
For those that are interested, I have solved this problem via PowerShell. Below is a working TrueNAS certificate import.
#Define the URL of the API endpoint where you want to make the request
$endpointUrl = "https://truenas.local/api/v2.0/certificate/"
$Cert = Get-Content -Path "C:\Cert.crt" -Raw
$PrivKey = Get-Content -Path "C:\Priv.key" -Raw
$jsonData = @{
"create_type" = "CERTIFICATE_CREATE_IMPORTED"
"name" = "Cert"
"certificate" = "$Cert"
"privatekey" = "$PrivKey"
}
$jsonData = $jsonData | ConvertTo-Json
# Set the content type for the request
$headers = @{
"Accept"= "application/json";
"Authorization" = "Bearer 1-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
"Content-Type" = "application/json"
}
# Make the request using Invoke-RestMethod
$response = Invoke-RestMethod -Uri $endpointUrl -Method Post -Body $jsonData -Headers $headers
# Output the response
$response