Help

Re: Powershell and Airtable JSON

362 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Peter_Buck
5 - Automation Enthusiast
5 - Automation Enthusiast

Looking at the great PowerShell community posts on GitHub, I cannot find an example of a JSON body formatted for Airtable for multiple records. the following CURL works, APIkey removed. While I can format the JSON Airtable likes for a single record in the payload, I cannot seem to get the script write to wrap the JSON with the "records";[ values that Airtable wants. I currently am trying the following in Powershell but the JSON is not formatted correctly. Any tips?  Depth 3 is works for a single record. 

#now wrap with fields value Airtable wants
[PSCustomObject]$AirtableRecordsWrap = @{
records = $AirtableWrap
}

# Convert the object to a JSON string depth of 3 is required to get extra '
$jsonBody = $AirtableRecordsWrap | ConvertTo-Json -Depth 4

 

 

============this CURL script will work, with API removed====================

curl -X POST https://api.airtable.com/v0/appQxHpZdplpm8i6V/IPConnections -H "Authorization: Bearer [APIKEY]" -H "Content-Type: application/json" 
--data '{
"records": [
    {
    "fields":  {
                       "Local Process":  "GoogleDriveFS",
                       "Remote IP Address":  "2607:f8b0:4005:814::200a",
                       "Hostname":  "sfo03s32-in-x0a.1e100.net",
                       "Location":  "Mountain View-United States-CA-Google LLC"
                   }
    },
    {
    "fields":  {        
                       "Local Process":  "msedge",
                       "Remote IP Address":  "2600:1406:d400::1738:32b",
                       "Hostname":  "g2600-1406-d400-0000-0000-0000-1738-032b.deploy.static.akamaitechnologies.com",
                       "Location":  "San Jose-United States-CA-Akamai International B.V."
                   }
     },
     {
    "fields":  {     
                       "Local Process":  "msedge",
                       "Remote IP Address":  "2603:1036:307:48df::2",
                       "Hostname":  "Unable to resolve hostname",
                       "Location":  "San Jose-United States-CA-Microsoft Corporation"
                   }
      },
      {
    "fields":  {     
                       "Local Process":  "GoogleDriveFS",
                       "Remote IP Address":  "2607:f8b0:4005:80e::200a",
                       "Hostname":  "nuq04s39-in-x0a.1e100.net",
                       "Location":  "Mountain View-United States-CA-Google LLC"
                   }
      },
      {
    "fields":  {     
                       "Local Process":  "GoogleDriveFS",
                       "Remote IP Address":  "2607:f8b0:4005:80e::200a",
                       "Hostname":  "nuq04s39-in-x0a.1e100.net",
                       "Location":  "Mountain View-United States-CA-Google LLC"
                   }
       },
       {
    "fields":  {     
                       "Local Process":  "msedge",
                       "Remote IP Address":  "2603:1036:2400::22",
                       "Hostname":  "Unable to resolve hostname",
                       "Location":  "San Francisco-United States-CA-Microsoft Corporation"
                   }
       },
       {
    "fields":  {     
                       "Local Process":  "msedge",
                       "Remote IP Address":  "2603:1036:2400::22",
                       "Hostname":  "Unable to resolve hostname",
                       "Location":  "San Francisco-United States-CA-Microsoft Corporation"
        }
        },
        {
    "fields":  {     
                       "Local Process":  "OneDrive",
                       "Remote IP Address":  "20.189.173.12",
                       "Hostname":  "Unable to resolve hostname",
                       "Location":  "San Francisco-United States-CA-Microsoft Corporation"
                   }
         }
    ]
}'
2 Replies 2
Alexey_Gusev
12 - Earth
12 - Earth

Hi,
I never tried using curl to create records, but I can just confirm that your string parsed to object, able to be used for multiple create records. The output is IDs of new created records.

Alexey_Gusev_2-1704443587447.png

 


Try to add typecast parameter (see example in API docs)?

Thank you Alexey for looking. Typecast would be useful for automatic data conversion from string values. My issue remains getting the JSON formatted correctly. The example you parsed was hand created to be correct. I am trying to create the Record block in the JSON from my data source and cannot figure it out.