skip to Main Content

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);
            }
        }
    }
}

2

Answers


  1. According to PayPal’s documentation about sending "Evidence" for "customer-disputes", I think all the things that are sent should be a JSON structure, something like the image below that the content of your PDF file is embedded in the "documents" section as a "JSON.stringify()" string.

    Or if that "Evidence" file is not private and that company has a dedicated site and server, and it is possible in terms of security, upload that file somewhere on your server and then put the link that contains the "AccessID" in the "documents" section. For example like below:

    "documents": [
        {
            "name": "Evidence_12.pdf", 
            "url": "https://example.com/PayPalEvidences/?EvidenceId=12&AccessId=3583597257053jjgfr766"
        }
    ]
    

    It is noteworthy that the content of each document should not exceed 10 MB, and the total size of documents should not exceed 50 MB.
    It appears from your code that you put the PDF file in the request information separately from the JSON structure.

    Because the practical implementation of sending "Evidence" has different steps, including registering as a developer in PayPal, I haven’t tested it myself at the moment, but if I get the practical C# code in the coming days, I will add more details to the answer.

    Evidence

    Login or Signup to reply.
  2. The issue you’re encountering with PayPal’s INVALID_EVIDENCE_FILE error likely stems from how the multipart form data is being structured in the request. PayPal expects the evidence data to be formatted in a specific way when submitting files as part of a dispute. Here’s how you can correct your approach:

    Key Points to Address:

    • Multipart Form Data Structure: PayPal expects the evidence data and the file itself to be structured correctly within the multipart
      form data.

    • Proper Naming and Metadata: The JSON metadata (evidences) and the file need to be properly named and associated with each other.

    Correcting Your Code

    Here is a revised version of your code:

    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();
    
        // Metadata part
        var metadata = new
        {
            evidences = new[]
            {
                new
                {
                    evidence_type = "OTHER", // Adjust as necessary
                    notes = "Supporting document for the dispute"
                }
            }
        };
        string jsonData = JsonConvert.SerializeObject(metadata);
    
        var jsonPart = new StringContent(jsonData);
        jsonPart.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
        {
            Name = "input"
        };
        jsonPart.Headers.ContentType = new MediaTypeHeaderValue("application/json");
        form.Add(jsonPart);
    
        // File part
        var byteContent = new ByteArrayContent(fileBytes, 0, fileBytes.Length);
        byteContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
        {
            Name = "file",
            FileName = fileNameWithExtension
        };
        byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
        form.Add(byteContent);
    
        // Sending the request
        using (var response = await httpClient.PostAsync(request.RequestUri, form))
        {
            strResponse = await response.Content.ReadAsStringAsync();
            var statusCode = (int)response.StatusCode;
            if (statusCode < 200 || statusCode >= 300)
            {
                throw new PaypalClientException(strResponse);
            }
        }
    }
    

    }

    Explanation of Changes:

    1.JSON Metadata Part (input):

    • Naming: The metadata part must be named "input" in the form data.
    • Content: The metadata (evidences) is structured as an array with
      relevant evidence type and notes.

    2.File Part (file):

    • Naming: The file part must be named "file".

    • Content Disposition: The file name should be set properly using the
      FileName property in the ContentDispositionHeaderValue.

    Key Notes:

    • Evidence Type: Adjust the evidence_type field in the JSON metadata
      according to the specific type of evidence you are submitting. PayPal
      expects this to be one of their predefined types.

    • Error Handling: Ensure proper error handling and logging of responses
      for better debugging.

    By ensuring that both the JSON metadata and file parts are properly named and structured according to PayPal’s expectations, you should be able to submit the evidence without encountering the INVALID_EVIDENCE_FILE error.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search