Help

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

Topic Labels: API
4435 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Carlos_Mario_Co
5 - Automation Enthusiast
5 - Automation Enthusiast

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

1 Reply 1
Carlos_Mario_Co
5 - Automation Enthusiast
5 - Automation Enthusiast

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())