Truenas Scale - CERTIFICATE_CREATE_IMPORTED - Curl Command

Hi, seeking support for the following error after running a certificate import command via CURL. I am using the API capability within Truenas scale.

Error: "500 Internal Server Error Server got itself in trouble# "

CURL Command being run on the Truenas scale host:
curl -X ‘POST’
-H ‘accept: application/json’
-H ‘Authorization: Bearer 1-xxxxxxxxxxxxxxxxxxxxxxxxxxx’
-H ‘Content-Type: application/json’
-d ‘{
“name”: cert,
“certificate”: /etc/certificates/Test.crt,
“privatekey”: /etc/certificates/Test.key,

The ultimate goal is to use the import function via an Invoke-RestMethod powershell script. But looking at getting the CURL working first.

Any support or guidance is appreciated.

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.

curl -k -X ‘POST’
-H ‘accept: application/json’
-H ‘Content-Type: application/json’
-d ‘{
“name”: “gcert”,
“certificate”: “$GCert”,
“privatekey”: “$GKey”

On the Truenas host, the logs show the following. Any ideas? The cert and privkey can be imported with no issues via the WebUI.


[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 = @{
    "name" = "Cert"
    "certificate" = "$Cert"
    "privatekey" = "$PrivKey"

$jsonData = $jsonData | ConvertTo-Json 

# Set the content type for the request
$headers = @{
    "Accept"= "application/json"; 
    "Content-Type" = "application/json"

# Make the request using Invoke-RestMethod
$response = Invoke-RestMethod -Uri $endpointUrl -Method Post -Body $jsonData -Headers $headers

# Output the response