Edits history of script submission #22333 for ' Create single record (airtable)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    type Airtable = {
      apiKey: string;
    };
    
    type AirtableTable = {
      baseId: string;
      tableName: string;
    };
    export async function main(
      atCon: Airtable,
      atTable: AirtableTable,
      newRecord: object,
    ) {
      const url = `https://api.airtable.com/v0/${atTable.baseId}/${encodeURIComponent(
        atTable.tableName,
      )}`;
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          Authorization: `Bearer ${atCon.apiKey}`,
          "Content-Type": "application/json",
        },
        body: JSON.stringify({ fields: newRecord }),
      });
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`);
      }
    
      const createOne = await response.json();
    
      return createOne;
    }
    

    Submitted by hugo989 4 days ago