[SalesForce] Update an existing attachment’s body via REST Api

I'm trying to find a way to update an attachment's body from a custom visual force page I've created. I have the attachment ID but when I try to call a PATCH web request on the URL: http://appid.salesforce.com/services/data/v38.0/sobjects/Attachment/{attachmentId} I get the following http error:

BAD REQUEST: Unable to create/update fields: ParentId. Please check
the security settings of this field and verify that it is read/write
for your profile or permission set.

How can I update an existing attachment's body? I don't want to create a new attachment or anything like that.

The I execute the request is the following:

    var objectUrl = http://appid.salesforce.com/services/data/v38.0/sobjects/Attachment/0660L000000WLlH;
    xhr.open("PATCH", objectUrl);
    xhr.setRequestHeader("Authorization", "OAuth " + SFsessionId);
    xhr.setRequestHeader("X-PrettyPrint", "1");
    xhr.setRequestHeader("Content-Type", "application/json");
    xhr.setRequestHeader("Accept", "application/json");

where attachmentBody is:

var attachment = JSON.stringify({
          name: documentName,
          ContentType: "application/pdf",
          body: pdfAsBase64,
          ParentId: parentid,
          Description: "pdf data"


The problem is the ParentId: parentid. During updating it must not be included. Only once during creation.

Best Answer

Assuming you followed Insert or Update Blob Data, odds are, you specified a ParentId. ParentId must not be set after creation, as the field can only be set when you create a new Attachment; trying to reparent an attachment is not allowed.