Struggling with the Wrike API and accessing the access token using Ajax or ASP.Net for the first time. Following the "Wrike for Developers Documentation", but facing Error 400 (bad request) when trying to obtain the access token.
Here's the code snippet used:
$.ajax({
type: 'POST',
url: "https://www.wrike.com/oauth2/token",
data: {
client_id: <client_id>,
client_secret: <client_secret>,
grant_type: "authorization_code",
code: get("code")//from redirect URI
},
crossDomain: true,
dataType: 'jsonp',
success: function (response) {
alert(response); // server response
}
});
Unable to find JavaScript or ASP.net examples, only projects on GitHub for node.js and PHP. Is there something obvious missing or authentication needs to be done server-side using C#?
Cross-origin issues encountered and attempted fixes mentioned below:
$.ajax({
type: 'Post',
url: "https://www.wrike.com/oauth2/token",
data: {
client_id: "<client_id>",
client_secret: <client_Secret>,
grant_type: "authorization_code",
code: get("code")
},
success: function (response) {
alert(response); // server response
}
});
No resolution found for CORS issue despite attempts referenced here: CORS on ASP.NET
Tried backend implementation in ASP.net with C# resulting in error 400 bad request. Request works in Postman. Posting the code for review and will update if resolved.
protected void Page_Load(object sender, EventArgs e)
{
// Code snippet
}