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:Samplestorageapppaypalsample.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:Samplestorageapppaypalsample.pdf';
$input = [
'evidences' => [
[
'evidence_type' => 'PROOF_OF_FULFILLMENT',
'evidence_info' => [
'tracking_info' => [
'carrier_name' => "FEDEX",
'tracking_number' => '122533485'
]
],
'notes' => 'Test',
],
]
];
$client = new GuzzleHttpClient([
'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 GuzzleHttpPsr7MultipartStream($options['multipart']);
$request = new GuzzleHttpPsr7Request('POST', $url, $headers, $body, '1.1');
$modify['set_headers']['Content-Type'] = 'multipart/related; boundary=' . $request->getBody()->getBoundary();
$request = GuzzleHttpPsr7modify_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.
What could be the issue? Any ideas or suggestion would very much help, thanks.
question from:
https://stackoverflow.com/questions/65918020/paypal-customer-dispute-api-provide-evidence-always-returns-missing-or-invalid