Help

Re: Checkbox field not updating as it cannot accept the value true

2060 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Lisa_Lemons
5 - Automation Enthusiast
5 - Automation Enthusiast

I’m hoping someone has run into this before and can help me out. I’m sure I just have a syntax error somewhere or something equally silly.

I’m using jQuery AJAX (I have to, I will explain why if anyone asks).

I am able to retrieve, post, and patch data for everything but my checkbox field. I have sent the value “true” with and without quotes.

Here is my code:

$.ajax({
  url: `${Airtable.API}/To%20Do/${recordId}`,
  type: 'PATCH',
  headers: {
    authorization: `Bearer ${Airtable.API_KEY}`,
    contentType: "application/json"
  },
  data: {
    "fields": {
      "Done": true // does not work as "true" or true
    }
  }
 })
.fail((error) => {
  console.error("There was an error processing your request:", error, error.responseText);
 })
.done((response) => {
   console.log(response);
 });

Here is the error:

responseJSON: {
    error: {
        {
            message: "Field Done can not accept value true"
            type: "INVALID_VALUE_FOR_COLUMN"
        }
}

For reference, this is a simple TODO table. The shape of the data is just:

Name: String,
Notes: String (Long Text),
Done: Boolean

8 Replies 8
Giovanni_Briggs
6 - Interface Innovator
6 - Interface Innovator

You are passing the string “true” not the boolean value true. Remove the quotes from true in your payload and you should be good to go!

data: {
        "fields": {
          "Done": true //use the boolean constant true not a string that spells "true"
        }
}

@Giovanni_Briggs

You are passing the string “true” not the boolean value true . Remove the quotes from true in your payload and you should be good to go!

Unfortunately that is not the case, as I noted I have tried to pass it with and without. I did update the code to show that I was passing it as a boolean though, as that is the main way I am trying to send it.

Lisa_Lemons
5 - Automation Enthusiast
5 - Automation Enthusiast

I also tried to add typecast true and that gets me the following error:

{"error":{"type":"INVALID_REQUEST_UNKNOWN","message":"Invalid request: parameter validation failed. Check your request data."}}

Here is the code with that typecast property set to true:

$.ajax({
  url: `${Airtable.API}/To%20Do/${recordId}`,
  type: 'PATCH',
  headers: {
    authorization: `Bearer ${Airtable.API_KEY}`,
    contentType: "application/json"
  },
  data: {
    "fields": {
      "Done": true 
    },
    "typecast": true  // Adding typecast: true does not work       
  }
})
.fail((error) => {
  console.error("There was an error processing your request:", error, error.responseText);
})
.done((response) => {
  console.log(response);
});
Giovanni_Briggs
6 - Interface Innovator
6 - Interface Innovator

I was using Postman to test and “true” doesn’t work where true does. For AJAX, can you try stringifying data? typecast shouldn’t be necessary in this case.

$.ajax({
  url: `${Airtable.API}/To%20Do/${recordId}`,
  type: 'PATCH',
  headers: {
    authorization: `Bearer ${Airtable.API_KEY}`,
    contentType: "application/json"
  },
  data: JSON.stringify({
      "fields": {
        "Done": true 
      }
    })
})
.fail((error) => {
  console.error("There was an error processing your request:", error, error.responseText);
})
.done((response) => {
  console.log(response);
});
Lisa_Lemons
5 - Automation Enthusiast
5 - Automation Enthusiast

@Giovanni_Briggs

I was using Postman to test and “true” doesn’t work where true does. For AJAX, can you try stringifying data? typecast shouldn’t be necessary in this case.

Thanks for messing with it. Wrapping the fields in JSON.stringify gives me an error because it cannot find fields. Moving it around, say to wrap the field itself, or just the word “true” also gives me errors, ones I’ve been running into.

I am presenting this as a demo for my class to play with it (I teach front end web development). So I’ve gone and changed it into a dropdown menu for now with the values “Yes” and “No”.

In the meantime though, this is starting to smell an awful lot like a bug!

openside
10 - Mercury
10 - Mercury

Hmm, your code looks correct, and I can assure you it does work. What happens if you use a 1 or 0 instead of true/false?

That’s cool you’re teaching Airtable in class. You should join a podcast on BuiltOnAir :slightly_smiling_face:

Lisa_Lemons
5 - Automation Enthusiast
5 - Automation Enthusiast

@openside

Blockquote Hmm, your code looks correct, and I can assure you it does work. What happens if you use a 1 or 0 instead of true/false?

Same thing.

That’s cool you’re teaching Airtable in class. You should join a podcast on BuiltOnAir :slightly_smiling_face:

Thanks! I will check that out :grinning_face_with_big_eyes:

Lisa_Lemons
5 - Automation Enthusiast
5 - Automation Enthusiast

I think I have insight into the problem, and it is definitely me.

I use a live server through Visual Studio Code or I serve through my file system. The students are very new to JS/jQuery, so I haven’t implemented any npm/webpack stuff. This is all pretty simple stuff.

I don’t have a self-signed certificate made yet, so my “live server” just serves at http://local-ip. It’s simple enough for most of my needs.

But ya’ll probably know what I’m getting at. Due to the limitations of what I show this class and my fake server, I have to use an browser extension to spoof Allow CORS. This prevents me from getting the CORS error so common with local hosting, and allows me to work without creating a self-signed certificate. As for working with Airtable’s API, this has been a solid solution to that problem until now.

Thanks to the investigative work by @Giovanni_Briggs and @openside I know that my code is correct and will submit booleans under the right circumstances. But something about my CORS submission prevents me from submitting any data that isn’t wrapped in a string.

So for now I shall stick with the drop down menu to keep things simple for my students. For anyone lucky enough to run into the same problem, you need to fix the path you’re serving from to be able to send data other than strings.

Hope that makes sense!