I was able to get Signpost work with QuickBooks Online using HttpPost. However when I tried querying with filters, I got 401 error every time. After contacting support, I was informed that this is a known bug. They pointed me to an example in C#. I am using Signpost oauth library in Java. The C# example doesn't make sense to me since I don't have those functions available in Signpost. Also I don't understand what exactly I need to do.
One side note: I had to use HttpClient for this content type: "application/x-www-form-urlencoded". This is the limitation that comes from Signpost.
Unauthorized OAuth Token: signature_invalid401SERVER
The C# workaround example:
https://gist.github.com/IntuitDeveloperRelations/6024616
/* filtering fails with 401 error */
HttpClient client = new DefaultHttpClient();
HttpPost requestHp = new HttpPost("https://qbo.intuit.com/qbo28/resource/accounts/v2/670436015");
requestHp.addHeader("Content-Type", "application/x-www-form-urlencoded");
BasicHttpEntity filter = new BasicHttpEntity();
filter.setContent(new StringInputStream("Filter=Name :EQUALS: Continuing"));
requestHp.setEntity(filter);
CommonsHttpOAuthConsumer consumer = new CommonsHttpOAuthConsumer(getOauthConsumerKey(), getOauthConsumerSecret());
consumer.setTokenWithSecret(getOauthAccessToken(),getOauthAccessTokenSecret());
consumer.sign(requestHp);
HttpResponse response = client.execute(requestHp);
AcctNum is not a valid filter for QBO Account entity.
Ref - https://developer.intuit.com/docs/0025_quickbooksapi/0050_data_services/v2/0400_quickbooks_online/account#Attributes_Supporting_Filtering_and_Sorting
You can use 'Name' attribute as filter.
PFB code snippet
Using java devkit
public List<QBAccount> testGetAll() {
QBAccountQuery accountQuery = new QBAccountQuery(context);
accountQuery.setName("BankCharges");
final List<QBAccount> entityList = new ArrayList<QBAccount>();
try {
QBAccountService service = QBServiceFactory.getService(context, QBAccountService.class);
List<QBAccount> qbAccountList = service.getAccounts(context, accountQuery);
for (QBAccount each : qbAccountList) {
entityList.add(each);
}
} catch (QBInvalidContextException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return entityList;
}
Endpoint - https://qbo.intuit.com/qbo1/resource/accounts/v2/188712345
Content-Type: application/x-www-form-urlencoded
post data to end point: Filter= Name :EQUALS: BankCharges
Using Signpost
public class PocApiCall {
static String accesstoken = "";
static String accessstokensecret = "";
static String appToken = "";
static String oauth_consumer_key = "";
static String oauth_consumer_secret = "";
static String realmID = "";
static String dataSource = "";
static String url = "";
PocApiCall() {
setupQBO();
}
public static void main(String args[]) {
PocApiCall apiCall = new PocApiCall();
apiCall.testLikeDevkit();
}
private void testLikeDevkit() {
HttpClient client = new DefaultHttpClient();
HttpPost requestHp = new HttpPost(url);
requestHp.addHeader("Content-Type", "application/x-www-form-urlencoded");
BasicHttpEntity filter = new BasicHttpEntity();
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("Filter", "Name :EQUALS: BankCharges"));
requestHp.setEntity(new UrlEncodedFormEntity(nameValuePairs,"UTF-8"));
CommonsHttpOAuthConsumer consumer = new CommonsHttpOAuthConsumer(oauth_consumer_key, oauth_consumer_secret);
consumer.setTokenWithSecret(accesstoken, accessstokensecret);
consumer.sign(requestHp);
debugRequestValues(requestHp);
HttpResponse execute = client.execute(requestHp);
System.out.println(new BufferedReader(new InputStreamReader(execute.getEntity().getContent())).readLine());
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (OAuthMessageSignerException e) {
e.printStackTrace();
} catch (OAuthExpectationFailedException e) {
e.printStackTrace();
} catch (OAuthCommunicationException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private void debugRequestValues(HttpPost requestHp) throws IOException {
System.out.println("Method - " + requestHp.getRequestLine().getMethod());
System.out.println("URI - " + requestHp.getRequestLine().getUri());
Header[] allHeaders = requestHp.getAllHeaders();
for(Header h : allHeaders){
System.out.println("Name - " + h.getName() + " Value - " + h.getValue());
}
if(requestHp.getEntity() != null){
System.out.println(new BufferedReader(new InputStreamReader(requestHp.getEntity().getContent())).readLine());
}
}
private static void setupQBO() {
System.out.println("QBO token setup");
accesstoken = "your tokens";
accessstokensecret = "your tokens";
appToken = "your tokens";
oauth_consumer_key = "your tokens";
oauth_consumer_secret = "your tokens";
realmID = "688779980";
dataSource = "QBO";
url = "https://qbo.intuit.com/qbo1/resource/accounts/v2/123459980";
}
}
Thanks