I want to create a new record with attachments in batch processing
Answer¶
Please use the "Record Creation API".
Overview¶
If you want to create records that include attachments in batch processing, use the "Record Creation API". Set the contents described in "JSON Data Layout: Item" in the "Attachments" object of the data to be posted.
Code Samples¶
PowerShell¶
Add-Type -AssemblyName "System.Web"
$error.Clear()
$requestUrl = "http://servername/api/items/2/create"
$apiKey = "af14A56RE68ssa320..."
$file = Get-Item "C:\Work\Test.pptx"
trap [Net.WebException] { continue; }
try{
$contentType = [System.Web.MimeMapping]::GetMimeMapping($file.FullName)
$base64filelist = New-Object System.Collections.ArrayList
[void]$base64filelist.Add(@{
Name = $file.Name
ContentType = $contentType
Base64 = [Convert]::ToBase64String([System.IO.File]::ReadAllBytes($file.FullName))
})
$json = @{
ApiKey = $apiKey
Title = "Test"
AttachmentsHash = @{
AttachmentsA = $base64filelist
}
}
$requestBody = $json | ConvertTo-Json -Depth 3
$res = Invoke-RestMethod -Uri $requestUrl -ContentType "application/json" -Method POST -Body ${requestBody}
Write-Output $res
}
catch {
Write-Output $_.Exception
}
if ($error.Count -gt 0)
{
Write-Output $error[0].ErrorDetails.Message | ConvertFrom-Json
}