I have integrated an SAP CAP application with Ariba through punchout. At the end of this process, I create a Purchase Requisition as a result of the user’s cart. The issue arises when I try to attach a generated PDF containing the cart’s products to the requisition import SOAP web service; the attachment is always blank.
Steps Taken:
I generate the PDF using pdf-lib.
I include the generated PDF in the tag of the SOAP request.
Expected Outcome:
The PDF should be correctly attached and contain the list of products from the cart.
Actual Outcome:
The attached PDF in the successfully created PR in Ariba is always blank.
Code Snippet:
Here is the relevant code snippet:
const pdfDoc = await PDFDocument.create();
const page = pdfDoc.addPage([600, 400]);
page.drawText('Product list and details', { x: 50, y: 350 });
const pdfBytes = await pdfDoc.save();
const pdfBase64 = Buffer.from(pdfBytes).toString('base64');
// SOAP request snippet
const soapRequest = '
<urn:Attachments>
<urn:item>
<urn:Attachment>
<urn:Filename>Options.pdf</urn:Filename>
<urn:ContentType>application/pdf</urn:ContentType>
</urn:Attachment>
<urn:ExternalAttachment>true</urn:ExternalAttachment>
<urn:MappedFilename><xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" xop:contentType="application/pdf" href="cid:Options.pdf">${pdfBase64}</xop:Include></urn:MappedFilename>
</urn:item>
</urn:Attachments>';
const options = {
url: '/forwardRequest',
method: 'POST',
data: soapRequest,
headers: {
'Content-Type': 'text/xml;charset=utf-8',
'SOAPAction': '/Process Definition',
'type': 'application/xop+xml'
}
};
$.ajax(options)
.done(function (response, statusText, xhr) {
debugger;
if (xhr.status == 200) {
console.log('Raw result', response);
};
console.log('Message', xhr.status, statusText);
})
.fail(function (error) {
console.error('Error', error.status, error.statusText);
});
Additional Information:
The integration between SAP CAP and Ariba is working fine for other functionalities.
The PDF generation process using pdf-lib works correctly when tested independently.
The SOAP web service call succeeds, but the attachment remains blank.
Youssef Toumi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.