Converting to PrivateApp: "Authentication credentials not found." - Using Powershell

Hi -

We are working to convert our API scripts to use the PrivateApp. Set up the PrivateApp. Got the token key. Tried a simple call. Got the error message "“Authentication credentials not found. This API supports both API Key and OAuth 2.0 authentication”.

Looking over examples and documentation and cant figure out. Am I missing something obvious?

Code:

$PrivateAppKey=“…(not shown)…”;

$url = “https://api.hubapi.com/crm/v3/objects/contacts/123456789”; # (obfuscated)

$headers = @{ ‘Content-Type’=‘application/json’
‘Authorization’= 'Basic ’ + $PrivateAppKey
}

$JSONStr=‘{“properties”:[{“property”:“Alink”,“value”:“https://www.someothersytsem.com”}]}’;

$response = Invoke-WebRequest -Uri $url -UseBasicParsing -Body $JSONstr -Headers $Headers -Method ‘PATCH’;

#Methods that fail: UPDATE, POST, GET

Response:

{“status”:“error”,“message”:"Authentication credentials not found. This API supports both API Key and OAuth 2.0 authentication and you can find more details at
https://developers.hubspot.com/docs/methods/auth/oauth-overview",“correlationId”:“27ded0ae-876c-4383-8129-0b3c7b64a83f”,“category”:“INVALID_AUTHENTICATION”}

Thanks!

@SeeOurBeach

Hi.

How about this?

$headers = @{ 'Content-Type'='application/json'
 'Authorization'= 'Bearer ' + $PrivateAppKey
}

`Authorization: Basic XXXX` means basic auth.

private app token is used by oauth2.

so , it should set `Authorization: Bearer XXXX` in header.

Thanks.

Perfect!
Thanks for that advice