I am running the following in Powershell. I am getting an error returned that "The given client credentials were not valid". I am trying to do the first step of using the API, generating the access token. I have confirmed that I have a valid client_id and client_secret.
This is working in Postman, but I am not seeing what I have wrong in Powershell. Help!
$URLTokenV2="https://accounts.adp.com/auth/oauth/v2/token?grant_type=client_credentials"
$Json= @{
client_id='xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx'
client_secret='xxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxxxxx'
}
$Json=$Json | ConvertTo-Json
$Cert = Get-ChildItem -Path "Cert:\LocalMachine\My" | Where-Object {$_.Subject -like "CN=CertCN*"}
$Response=Invoke-RestMethod -Uri $URLTokenV2 -Method Post -Body $Json -Certificate $Cert -ContentType 'application/x-www-form-urlencoded'
I have tried the same with Invoke-RestMethod and Invoke-WebRequest. I get the same result for both, that the client credentials are not valid.
Responses are appreciated. Thanks in advance.
-ContentType 'application/json'
? – Theogrant_type
query parameter in the body (add it to the$JSON
hashtable) instead of as part of the URI. – Mathias R. Jessen