I'm trying to submit a PDF file as dispute evidence in the Paypal sandbox using the /v1/customer/disputes/" + dispute.ID +"/provide-evidence
end point. Whatever I try, the error message from Paypal shows as:
INVALID_EVIDENCE_FILE
I've verified that fileBytes
is a valid PDF file by saving it to disk just before posting, and it is. I've also tried sending a JPG as well but receive the same error.
The Paypal docs aren't much help for this issue:
https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_provide-evidence
And don't really provide any help as to how the document(s) should be posted. Likely I am not submitting the data properly, any help in pointing out what I might be doing wrong is much appreciated.
using (var httpClient = new HttpClient()){ httpClient.DefaultRequestHeaders.Authorization = AuthenticationHeaderValue.Parse($"Bearer {auth.access_token}"); using (var request = new HttpRequestMessage(HttpMethod.Post, $"{BaseUrl()}" + path)) { var form = new MultipartFormDataContent(); dynamic p = new { evidences = new List<object> { } }; string strData = JsonConvert.SerializeObject(p); var jsonPart = new StringContent(strData); jsonPart.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data"); jsonPart.Headers.ContentType = new MediaTypeHeaderValue("application/json"); form.Add(jsonPart); var byteContent = new ByteArrayContent(fileBytes, 0, fileBytes.Length); byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/pdf"); form.Add(byteContent, fileNameWithExtension); using (var response = await httpClient.PostAsync(request.RequestUri, form)) { strResponse = await response.Content.ReadAsStringAsync(); var statusCode = (int)response.StatusCode; if (statusCode is < 200 or >= 300) { throw new PaypalClientException(strResponse); } } }}