Paypal Customer Dispute API - Provide Evidence always returns MISSING_OR_INVALID_REQUEST_BODY

dexterb2992
Contributor
Contributor

I've been trying to upload a pdf file when providing an evidence to Paypal Disputes in the Claim Stage after verifying that the dispute case has the /provide-evidence on its HATEOAS links, the curl code below works in the CLI:

 $ curl -v -X POST https://api.sandbox.paypal.com/v1/customer/disputes/PP-D-12345/provide-evidence \
   -H "Content-Type: multipart/related" \
   -H "Authorization: Bearer {AccessToken}" \
   -F 'input={"evidences":[{"evidence_type": "PROOF_OF_FULFILLMENT", "evidence_info": {"tracking_info": [{"carrier_name": "FEDEX", "tracking_number": "123456789"}]}, "notes": "Test"}]};type=application/json' \
   -F 'file1=@D:\Sample\storage\app\paypal\sample.pdf'

However when converted to PHP, either using curl or guzzle the API returns VALIDATION_ERROR - MISSING_OR_INVALID_REQUEST_BODY, I've tried almost every possible approach, but the error is consistent.

Using Guzzle: (trying to copy the working curl above as much as possible, since Guzzle can't send multipart/related request, I had to modify the content-type manually).

$pdf = 'D:\Sample\storage\app\paypal\sample.pdf';

$input = [
  'evidences' => [
    [
      'evidence_type' => 'PROOF_OF_FULFILLMENT',
      'evidence_info' => [
        'tracking_info' => [
          'carrier_name' => "FEDEX",
          'tracking_number' => '122533485'
        ]
      ],
      'notes' => 'Test',
    ],
  ]
];

$client = new \GuzzleHttp\Client([
    'base_uri' => 'https://api.sandbox.paypal.com',
    'timeout'  => 2.0,
    'version' => 1.1
]);

$options = [
  'headers' => [
    'Authorization' => "Bearer $token",
  ],
  'multipart' => [
      [
          'name'     => 'input',
          'contents' => json_encode($input),
          'headers'  => ['Content-Type' => 'application/json']
      ],
      [
          'name'     => 'file1',
          'contents' => fopen($pdf, 'r'),
          'filename' => 'sample.pdf',
          'headers'  => ['Content-Type' => 'application/pdf']
      ],
  ]
];

$url = '/v1/customer/disputes/'.$disputeId.'/provide-evidence';

$headers = isset($options['headers']) ? $options['headers'] : [];
$body = new \GuzzleHttp\Psr7\MultipartStream($options['multipart']);
$request = new \GuzzleHttp\Psr7\Request('POST', $url, $headers, $body, '1.1');

$modify['set_headers']['Content-Type'] = 'multipart/related; boundary=' . $request->getBody()->getBoundary();

$request = \GuzzleHttp\Psr7\modify_request($request, $modify);

$response = $client->send($request);

The guzzle code above still return {VALIDATION_ERROR - MISSING_OR_INVALID_REQUEST_BODY} and same result when I just do a normal multipart/form-data request.

 

I also tried doing the post request without the pdf file with PHP but same error, it only works on CLI or on Paypal APEX tool. What could be the issue? Any ideas or suggestion would very much help, thanks.

Login to Me Too
2 REPLIES 2

yzsr
New Community Member

it's working with java 

this is sample code to upload a file for evidence 

 

HttpPost httpPost = new HttpPost(URI.create(PaypalUtils.getDomain(dictData) + "/v1/customer/disputes/" + evidenceRequestObj.getDisputeId() + "/provide-evidence"));
httpPost.addHeader("authorization", PaypalUtils.getAccessToken(dictData, redisTemplate.opsForValue()).getTokenString());
MultipartEntity entity = new MultipartEntity();
##upload tracking evidence
entity.addPart("evidences", new StringBody(JSON.toJSONString(evidenceRequestObj), ContentType.getByMimeType("application/json")));

 

##upload file evidence
## this tempFile is uploaded from browser , i save it to disk on my server , then use addPart method to set as part of post param
entity.addPart("evidence-file", new FileBody(tempFile));

#execute request 
httpPost.setEntity(entity);
CloseableHttpResponse execute = httpClient.execute(httpPost);
String s = IOUtils.toString(execute.getEntity().getContent());

 

Login to Me Too

fazleyrabby
Contributor
Contributor

Hi I was trying to figure out how to attach a file in dispute api endpoints. I have tested this and its working.

 

 

use GuzzleHttp\Client;

$request_string = '{"evidences":[{"evidence_type":"' . $data['evidence_type'] . '","evidence_info":{"tracking_info":[{"carrier_name":"' . $data['carrier_name'] . '","tracking_number":"' . $data['tracking_number'] . '"}]},"notes":"' . $data['note'] . '"}]}';
 
$client = new Client();
$response = $client->post("https://api-m.sandbox.paypal.com/v1/customer/disputes/{dispute_id}/provide-evidence", [
'headers' => [
'Authorization' => 'Bearer {access_token}',
],
'multipart' => [
[
'name' => 'input',
'contents' => $request_string,
'headers' => [
'Content-Type' => 'application/json',
],
],
'name' => 'file1',
'contents' => fopen('/your-image-path/image.png', 'r'),
],
]);
$statusCode = $response->getStatusCode();
$responseData = json_decode($response->getBody(), true);
return [
     'success' => true,
     'code' => $statusCode,
     'data' => $responseData,
 ];

 

 

Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.