I'm putting together a process in Salesforce to work with PureCloud campaigns, and as it's the first OAuth process into PureCloud I've built I'm requesting some guidance. At this point I'm getting 'Bad Request' as the response, so (hopefully) it's something small and naive on my part that can be easily remedied. (I have also posted this on PureCloud's board; in general, there don't seem to be many other Salesforce developers that have worked with the Platform API over there.)
At the moment, I'm just putting together the request for an access token, and one piece that doesn't appear to be setting correctly is the grant_type. When I try to verify the header, I'm seeing null there.
Their example for getting the access token is:
POST /oauth/token HTTP/1.1 Host: login.mypurecloud.com Content-Type: application/x-www-form-urlencoded Authorization: Basic BASE64(<client_id>:<client_secret>) grant_type=client_credentials
In Apex, the code is as follows:
HttpRequest req = new HttpRequest(); req.setMethod('POST'); req.setHeader('Host','login.mypurecloud.com/oauth'); req.setHeader('content-type', 'application/x-www-form-urlencoded'); req.setHeader('authorization', 'Basic BASE64(' + clientId + ':' + clientSecret + ')'); req.setHeader('grant_type', 'client_credentials'); req.setEndpoint('https://login.mypurecloud.com/oauth/token');
When I output the header, I get the following:
Method:POST grant_type null authorization Basic BASE64(--clientID--:--clientSecret--) content-type application/x-www-form-urlencoded Host login.mypurecloud.com/oauth System.HttpRequest[Endpoint=https://login.mypurecloud.com/oauth/token, Method=POST]
So right now, it looks like the grant_type setting is invalid, at a minimum. Let me know if anything else jumps out at you, and thanks!