Search code examples
intuit-partner-platformquickbooks-online

401 when adding customer with QB Online API v3


I keep getting a 401 when I try to add a customer with QB Online API v3. The xml works in the API Explorer, and I'm able to query customers from my program. I just can't POST. What am I doing wrong?

        string reqBody = "<Customer xmlns=\"http://schema.intuit.com/finance/v3\" domain=\"QBO\" sparse=\"false\"><DisplayName>Empire Records</DisplayName>"
                + "<BillAddr><Line1>201 S King St</Line1><City>Seattle</City><CountrySubDivisionCode>WA</CountrySubDivisionCode><PostalCode>98104</PostalCode></BillAddr>"
                + "<PrimaryPhone><FreeFormNumber>425-867-5309</FreeFormNumber></PrimaryPhone><PrimaryEmailAddr><Address>[email protected]</Address></PrimaryEmailAddr></Customer>";

        IConsumerRequest req = session.Request();
        req = req.Post().WithRawContentType("application/xml").WithRawContent(System.Text.Encoding.ASCII.GetBytes(reqBody));
        req.AcceptsType = "application/xml";
        string response = req.Post().ForUrl("https://quickbooks.api.intuit.com/v3/company/" + realmID + "/customer").ToString()

Solution

  • OAuthConsumerContext consumerContext1 = new OAuthConsumerContext 
    { 
    ConsumerKey = ConfigurationManager.AppSettings["consumerKey"].ToString(), 
    SignatureMethod = SignatureMethod.HmacSha1, 
    ConsumerSecret = ConfigurationManager.AppSettings["consumerSecret"].ToString() 
    };  
    
    OAuthSession oSession1 = new OAuthSession(consumerContext1,     "https://oauth.intuit.com/oauth/v1/get_request_token", 
    "https://workplace.intuit.com/Connect/Begin", 
    "https://oauth.intuit.com/oauth/v1/get_access_token"); 
    
    oSession1.ConsumerContext.UseHeaderForOAuthParameters = true;