API PATCH with JQuery Ajax: error 422 with integers (SOLVED)


#1

Hi!

I can’t undestand this error. Here is my code using JQuery and Ajax:

$(document).ready(function(){
    x = 1;
    $("button").click(function(){
              $.ajax({
          url: "https://api.airtable.com/v0/appHQ1ATs3SjuAC20/XXXXXX?api_key=XXXXXX",
          type: 'PATCH',
          dataType: "json",
          data: {
            "fields" : {
              "FIELD": VALUE
            }
          },
        });
    });
});  

When I replace FIELD with the proper field name, and the data type of that field is a string, and replace VALUE with a string (e.g., “hola”), I can update the field through the API. But when replace FIELD with the proper name of an integer field, and replace VALUE whit a number (e.g., 1234), I get this error:

PATCH https://api.airtable.com/v0/appHQ1ATs3SjuAC20/xxxxxx/?api_key=xxxxxxx 422 (Unprocessable Entity)

I tried a lot of things but nothing works.

Anyone can help me?

Thanks


#2

Nadie apareció, pero logré resolverlo solo. Me faltaba poner el parámetro

contentType : "application/json",

Y en caso de que el valor se pase a través de un textfield, hay que encerrar la variable en un parseINT(), así:

parseInt($(SELECTOR).val())