Thanks DougS,
Looks like my problem is that I don't have the oauthAccessToken. I think I'm almost there, using the endpoint and plain javascript I was able to get the 'autorization_code', but when I do the POST /accessToken call I'm getting an internal server error.
I'm working with an endpoint because I don't need to display anything on our community. I'm working on an automated way to replace broken links on our community, so basically I'm pulling the content then using javascript to make the replacements and now I'm trying to write the message body back to the community.
Here's what I'm doing.
1. I'm using an XMLHttpRequest to send the GET /authorize request. I'm using a dummy redirect_uri because I want to do all the processing on the same endpoint, so I'm getting the authorization code from the 'responseURL'
2. I'm using that authorization code for the POST /accessToken request but I keep getting a 'Internal server error' ({"status":"Internal Server Error","message":"Internal Server Error","statusCode":500}) -not very descriptive-
var requestBody = {"client_id" : "<my client ID>",
"client_secret" : "<my client secret>",
"code" : authorization_code,
"redirect_uri" : "http://<my stage community URL>/",
"grant_type" : "authorization_code",
"state" : "someUniqueInfoAboutTheState"};
xhr2 = new XMLHttpRequest();
xhr2.open('POST',encodeURI('https://api.lithium.com/auth/v1/accessToken'),true);
xhr2.setRequestHeader('Content-Type', 'application/json');
xhr2.setRequestHeader('client-id', '<my client ID>');
xhr2.onload = function(aEvt) {
if(xhr2.status == 200) {
console.log("Response URL = " + xhr2.responseURL);
}
else {
console.log("Error loading page\n");
}
};
xhr2.send(JSON.stringify(requestBody));
I'm decoding the authorization code before sending it.
Any ideas?