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:
- Open an API Application.
- Fill authentication details.
- Select POST Method.
- Fill URL as https://{tenant_URL}/sap/c4c/api/v1/document-service/documents/
- Select JSON as body and fill as the example payload below:
{"fileName":"Test.pdf",
"category":"DOCUMENT","type":"10001"} - Click on Run/Send.
- It will return 201 status.
- In the response, copy the following values: "id": "XXXXXXXXXXXXXXXXXXXXXXX" and "uploadUrl": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
- Create a new HTTP Request. Do not fill any authentication.
- Select PUT Method.
- Paste URL as the one you copied from uploadURL field.
- Select body as Binary file.
- Browse and upload the wanted attachment.
- Click on Run/Send.
- 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.
- Select GET operation.
- Fill authentication details.
- Set URL as https://{tenant_URL}/sap/c4c/api/v1/lead-service/leads/{lead_technical_ID}
- Click on Run/Send.
- In response, go to Headers and copy the value for Etag field.
- In the headers of the request, add a new line.
- Header should be If-Match.
- Value should be the one you copied from Etag field.
- Change method to PATCH.
- Paste below JSON payload:
{
"attachments": [
{
"id": "document ID you copied from previous step"
}
]
} - For e-mail entity the attribute name changes, so please use the payload below:
- "attachments": [
{
"documentId": "document ID you copied from previous step"
}
] - Click on Run/Send.
After that, the attachment should be added to the specified record.
See Also
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