I am trying to use RestSharp to call the outbound_email endpoint.
If I don’t include an attachment I am able to post to the end point successfully, however when I do include an attachment using the code below it fails.
var client = new
RestClient(outboundEmail);
var request = new RestRequest("", Method.Post);
request.AddHeader("Authorization", "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes(apiKey + ":X")));
string attachmentFilePath = filePath;
bytet] attachmentBytes = File.ReadAllBytes(attachmentFilePath);
request.AddHeader("Accept", "application/json");
request.AddHeader("Content-Type", "multipart/form-data");
request.AddFile("attachmentst]", attachmentBytes, file.pdf, "application/pdf");
request.AddParameter("email", myEmail);
request.AddParameter("subject", subject);
request.AddParameter("description", description);
request.AddParameter("status", status);
request.AddParameter("priority", priority);
request.AddParameter("email_config_id", emailConfigID);
var response = client.Execute(request);
It comes back with a bad request, stating
\"description\":\"Validation failed\",\"errors\":\{\"field\":\"email\\r\\n\",\"message\":\"Unexpected/invalid field in request\",\"code\":\"invalid_field\"},{\"field\":\"subject\\r\\n\",\"message\":\"Unexpected/invalid field in request\",\"code\":\"invalid_field\"},{\"field\":\"description\\r\\n\",\"message\":\"Unexpected/invalid field in request\",\"code\":\"invalid_field\"},{\"field\":\"status\\r\\n\",\"message\":\"Unexpected/invalid field in request\",\"code\":\"invalid_field\"},{\"field\":\"priority\\r\\n\",\"message\":\"Unexpected/invalid field in request\",\"code\":\"invalid_field\"},{\"field\":\"email_config_id\\r\\n\",\"message\":\"Unexpected/invalid field in request\",\"code\":\"invalid_field\"}]}"
I am able to get it working correctly in Postman, so I’m wondering if the file I am adding is in the wrong format or something, but couldn’t find anything when going through the API docs.