2

I created table with the following 3 fields with quickbase

name,email,post

Now am trying to insert into the table via table id with quickbase.

here is the documentation API Link API lINK

here is the API Curl documentation

curl -X POST 'https://api.quickbase.com/v1/records' \
-H 'QB-Realm-Hostname: {QB-Realm-Hostname}' \
-H 'User-Agent: {User-Agent}' \
-H 'Authorization: {Authorization}' \
-d {}

here is the sample request

{
  "to": "bck7gp3q2",
  "data": [
    {
      "6": {
        "value": "This is my text"
      },
      "7": {
        "value": 10
      },
      "8": {
        "value": "2019-12-18T08:00:00.000Z"
      },
      "9": {
        "value": [
          "a",
          "b"
        ]
      },
      "10": {
        "value": true
      },
      "11": {
        "value": "user@quickbase.com"
      },
      "12": {
        "value": "www.quickbase.com"
      },
      "13": {
        "value": [
          {
            "id": "123456.ab1s"
          },
          {
            "id": "254789.mkgp"
          },
          {
            "id": "789654.vc2s"
          }
        ]
      }
    }
  ],
  "fieldsToReturn": [
    6,
    7,
    8,
    9,
    10,
    11,
    12,
    13
  ]
}

Here is my effort so far When I run the code below, I have the following error

{"data":[],"metadata":{"createdRecordIds":[],"lineErrors":{"1":["Can not find record by ID \"My First post\"."]},"totalNumberOfRecordsProcessed":1,"unchangedRecordIds":[],"updatedRecordIds":[]}}{"data":[],"metadata":{"createdRecordIds":[],"lineErrors":{"1":["Can not find record by ID \"My First post\"."]},"totalNumberOfRecordsProcessed":1,"unchangedRecordIds":[],"updatedRecordIds":[]}}

here is my code

<?php

$access_t ="my_access_token-goes here";
$url="https://api.quickbase.com/v1/records";
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
$useragent ='my-user-agent goes here';

$quicbase_domain= 'my-quickbase-domain-goes-here';

$data='

{
  "to": "my-table-id-goes-here",
  "data": [
    {


      "1": {
        "value": "nancy more"
      },
      "2": {
        "value": "nancy@gmail.com"
      },

"3": {
        "value": "My First post"
      }

    }
  ]
  
}

';

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"QB-Realm-Hostname: quicbase_domain",
"User-Agent: $useragent",
"Authorization: QB-USER-TOKEN $access_t",
'Content-Type:application/json'
));  

curl_setopt($ch,CURLOPT_CUSTOMREQUEST,'POST');
curl_setopt($ch,CURLOPT_POSTFIELDS, $data);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
 echo $response = curl_exec($ch);

curl_close($ch);

print_r($response);
Nancy Moore
  • 2,322
  • 2
  • 21
  • 38

1 Answers1

1

The same endpoint is used for both insert and update and Quick Base uses the inclusion of the key field to distinguish between the two. In my experience field ID #3 has always been the "Record ID#" field; one of the fields Quick Base automatically creates for every new table and the one it uses as the default key field. Since your data array contains a value for field ID #3, Quick Base is interpreting your request as an update to which it can find no record with the ID "My First Post". There's also the issue that field ID #3 expects a number, but Quick Base's error response is not sophisticated enough to give that feedback.

I think the issue with your request is that you have the wrong field IDs. 1, 2, and 3 correspond to the automatically generated fields of "Date Created", "Date Modified", and "Record ID#". The fields that you created for your table probably start at field ID #6. If you go into Quick Base and look at the properties of your table you should be able to see a list of fields and their Field Ids (if you don't see the Field Id column, you can choose to display it in Advanced Options). Use the correct field IDs in your request, and it should work as expected.

Nathan Hawe
  • 281
  • 3
  • 5
  • This is what I was going to suggest also. – Erich Wehrmann Sep 28 '20 at 19:10
  • Thanks @Nathan Hawe. Insert is working now. before i accept your answer please do you have any idea on how I can delete a particular row based on Id. Lets assume i want to delete record where an id is **18**. I have tried it like this but it says error **bad request** `$post =' { "from": "bqvieybn", "where": "{18}" } ';` – Nancy Moore Sep 28 '20 at 22:15
  • Thanks @Erich Wehrmann for responding also. Please do you have any idea on how I can delete data based on id as I stated in the comment section above. – Nancy Moore Sep 28 '20 at 22:18
  • 1
    @NancyMooree, you pass a query to delete. So, assuming that in your example 18 is the record ID you would delete with `$post ='{ "from" : "bqvieybn", "where": "{3.EX.18}"}';`. – Nathan Hawe Sep 28 '20 at 23:04
  • Thanks alot Sir Nathan. You are the best – Nancy Moore Sep 29 '20 at 10:44
  • @NathanHawe, one more question, let assume that I want to delete records where two variables matches **Eg. where record ID is 18 and email address is ann@gmail.** How do I do that. Between Thanks, hoping to hear from you sir – Nancy Moore Sep 29 '20 at 10:47
  • @NancyMooree, you can pass any query as the value for the the `where` property and all the records that match your query will be deleted. So, assuming that email is field ID #8 your query might look like `{3.EX.18}AND{8.EX.'ann@gmail.com'}`. You can read more about Quick Base's query syntax on their [Components of a Query](https://help.quickbase.com/api-guide/componentsquery.html) page. This is the same syntax used to query records so you can double check which records you're about to delete by plugging that query into a get records request. – Nathan Hawe Sep 29 '20 at 15:43
  • @NathanHawe. Thanks alot – Nancy Moore Sep 29 '20 at 19:45
  • @NathanHawe Please I need your help at this issue here on stackoverflow.Thanks link https://stackoverflow.com/questions/64513539/issues-with-quickbase-api-call – Nancy Moore Oct 24 '20 at 13:00