Forum Discussion

JoeLugo's avatar
JoeLugo
Qrew Member
4 years ago

Restful API / Update record

I am attempting to update a record.  The guide groups Insert/update in the same example.  Updating a record requires the field key.  Yet, when I'm including the value to update the record, the error message states I don't have permission to ADD records.  See below:
field 19 has the key number and field 656 is the column being updated.  Am I missing something?
var headers = {
  	'QB-Realm-Hostname': 'shumasports.quickbase.com',
	'User-Agent': 'joeinatlanta',
	'Authorization': 'QB-USER-TOKEN byud27_kxv6_dx6c7ygcyti5cizy2spyp22vy',
    'Content-Type': 'application/json'
};
var body = {"to":"bnsjwj798","data":[{"19":{"value":44981},"656":{"value":1234567890}}],"fieldsToReturn":[656]};

$.ajax({
    url: 'https://api.quickbase.com/v1/records',
    method: 'POST',
    headers: headers,
    data: JSON.stringify(body),
    success: function(result) {
        console.log(JSON.stringify(result));
    }
})​


------------------------------
Joe Lugo
------------------------------
  • AustinK's avatar
    AustinK
    Qrew Commander
    I don't have an answer right away here but I will suggest you remove your user token and any other identifying information from there. The user token can be used to impersonate you on that app via the API if someone wanted to. Not a huge deal if this was a token create for testing on a random app with no data, but a warning just in case.

    Do you have add permission in our current role on the table it is saying you do not have it on? My thought there is maybe it requires add permissions in order to merge or update things. I know it seems like a silly question as you are the admin there or at least have extra access but I am just curious.
    • JoeLugo's avatar
      JoeLugo
      Qrew Member
      Austin, thanks for the advice.  I have a SQL background and we figured out I was attempting to update a view rather than the actual table.  It appears with quickbase the field number is typically field 3.  So the data array was changed to 

      {
      "to": "bnsjuuhgv",
      "data": [
      {
      "3": {
      "value": 44981
      },
      "656": {
      "value": 1234567890
      }


      }
      ],
      "fieldsToReturn": [
      656
      ]
      }

       See table name and reference to field number 3.  If the field is included, quickbase assumes record is being updated.  Otherwise, it will attempt to add the record.  In SQL terms it would read "update bnsjuuhgv set field656="1234567890" where field3=44981".  I guess my next question would be, how about if I want to update multiple records based on a different condition.  Say "update bnsjuuhgv set field656="1234567890" where field17>5".  Possible?  Anyboddy?



      ------------------------------
      Joe Lugo
      ------------------------------