Symptom
- Your organization is planning on using the "" to upload attachments from a local path
- The attachments are uploaded and added to the ticket, but when the user opens such attachment it is either blank or corrupted
Environment
- SAP Cloud for Customer
- SAP Cloud for Service
- SAP Cloud for Sales
Reproducing the Issue
- Use either the "https://api.sap.com/api/ticket/tryout" or "https://www.postman.com/"
- Connect to the tenant in question. For example, using Postman:
- Open postman and create a new request (GET)
- Enter the tenant URL including the path of the OData service + the ObjectID you need to use.
- For example, https//myTenant.crm.ondemand.com/sap/c4c/odata/v1/c4codataapi/ServiceRequestCollection(%27OBJECTID%27)/ServiceRequestAttachmentFolder.
- The OBJECTID needs to be replaced with the actual ID.
- Go to Authorization and select "Basic Auth", then enter the user credentials
- Next, we need to get the x-csrf-token:
- Go to Header -> under KEY enter "x-csrf-token" and value "fetch" -> Send
- When the response arrives, go to response header and copy the x-csrf-token
- Go to the Headers tab and paste the previously copied value
- Now that you are able to connect, go to the Body tab -> Raw and select the desired format (json, xml, txt, JavaScript or HTML)
- In this case, we will be using Json, and use the following example, assuming "0279690046081EECB2DFAA7408DA1D32" is the actual ObjectID referenced. Values marked in blue are variables that would change based on demand:
{"ParentObjectID": "0279690046081EECB2DFAA7408DA1D32","ServiceRequestID": "1234","TypeCode": "10001","MimeType": "standard/attachment","Name": "Test.pdf","CategoryCode": "2","DocumentLink": "C:/Users/ZYZ/AppData/Local/test.pdf"} - Click Send
- Go to your C4C tenant and open ticket 1234 -> attachments
- Download and open "test.pdf"
- The file does not open and displays error saying it is corrupted or
- Opens but there is no information (it is blank)
Cause
Although the "DocumentLink" parameter would work to upload the file/attachments to the attachmentFolders, the actual content cannot be guaranteed as there is no conversion process
Resolution
- Instead of using the "DocumentLink" during the upload process, the file should be converted to Binary
- The "Binary" parameter should be used in the payload. For example:
{"ParentObjectID": "0279690046081EECB2DFAA7408DA1D32","ServiceRequestID": "1234","TypeCode": "10001","MimeType": "standard/attachment","Name": "Test.pdf","CategoryCode": "2","Binary": "[copy and paste the binary code from the Test_PDF_Binary_Example.txt"} - If you would like to test converting another PDF file, you could visit the following site: https://base64.guru/converter/encode/pdf (for testing only)
See Also
- Service Request Attachment
- Service Request Attachment Folder Help Document
- 2458877 - Post Attachment Using OData Services
- 3141762 - Error code: Out of Memory,When trying to execute the Odata call for Service Request Attachment
- 2738573 - Incorrect Attachment Name from Service Request Displayed in Odata
- 3210178 - Error Message When Trying To Upload Attachment Using OData From Local Folder
- 3051223 - Binary Content for Word Document is Missing in Attachment Collection of any Object
Keywords
Odata Services, , KBA , LOD-CRM-SRP-API , Ticket API & Odata , LOD-CRM-INT-API , OData API (C4C Only) , How To
Product
SAP Cloud for Customer add-ins 1905 ; SAP Cloud for Customer add-ins 2020 ; SAP Cloud for Customer add-ins 2021 ; SAP Cloud for Customer add-ins 2022
Attachments
Test_PDF_Binary_Example.txt |