Sending SQL Server Data to Airtable Using REST API POST Request

Need Help with API Integration from SQL Server to Airtable

I have a SQL Server 2019 database with a table called GameStats that contains player performance data. The table structure looks like this:

CREATE TABLE GameStats (
    GameMode            varchar(25),
    GameModeDescription varchar(50),
    TotalPlayers        varchar(15),
    Username            varchar(30),
    FinalScore          nvarchar(25),
    EnemiesDefeated     varchar(20),
    HitPercentage       varchar(40),
    HealthLost          varchar(25),
    PlayTime            varchar(35),
    Losses              varchar(40),
    RecordedDate        datetime
);

I successfully tested sending data to Airtable using this curl command:

curl -X POST \
https://api.airtable.com/v0/appXYZ123/PlayerStats \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
  "records": [
    {
      "fields": {
        "GameMode": "Demo Post",
        "GameModeDescription": "Survival arena desert map",
        "TotalPlayers": 2,
        "Username": "TestUser123",
        "FinalScore": 85000,
        "EnemiesDefeated": 750,
        "HitPercentage": 87.5,
        "HealthLost": 45,
        "Losses": 2
      }
    }
  ]
}'

The curl method works perfectly and I can see the records appear in my Airtable base. However, I need to automate this process directly from SQL Server. How can I make POST requests to external APIs from within SQL Server? Are there built-in functions or do I need to use stored procedures with specific components?

SSIS is another solid option here. You’d create a package with a Script Task using C# for the HTTP POST requests to Airtable’s API. Way better error handling and logging than command line stuff. I’ve built similar integrations - SSIS grabs data from SQL tables, converts to JSON, then posts to external APIs. You get much more control over data flow and can schedule it easily through SQL Server Agent. Only downside is needing SSIS installed on your server, but it’s usually more reliable than shell commands in production.

I’ve dealt with this exact thing for years. What worked best for me was using SQL Server’s built-in sp_OACreate and sp_OAMethod procedures to make HTTP requests directly.

Just create a stored procedure that builds the JSON payload from your GameStats table and sends it via XMLHTTP object. Here’s the basic structure:

DECLARE @Object INT
DECLARE @ResponseText VARCHAR(8000)

EXEC sp_OACreate 'MSXML2.XMLHTTP', @Object OUT
EXEC sp_OAMethod @Object, 'open', NULL, 'POST', 'https://api.airtable.com/v0/appXYZ123/PlayerStats', 'false'
EXEC sp_OAMethod @Object, 'setRequestHeader', NULL, 'Content-Type', 'application/json'
EXEC sp_OAMethod @Object, 'setRequestHeader', NULL, 'Authorization', 'Bearer YOUR_TOKEN'
EXEC sp_OAMethod @Object, 'send', NULL, @JsonData

The tricky part? Building the JSON from your table data. I usually create a function that formats the records with all the nested structure Airtable expects.

This keeps everything within SQL Server - no SSIS or external assemblies needed. Just make sure Ole Automation Procedures are enabled on your server.

I’ve used this for pushing data to various APIs and it’s been pretty reliable. Only downside is JSON formatting gets messy with complex data structures.

CLR integration’s worth a shot if you want everything in SQL Server. Write a C# assembly for the HTTP requests and register it as a stored procedure. I did this for a project where we pushed inventory data to multiple external systems. You get full control over HTTP client config, headers, and error handling - no need for external tools or SSIS packages. You’ll need to enable CLR integration and mark the assembly as EXTERNAL_ACCESS for network calls. Performance’s been solid, and you can call it from triggers or scheduled jobs. Just handle auth tokens securely in the assembly code.

yep, xp_cmdshell is perfect for running curl in SQL Server! just remember to enable it via sp_configure first. i often put the curl POST in a stored procedure - makes API calls super easy. used it lots already!