static void GetInvoice()
        {
            var access_token = "eyJlbmMiOiJBMTI4Q0JDLUhTMjU2IiwiYWxnIjoiZGlyIn0..LwSTn4HRGxVVQwYR8gCKCA.CgUGG49Xm9AL33-FLxErp8PCWysuLdVhWKVWOsXAdD32ogoZws0hwicnQwgoeI_NuBPOZsEv-TjFxDMblx42udGfW74bfAb9JUr9m94miOSPCuZGsw7LlnOaAEXp4JHQka8SEStVWlGQ_3jGzwygIyaoVF9QmVuExfFBnE0ZXG1AEatZscqLke_BAq-hyi_8hIm5JihrUpVq6qHXfp6XotH4ucakDC8z4U-KORYSVYWgRStQFQy9W2z_-hA1xg-kA1j3vMP4UkfE0292ORpPp_NU-__ZnRyj42OMP71pjTZpCB87dWXPZX9Vt8P7icxnaYQ2ZQL_z_VxDFbRnlOCzxwN7e6ukmZLbo7FTsZjuIgevYE46dF7cHwWJKqnRTsL7addty6DXcscOoM_q5qswlz8So_Klrnn6xNZVcJpF20QdKMK01GPDRyDBciAS1kq-U8CvESKa13F_LKM7_c-6Lmmw0OdMlomLRSc_ljwpuooQmI6GcAl-RZkoiuLR7UtFgdk6L0X99triME1aggWo5hZ0iMPNuUj9SHd-gMMvQl4IyqcZ7MAqNkxVeEDxkPUsgAiHX78eEHBkcfYhrxBEaTf6NEoztKrV8NaATJkLFEifwqy_xc2gKLZdoVpD0t787VDiMhGvlOFi_fSdSPrCrucU0jPR2zhKzfnXjNasXYP3RdxngRtlNO8GGuMvvqf.havdNFIRyLJ2ocADbZtpdg";

            realmId = "123146024163879";
            OAuth2RequestValidator oauthValidator = new OAuth2RequestValidator(access_token);

            ServiceContext serviceContext = new ServiceContext(realmId, IntuitServicesType.QBO, oauthValidator);

            serviceContext.IppConfiguration.BaseUrl.Qbo = "https://sandbox-quickbooks.api.intuit.com/"; //sandbox
                                                                                                        //serviceContext.IppConfiguration.BaseUrl.Qbo = "https://quickbooks.api.intuit.com/";//prod

            serviceContext.IppConfiguration.Message.Request.SerializationFormat  = Intuit.Ipp.Core.Configuration.SerializationFormat.Xml;
            serviceContext.IppConfiguration.Message.Response.SerializationFormat = Intuit.Ipp.Core.Configuration.SerializationFormat.Xml;
            serviceContext.IppConfiguration.MinorVersion.Qbo = "8";

            //serviceContext.IppConfiguration.Logger.RequestLog.EnableRequestResponseLogging = true;
            //serviceContext.IppConfiguration.Logger.RequestLog.ServiceRequestLoggingLocation = @"C:\Users\nshrivastava\Documents\Logs";
            //serviceContext.RequestId = "897kjhjjhkh9";

            DataService commonServiceQBO = new DataService(serviceContext);

            Intuit.Ipp.Data.Item   item      = new Intuit.Ipp.Data.Item();
            List <Item>            results   = commonServiceQBO.FindAll <Item>(item, 1, 1).ToList <Item>();
            QueryService <Invoice> inService = new QueryService <Invoice>(serviceContext);
            Invoice In = inService.ExecuteIdsQuery("SELECT * FROM Invoice").FirstOrDefault();
        }
Exemple #2
0
        /// <summary>
        /// Test QBO api call
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="refresh_token"></param>
        /// <param name="realmId"></param>
        /// <returns></returns>
        public async System.Threading.Tasks.Task qboApiCall(string access_token, string refresh_token, string realmId)
        {
            try
            {
                if (realmId != "")
                {
                    output("Making QBO API Call.");

                    OAuth2RequestValidator oauthValidator = new OAuth2RequestValidator(access_token);

                    ServiceContext serviceContext = new ServiceContext(realmId, IntuitServicesType.QBO, oauthValidator);
                    serviceContext.IppConfiguration.BaseUrl.Qbo = "https://sandbox-quickbooks.api.intuit.com/"; //sandbox
                                                                                                                //serviceContext.IppConfiguration.BaseUrl.Qbo = "https://quickbooks.api.intuit.com/";//prod

                    serviceContext.IppConfiguration.Message.Request.SerializationFormat  = Intuit.Ipp.Core.Configuration.SerializationFormat.Xml;
                    serviceContext.IppConfiguration.Message.Response.SerializationFormat = Intuit.Ipp.Core.Configuration.SerializationFormat.Xml;
                    serviceContext.IppConfiguration.MinorVersion.Qbo = "8";


                    //serviceContext.IppConfiguration.Logger.RequestLog.EnableRequestResponseLogging = true;
                    //serviceContext.IppConfiguration.Logger.RequestLog.ServiceRequestLoggingLocation = @"C:\Users\nshrivastava\Documents\Logs";
                    //serviceContext.RequestId = "897kjhjjhkh9";

                    DataService            commonServiceQBO = new DataService(serviceContext);
                    Intuit.Ipp.Data.Item   item             = new Intuit.Ipp.Data.Item();
                    List <Item>            results          = commonServiceQBO.FindAll <Item>(item, 1, 1).ToList <Item>();
                    QueryService <Invoice> inService        = new QueryService <Invoice>(serviceContext);
                    Invoice In = inService.ExecuteIdsQuery("SELECT * FROM Invoice").FirstOrDefault();

                    output("QBO call successful.");
                    lblQBOCall.Visible = true;
                    lblQBOCall.Text    = "QBO Call successful";
                }
            }
            catch (IdsException ex)
            {
                if (ex.Message == "UnAuthorized-401" || ex.Message == "The remote server returned an error: (401) Unauthorized.")
                {
                    output("Invalid/Expired Access Token.");
                    //if you get a 401 token expiry then perform token refresh
                    await performRefreshToken(refresh_token);

                    if ((dictionary.ContainsKey("accessToken")) && (dictionary.ContainsKey("accessToken")) && (dictionary.ContainsKey("realmId")))
                    {
                        await qboApiCall(dictionary["accessToken"], dictionary["refreshToken"], dictionary["realmId"]);
                    }
                }
                else
                {
                    output(ex.Message);
                }
            }
            catch (Exception ex)
            {
                //Check Status Code 401 and then
                output("Invalid/Expired Access Token.");
            }
        }