Using SharePoint 2013 REST API, I am trying to attach a simple text file to a list's item.
jQuery.ajax({
url: web.get_url() + "/_api/web/lists/GetByTitle('List1')/items(1)/AttachmentFiles/add(FileName='readme.txt')",
type: "POST",
headers: {
"body": "Contents of file.",
"content-length": 17,
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
success: doSuccesRestAPIAddAttachment,
error: doErrorRestAPIAddAttachment
});
I get the following error:
500:Internal Server Error
<?xml version="1.0" encoding="utf-8"?><m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><m:code>-2147024883, Microsoft.SharePoint.SPException</m:code><m:message xml:lang="en-US">The data is invalid. (Exception from HRESULT: 0x8007000D)</m:message></m:error>
Can anyone tell me what I am doing wrong?
Thanks.