I am new to coding to REST API and could use some help.
I am trying to get my token in a C# application. I think I am close but I am getting back - Bad request
Here is my code. Any help would be appreciated.
var baseUri = new Uri("https://c2afw1111111111111.caspio.com/");
var encodedConsumerKey = HttpUtility.UrlEncode("111111111111111111111111111");
var encodedConsumerKeySecret = HttpUtility.UrlEncode("111111111111111111111111111");
var encodedPair = Base64Encode(String.Format("{0}:{1}", encodedConsumerKey, encodedConsumerKeySecret));
var requestToken = new HttpRequestMessage
{
Method = HttpMethod.Post,
RequestUri = new Uri(baseUri, "oauth/token"),
Content = new StringContent("grant_type=client_credentials")
};
requestToken.Content.Headers.ContentType = new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded") { CharSet = "UTF-8" };
requestToken.Headers.TryAddWithoutValidation("Authorization", String.Format("Basic {0}", encodedPair));
using (HttpClient client = new HttpClient())
{
using (HttpResponseMessage response = client.SendAsync(requestToken).Result)
{
using (HttpContent content = response.Content)
{
var json = content.ReadAsStringAsync().Result;
}
}
}