Forum Discussion

AlexBennett3's avatar
AlexBennett3
Qrew Trainee
4 years ago

QuickBase API "Query for Data" body help

Hey Everyone,

I'm attempting to do an API call in an external application to pull some data over from our QuickBase to be able to manipulate other charts and graphs outside of QuickBase based on these field data values.
I wondered if anyone had any input on how to form the body properly, I'm reading maybe using the API_DoQuery call with clist of all field ID's? I was able to make the call getting the field id's at names pulled over, but no data yet.

var headers = {
  'QB-Realm-Hostname': 'XXXXXXXXX.quickbase.com',
  'User-Agent': 'FileService_Integration_V2.1',
  'Authorization': 'QB-USER-TOKEN XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
  'Content-Type': 'application/json'
}

// var body = {
//   "from": "bpz99ram7",
//   "select": [],
//   "sortBy": [
//     {
//       "fieldId": 6,
//       "order": "ASC"
//     },
//   ],
// }

fetch('https://api.quickbase.com/v1/fields/usage?tableId=bpz99ram7&skip=0&top=0',
  {
    method: 'GET',
    headers: headers,
    //body: JSON.stringify(body)
  })

.then(res => {
  if (res.ok) {
    return res.json().then(res => console.log(res));
  }
  return res.json().then(resBody => Promise.reject({status: res.status, ...resBody}));
})
.catch(err => console.log(err))
ā€‹
As you can see above, I've commented out the 'body' and changed the method to GET, I believe I need to have the body with the field ID's being pulled over, and changing the method type to POST, but am getting 405 error (Method Not Allowed) whenever I attempt to use a body and method type of POST. 

Again, the idea is to pull over field values to be able to be used in custom software charts and graphs based on what is in these fields in QuickBase.

Any help would be greatly appreciated!

Edit: I know the "select" array for field ID's is blank, when I added field ID's I still got errors.
This code also works and I can see in my Console that I'm getting all the field ID's from that table and their corresponding field names, but not values which is why I'm attempting to switch to "Query for Data".

Thanks!!

------------------------------
Alex Bennett
------------------------------

1 Reply

  • UPDATE: I found my issue, it was in my syntax, I'm leaving the Array blank to include all fields from the designated table, but had my syntax formatted wrong due to trying to convert over from the method "GET" to "POST". Here is my updated API call for reference for anyone else having issues.

    var headers = {
      	'QB-Realm-Hostname': 'XXXXXXXXXXXX.quickbase.com',
    	'User-Agent': 'FileService_Integration_V2.1',
    	'Authorization': 'QB-USER-TOKEN XXXXXXXX_XXXXXXXXX_XXXXXXXXXXXXXXXXX',
        'Content-Type': 'application/json'
    }
    var body = {"from":"bpz99ram7","select":[],"sortBy":[{"fieldId":6,"order":"ASC"}],"groupBy":[{"fieldId":6,"grouping":"equal-values"}],"options":{"skip":0,"top":0,"compareWithAppLocalTime":false}}
    
    fetch('https://api.quickbase.com/v1/records/query',
      {
        method: 'POST',
        headers: headers,
        body: JSON.stringify(body)
      })
    .then(res => {
      if (res.ok) {
        return res.json().then(res => console.log(res));
      }
      return res.json().then(resBody => Promise.reject({status: res.status, ...resBody}));
    })
    .catch(err => console.log(err))ā€‹


    ------------------------------
    Alex Bennett
    ------------------------------