I'm trying to upload evidence file by the documentation of PayPal API (https://developer.paypal.com/docs/api/customer-disputes/v1/)
But I get error 400 - INVALID_REQUEST, MISSING_OR_INVALID_REQUEST_BODY.
I do not understand what I'm doing wrong. This is part of the code that produces form-data:
const str = {
evidences: [
{
evidence_type: "PROOF_OF_FULFILLMENT",
evidence_info: {
tracking_info: [
{
carrier_name: "FEDEX",
tracking_number: "122533485"
}
]
},
notes: "Test"
}
]
}
const data = JSON.stringify(str);
const formData = new FormData();
formData.append('input', data);
formData.append('type', "application/json");
formData.append('file1', fileBuffer, {
filename: "@maor.pdf"
});
And this is the log of the request:
{
method: 'post',
headers: {
'Content-Type': 'multipart/related; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW',
Authorization: 'Bearer XXXXXXXXXXX'
},
body: FormData {
_overheadLength: 364,
_valueLength: 75083,
_valuesToMeasure: [],
writable: false,
readable: true,
dataSize: 0,
maxDataSize: 2097152,
pauseStreams: true,
_released: false,
_streams: [
'----------------------------736530077015435126960318\r\n' +
'Content-Disposition: form-data; name="input"\r\n' +
'\r\n',
'{"evidences":[{"evidence_type":"PROOF_OF_FULFILLMENT","evidence_info":{"tracking_info":[{"carrier_name":"FEDEX","tracking_number":"122533485"}]},"notes":"Test"}]}',
[Function: bound ],
'----------------------------736530077015435126960318\r\n' +
'Content-Disposition: form-data; name="type"\r\n' +
'\r\n',
'application/json',
[Function: bound ],
'----------------------------736530077015435126960318\r\n' +
'Content-Disposition: form-data; name="file1"; filename="@maor.pdf"\r\n' +
'Content-Type: application/pdf\r\n' +
'\r\n',
<Buffer 25 50 44 46 30 20 6f 62 6a 0a 3c 3c 2f 50 61 67 65 0a 2f 50 61 72 65 6e 74 20 31 20 30 20 52 0a 2f 4d 65 64 69 ... 74855 more bytes>,
[Function: bound ]
],
_currentStream: null,
_insideLoop: false,
_pendingNext: false,
_boundary: '--------------------------736530077015435126960318'
}
}
What am I doing wrong?