Bulk Software Suggestion via File Upload
Perform the following steps to send bulk Software Suggestions via file upload.
To send bulk Software Suggestions via file upload:
1. | Open preferred API client or tool to initiate the request. |
2. | Proceed with software suggestion APIs using the authenticated session or token: |
Request Type |
Description |
||||||||||||||||||||||||
API |
/api/upload-suggest-software/ |
||||||||||||||||||||||||
Method |
POST |
||||||||||||||||||||||||
Parameters |
Specify the following parameters in the Body:
Specify the following parameters in the Header:
|
||||||||||||||||||||||||
Response |
Response: {'saved': True} |
3. | After entering the above parameters, click Send to submit the request. |
PowerShell Script for Bulk Software Suggestion via File Upload
Below is a sample PowerShell script to send bulk Software Suggestion via File Upload:
Note:Make sure that the file does not contain more than 100 products at a time.
# PowerShell script to upload a CSV file to the Secunia API using multipart/form-data
$token = "XXXXXXXX"
$url = "https://api.app.secunia.com/api/upload-suggest-software/"
$filePath = "C:\Users\filename\code\secunia\app\software-suggestion\softsuggestion.csv"
# Create HTTP client and multipart form
Add-Type -AssemblyName System.Net.Http
$client = New-Object System.Net.Http.HttpClient
$client.DefaultRequestHeaders.Add("Authorization", "Token $token")
$form = New-Object System.Net.Http.MultipartFormDataContent
# Add form fields
$form.Add([System.Net.Http.StringContent]::new(","), "separator")
$form.Add([System.Net.Http.StringContent]::new("true"), "has_header")
$form.Add([System.Net.Http.StringContent]::new("product name"), "column_name")
$form.Add([System.Net.Http.StringContent]::new("product version"), "column_version")
$form.Add([System.Net.Http.StringContent]::new("url"), "column_url")
$form.Add([System.Net.Http.StringContent]::new("xxxx@xxxx.com"), "email")
$form.Add([System.Net.Http.StringContent]::new("xyz"), "comment")
# Add file
$fileStream = [System.IO.File]::OpenRead($filePath)
$fileContent = New-Object System.Net.Http.StreamContent($fileStream)
$fileContent.Headers.Add("Content-Type", "text/csv")
$form.Add($fileContent, "file", [System.IO.Path]::GetFileName($filePath))
try {
$response = $client.PostAsync($url, $form).Result
$result = $response.Content.ReadAsStringAsync().Result
if ($response.IsSuccessStatusCode) {
Write-Host "File successfully uploaded. Response:" $result
} else {
Write-Host "Error occurred while uploading the file: $($response.StatusCode)"
Write-Host "Response content:" $result
}
}
finally {
$fileStream.Dispose()
$client.Dispose()
}