I have a script to read field numbers from a table, map these to CSV columns, determine if the record exists or not, then POST either a new record or an update to an existing record.
All the GET queries to the API work, but my efforts to POST with PowerShell fail with
Invoke-RestMethod : {“type”:“error”,“msg”:“The request is invalid. That’s all we know.”}
I’ve tried simplifying all the way down to a single field update to a single record with the same error.
Can anyone point out where I might be going wrong? Below is the pertinent lines of code:
$headers = @{}
$headers.Add(“X-Tadabase-App-id”, $appID)
$headers.Add(“X-Tadabase-App-Key”, $apiKey)
$headers.Add(“X-Tadabase-App-Secret”, $apiSecret)
$headers.Add(“Content-Type”, “application/x-www-form-urlencoded”)
$multipartContent = [System.Net.Http.MultipartFormDataContent]::new()
$stringHeader = [System.Net.Http.Headers.ContentDispositionHeaderValue]::new(“form-data”)
$dateFieldId = ($tableFields.fields | ?{$_.name -eq ‘Last Updated’}).slug
$stringHeader.Name = $dateFieldId
$stringContent = [System.Net.Http.StringContent]::new((Get-Date -Format “dd/MM/yyyy HH:mm”))
$stringContent.Headers.ContentDisposition = $stringHeader
$multipartContent.Add($stringContent)
Invoke-RestMethod “https://api.tadabase.io/api/v1/data-tables/$userDetailsTableID/records$specificRecordPath” -Method ‘POST’ -Headers $headers -Body $multipartContent
[DBG]: PS C:\Users\User>> “https://api.tadabase.io/api/v1/data-tables/$userDetailsTableID/records$specificRecordPath”
https://api.tadabase.io/api/v1/data-tables/q3kjZ2Vj6V/records
[DBG]: PS C:\Users\User>> $multipartContent.ReadAsStringAsync()
Result --73660bbf-ad8d-4fd2-80f7-864c20bacda7
Content-Type: text/plain; charset=utf-8
Content-Disposition: form-data; name=“field_712”
13/09/2021 17:19
--73660bbf-ad8d-4fd2-80f7-864c20bacda7--
Id : 28747
Exception :
Status : RanToCompletion
IsCanceled : False
IsCompleted : True
CreationOptions : None
AsyncState :
IsFaulted : False
AsyncWaitHandle : System.Threading.ManualResetEvent
CompletedSynchronously : False