SAP Knowledge Base Article - Public

3211962 - Uploading attachment through the OData Service "ServiceRequestAttachmentFolder" using the "DocumentLink" does not work well

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

  1. Use either the "https://api.sap.com/api/ticket/tryout" or "https://www.postman.com/"
  2. Connect to the tenant in question. For example, using Postman:
    1. Open postman and create a new request (GET)
      Step1.png
    2. 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.
        Step2.png
    3. Go to Authorization and select "Basic Auth", then enter the user credentials
    4. Next, we need to get the x-csrf-token:
      1. Go to Header -> under KEY enter "x-csrf-token" and value "fetch" -> Send
      2. When the response arrives, go to response header and copy the x-csrf-token
      3. Go to the Headers tab and paste the previously copied value
    5. Now that you are able to connect, go to the Body tab -> Raw and select the desired format (json, xml, txt, JavaScript or HTML)
    6. 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"
      }
    7. Click Send
    8. Go to your C4C tenant and open ticket 1234 -> attachments
    9. 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

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