Advertisement

API connection to Joomla 4 not working via PowerShell

For Joomla! 4.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Post Reply
SoundHunter
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Mon Jun 17, 2024 8:00 pm

API connection to Joomla 4 not working via PowerShell

Post by SoundHunter » Mon Jun 17, 2024 8:12 pm

Hello all,

Not 100% shure if this should be under coding but I do have troubles with API access via Windows PowerShell.

Steps to reproduce the issue
Open Powershell, for example PowerShell 5 or 7 both x86 and x64 bits.
Fill in the code placed below under "Used code".

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:

Code: Select all

$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
Hopefully someone can help me further with this.
I already dropped this issue on the Joomla Github but received a reaction that this does not looks like a bug.
And to post it in the forums. https://github.com/joomla/joomla-cms/issues/43498

Thank you!

Advertisement
SharkyKZ
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3004
Joined: Fri Jul 05, 2013 10:35 am
Location: Parts Unknown

Re: API connection to Joomla 4 not working via PowerShell

Post by SharkyKZ » Tue Jun 18, 2024 5:43 am

Core APIs use application/vnd.api+json content type.

Advertisement

Post Reply

Return to “Joomla! 4.x Coding”