No Code Attached Yet
avatar SoundHunter1
SoundHunter1
20 May 2024

Steps to reproduce the issue

Open Powershell, for example PowerShell 5 or 7 both x86 and x64 bits.

Expected result

JSON output of all Joomla articles and their settings.

Actual result

PowerShell 7.4.2: Invoke-RestMethod: Could not match accept header
PowerShell 5.1: Invoke-RestMethod: The remote server returned an error: (406) Not Acceptable

System information (as much as possible)

Windows 11 Pro 23H2 with PowerShell 7.4.2.
Joomla 4.4.4.

Additional comments

When using Postman I can get a connection, but via PowerShell it looks like Joomla don;t accept the application/json header.
I use PowerShell to do a lot of automations involving Joomla.

Used code:

$token = <BEARER_JOOMLA_API_KEY>

$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers = @{
    'Authorization'='Bearer $token'
    'Content-Type'='application/json'
}

$response = Invoke-RestMethod 'https://<DOMAIN_NAME>/api/index.php/v1/content/articles' -Method 'GET' -Headers $headers
$response | ConvertTo-Json
avatar SoundHunter1 SoundHunter1 - open - 20 May 2024
avatar joomla-cms-bot joomla-cms-bot - change - 20 May 2024
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 20 May 2024
avatar SoundHunter1 SoundHunter1 - change - 20 May 2024
The description was changed
avatar SoundHunter1 SoundHunter1 - edited - 20 May 2024
avatar rdeutz rdeutz - close - 1 Jun 2024
avatar rdeutz
rdeutz - comment - 1 Jun 2024

This doesn't looks like a bug, please use the forum.joomla.org for such questions

avatar rdeutz rdeutz - change - 1 Jun 2024
Status New Closed
Closed_Date 0000-00-00 00:00:00 2024-06-01 13:39:59
Closed_By rdeutz
avatar SoundHunter1
SoundHunter1 - comment - 6 Aug 2025

This is indeed an PowerShell issue, if someone need it in the feature, this is the correct code to read posts via PowerShell from Joomla 5:

# === Variables ===
$apiUrl = "https://<DOMAIN_NAME>/api/index.php/v1/content/articles"  # Change to your site
$apiKey = "<BEARER_JOOMLA_API_KEY>"  # Replace with your actual Bearer token

# === Headers ===
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "Bearer $apiKey")
$headers.Add("Content-Type", "application/json")
$headers.Add("Accept", "application/vnd.api+json")

# === POST Request ===
$response = Invoke-RestMethod -Uri $apiUrl -Method 'GET' -Headers $headers
$response | ConvertTo-Json

And the correct code to post an article:

# === Variables ===
$apiUrl = "https://<DOMAIN_NAME>/api/index.php/v1/content/articles"  # Change to your site
$apiKey = "<BEARER_JOOMLA_API_KEY>"  # Replace with your actual Bearer token

$title = "Article Title"
$text = "<p>This is the article content.</p>"
$categoryId = 1     # Category ID
$accessLevel = 1    # 1 = Public
$languageCode = "en-US"  # Language tag (e.g., "en-US", "nl-NL")

# === Headers ===
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "Bearer $apiKey")
$headers.Add("Content-Type", "application/json")
$headers.Add("Accept", "application/vnd.api+json")

# === JSON body ===
$body = @{
    title      = $title
    catid      = $categoryId
    access     = $accessLevel
    introtext  = $text
    language   = $languageCode
    state      = 1  # 1 = Published (0 = Unpublished)
} | ConvertTo-Json -Depth 3

# === POST Request ===
try {
    $response = Invoke-RestMethod -Uri $apiUrl -Method 'POST' -Headers $headers -Body $body
    Write-Host "Article created successfully:"
    $response | ConvertTo-Json -Depth 5
} catch {
    Write-Host "Error creating article:"
    Write-Host $_.Exception.Message
    if ($_.ErrorDetails) {
        Write-Host $_.ErrorDetails.Message
    }
}

Add a Comment

Login with GitHub to post a comment