Invoke Ansible API Token via Powershell

Viewed 31

I have created a Token for Admin account. Now I am trying to invoke some API in ansible using the below

$headers=@{
Authorization="Bearer <token>"
} 
$response=Invoke-WebRequest -Method GET -Uri "https://ansible.xyz.com/api/v2/job_templates" -Headers  $headers -ContentType "application/json"

When I do run the above I get the following error:

Authentication credentials were not provided. To establish a login session, visit /api/login/.

I don't understand when I use Token to authenticate why it's still showing an error.

When I use the same auth token in postman or curl it's working fine.

0 Answers
Related