Hi everyone,
I am working on Dynamics CRM integeration with MyOB Accounright (Live API) and I am not able to get OAUTH TOKEN from their API.
For each and every request it says "Invalid request" whereas I am sending the message/request in the format given on their developer portal and enclosing all the require headers/parameters.
Can someone help ? I already got the access code but need to get OAUTH ACCESS TOKEN.
I am using Online/Cloud based file and need to obtain it for the same.
Below is my C# code.
string baseUrl = "secure.myob.com/.../authorize"; try { using (var client = new HttpClient()) { client.BaseAddress = new Uri(baseUrl); // We want the response to be JSON. client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); // Build up the data to POST. List<KeyValuePair<string, string>> postData = new List<KeyValuePair<string, string>>(); postData.Add(new KeyValuePair<string, string>("grant_type", "authorization_code")); postData.Add(new KeyValuePair<string, string>("client_id", clientId)); postData.Add(new KeyValuePair<string, string>("client_secret", clientSecret)); postData.Add(new KeyValuePair<string, string>("scope", "CompanyFile")); postData.Add(new KeyValuePair<string, string>("redirect_uri", "http://desktop")); postData.Add(new KeyValuePair<string, string>("code", "UviY%21IAAAAC64WKiDpPhnUfp48i-WJAmaGrPDe4IhQUKSG90woCudAQEAAAFaYQZmCvVPVUPo4NysgvDzkQR2Xy6Bj2VWNAYlpC_xamLmcPs3Yw9Omw2_6ayPvEapdJYCQhHzRUDoGMrper1JD92jTs7jD1-ywmn6EmLdQnDBSbQGVD_ZN3UqRVtryE1LrDQbKgRF5mhTToqAClH_53qQLiD4enW3cyrmusa1rfx5vmZ5lqVNprUeyv3l6SyhF6b6vNuerqYvqSrLnNbpXSOnT5R9CKTbU5gKPa2Egp7Hm8Uw-4eF2FrEuU3FGXfvTHNpyPhwtzhQzVrNvUR1fzo02c3HRZaN01dfFHoBJucSWYFtT4-S7xm4HG8_TQCOLIPcLeZK-0c65ut7y1V_")); FormUrlEncodedContent content = new FormUrlEncodedContent(postData); // Post to the Server and parse the response. HttpResponseMessage response = await client.PostAsync("authorize", content); string jsonString = await response.Content.ReadAsStringAsync(); object responseData = JsonConvert.DeserializeObject(jsonString); // return the Access Token. return ((dynamic)responseData).access_token; } }
Reference URL (MyOB):
http://developers.myob.com/api/accountright/api-overview/authentication/
Thanks in Advance.
*This post is locked for comments