Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

D365 to Xero Integration

Posted on by 1,825
  • MichaelTomar Profile Picture
    MichaelTomar 65 on at
    RE: D365 to Xero Integration

    Hi, there are different ways to integrate D365 to Xero, I chose a simple method for myself that does not require coding, a free option is available, try the tool Skyvia

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: D365 to Xero Integration

    Hi Hemant,

    If you are still stuck with the issue, I'll suggest please have a look at the link below. We have a Connector that helps in a smooth integration between Xero and Dynamics 365 CRM.

    Link: www.solzit.com/.../

  • Hemant Kumar Sahu Profile Picture
    Hemant Kumar Sahu 1,825 on at
    RE: D365 to Xero Integration

    Hi Shahzad,

    The below step you need to follow:

    1)Generate Code, providing below details, paste the URL in browser, it will be manual process for the first time

    login.xero.com/.../authorize openid profile email accounting.transactions accounting.contacts accounting.contacts.read accounting.settings&state=1264

    This will give code as query string, store it in your system.

    2)Generate Token

    Call the below API:

    identity.xero.com/.../token

    In your code, you are missing below components:


    So your code should look like:

    private static async Task<string> GetAccessToken()

           {

               string accessToken = null;

               string refresh_token = null;

               string baseUrl = "identity.xero.com/.../token

               string clientId = "client_id";

               string clientSecret = "client_secrete";

     var plainText =ClientID:ClientSecret;

      var encodedText = Base64Encode(plainText);

               using (var client = new HttpClient())

               {

                   client.BaseAddress = new Uri(baseUrl);

                   // We want the response to be JSON.

                   client.DefaultRequestHeaders.Accept.Clear();

                   

        string _ContentType = "application/x-www-form-urlencoded";
              client .DefaultRequestHeaders.Add("authorization", "Basic " + encodedText);
              client .DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(_ContentType));

                   // 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>("code", "Code that you get at step 1"));

                   postData.Add(new KeyValuePair<string, string>("redirect_uri", "redirect_uri"));

                         var req = new HttpRequestMessage(HttpMethod.Post, "">identity.xero.com/.../token") { Content = new FormUrlEncodedContent(postData) };
      var response = cl.SendAsync(req).Result;
                var stream = response.Content.ReadAsStringAsync();
                if (response.IsSuccessStatusCode)
                {
                    var customerJsonString = response.Content.ReadAsStringAsync();
         

     object responseData = JsonConvert.DeserializeObject(jsonString);

                   // return the Access Token.

                   accessToken = ((dynamic)responseData).access_token;

                   refresh_token = ((dynamic)responseData).refresh_token;

     

               }

               return accessToken;

           }


    Keep, the refresh token saved, and next time you need to the same API and change the header
      postData.Add(new KeyValuePair<string, string>("grant_type", "refresh_token")
      postData.Add(new KeyValuePair<string, string>("refresh_token", "refreshtoken"));


    Hope this helps you.

    Regards
    Hemant

  • RE: D365 to Xero Integration

    Hi Hemant,

    Following is the code i am using but it gives a dialog for user id and password to generate token. whereas i need to generate token in the background so that i can run WebApi requests

    private static async Task<string> GetAccessToken()

           {

               string accessToken = null;

               string refresh_token = null;

               string baseUrl = "identity.xero.com/.../token

               string clientId = "client_id";

               string clientSecret = "client_secrete";

               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", "refresh_token"));

                   postData.Add(new KeyValuePair<string, string>("client_id", clientId));

                   postData.Add(new KeyValuePair<string, string>("client_secret", clientSecret));

                   postData.Add(new KeyValuePair<string, string>("scopes", "openid profile email accounting.transactions offline_access"));

                   postData.Add(new KeyValuePair<string, string>("state", "123"));

                   FormUrlEncodedContent content = new FormUrlEncodedContent(postData);

                   // Post to the Server and parse the response.

                   HttpResponseMessage response = await client.PostAsync("Token", content);

                   string jsonString = await response.Content.ReadAsStringAsync();

                   object responseData = JsonConvert.DeserializeObject(jsonString);

                   // return the Access Token.

                   accessToken = ((dynamic)responseData).access_token;

                   refresh_token = ((dynamic)responseData).refresh_token;

                   //Console.WriteLine("refresh_token: " + refresh_token);

                   //Console.WriteLine("accessToken: " + accessToken);

                   GetInvoice(accessToken);

               }

               return accessToken;

           }

  • Hemant Kumar Sahu Profile Picture
    Hemant Kumar Sahu 1,825 on at
    RE: D365 to Xero Integration

    Sure Shahzad, I will try to help you.

    Please share your code if you can or share the error that you are getting with details.

    Regards

    Hemant

  • RE: D365 to Xero Integration

    Hi Hemant,

    Good to know that it is sorted at your end. I am working through multiple example codes but unable to authenticate Web API requests to Xero via dynamics custom workflow using OAuth2.0

    Let me know if you can help in this regards.

    Shahzad

  • Hemant Kumar Sahu Profile Picture
    Hemant Kumar Sahu 1,825 on at
    RE: D365 to Xero Integration

    Hi Shahzad,

    Yes, I managed it to work for me. Please do let me what issue are you getting?

    Regards

    Hemant

  • RE: D365 to Xero Integration

    Hi Hemant,

    I am also stuck with authentication for my Xero integration. Has there been any luck for you to resolve, would appreciate if you can share or guide.

    Regards

  • Hemant Kumar Sahu Profile Picture
    Hemant Kumar Sahu 1,825 on at
    RE: D365 to Xero Integration

    Thanks Mehdi for quick response.

    I agree with you, we cant use the external dlls within sandbox but  we can make  REST API calls. 

    But currently I am strugglung with authetication, and not able to get access token to make connection with XERO.

    Thanks
    Hemant

  • Suggested answer
    meelamri Profile Picture
    meelamri 13,204 User Group Leader on at
    RE: D365 to Xero Integration

    Hi,

    There are some restrictions in CRM Online:

    You cannot access any other DLL’s

    You cannot call any webservices from within a sandboxed plugin

    Please check:

    community.dynamics.com/.../understanding-plugin-sandbox-mode

    An alternative way is to deploy your plugin as an Azure Function.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans