SAP Knowledge Base Article - Public

3497506 - How to Create Attachments Via Document Service API?

Symptom

Creation of attachment via document service API is not working. The following error might appear:

  • Document service unknown exception.

Environment

  • SAP Service Cloud v2
  • SAP Sales Cloud v2

Resolution

Steps to create the document with document-service API:

  1. Open an API Application.
  2. Fill authentication details.
  3. Select POST Method.
  4. Fill URL as https://{tenant_URL}/sap/c4c/api/v1/document-service/documents/
  5. Select JSON as body and fill as the example payload below:
    {"fileName":"Test.pdf",
     "category":"DOCUMENT","type":"10001"}
  6. Click on Run/Send.
  7. It will return 201 status.
  8. In the response, copy the following values: "id": "XXXXXXXXXXXXXXXXXXXXXXX" and "uploadUrl": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
  9. Create a new HTTP Request. Do not fill any authentication.
  10. Select PUT Method.
  11. Paste URL as the one you copied from uploadURL field.
  12. Select body as Binary file.
  13. Browse and upload the wanted attachment.
  14. Click on Run/Send.
  15. It will return 200 status.

Now the attachment was create. Please proceed to link the attachment to an entity. Lead will be used as an example.

* Make sure to use the same user ID to perform the POST and PATCH methods, or the PATCH operation will fail.

  1. Select GET operation.
  2. Fill authentication details.
  3. Set URL as https://{tenant_URL}/sap/c4c/api/v1/lead-service/leads/{lead_technical_ID}
  4. Click on Run/Send.
  5. In response, go to Headers and copy the value for Etag field.
  6. In the headers of the request, add a new line.
  7. Header should be If-Match.
  8. Value should be the one you copied from Etag field.
  9. Change method to PATCH.
  10. Paste below JSON payload:
     {
         "attachments": [
          {
            "id": "document ID you copied from previous step"
            }
        ]
         }
  11. For e-mail entity the attribute name changes, so please use the payload below:
  12.  "attachments": [
                {
                    "documentId": "document ID you copied from previous step"
                
                }
            ]
  13. Click on Run/Send.

After that, the attachment should be added to the specified record.

See Also

Document API Service

Keywords

Document, Document-service, Attachment, API, POST, PATCH, UploadURL , KBA , CEC-CRM-DOS , Document Service for SAP Sales/Service Cloud , How To

Product

SAP Sales Cloud and SAP Service Cloud Version 2 1.0