This is the endpoint: https://api.openai.com/v1/files
The Api Key is configured.
The local file points to an accesible and readable pdf file.
vListFormDataPart = New List(Of UiPath.Web.Activities.Http.Models.FormDataPart) From {New UiPath.Web.Activities.Http.Models.FileFormDataPart(“{pdf filepath}”, “file”, “application/pdf”), New UiPath.Web.Activities.Http.Models.TextFormDataPart(“purpose”, “answers”)}
The response:
“StatusCode”: “BadRequest”,
“TextContent”: "
{
\n "error":
{
\n "message": "Additional properties are not allowed (‘2025-001120179.pdf’,
‘answers’ were unexpected)",\n "type": "invalid_request_error",\n "param": null,\n "code": null\n
}\n
}\n",
“BinaryContent”: “”,
“File”: null,
With this code:
’ Inputs:
’ vStrApiKey As String → API Key OpenAI
’ vStrArchivo As String → FilePath
’ vStrPurpose As String → “assistants”
’ in_Config(“API_ENDPOINT_SUBIDA”) → URL API
’ Output:
’ vStrResponse As String → JSON response
Dim client As New System.Net.Http.HttpClient()
Dim requestContent As New System.Net.Http.MultipartFormDataContent()
’ Add file
Dim fileBytes() As Byte = System.IO.File.ReadAllBytes(vStrArchivo)
Dim fileContent As New System.Net.Http.ByteArrayContent(fileBytes)
fileContent.Headers.ContentType = New System.Net.Http.Headers.MediaTypeHeaderValue(“application/octet-stream”)
requestContent.Add(fileContent, “file”, System.IO.Path.GetFileName(vStrArchivo))
’ Add purpose
Dim purposeContent As New System.Net.Http.StringContent(vStrPurpose)
requestContent.Add(purposeContent, “purpose”)
’ API Key
client.DefaultRequestHeaders.Authorization = New System.Net.Http.Headers.AuthenticationHeaderValue(“Bearer”, vStrApiKey)
’ Send POST request
Dim response As System.Net.Http.HttpResponseMessage = client.PostAsync(in_Config(“API_ENDPOINT_SUBIDA”).ToString, requestContent).Result