Sharepoint is giving me this message which I can't interpret.

"Microsoft.SharePoint.Client.InvalidClientQueryException","message": {...see below...}" is not valid."}}}"

URL: https://{entitychanged}.sharepoint.com/{siteChanged}/_api/Web/GetFolderByServerRelativeUrl('{siteChanged}/#arguments.libraryPath#/#arguments.folderName#')/Files/add(url='#arguments.filename#';overwrite=true;)/@TargetFileName='#arguments.filename#'

Error: {"error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"en-US","value":"The expression \"Web/GetFolderByServerRelativeUrl('/{siteChanged}/{folder name(with space, not %20)}/C88-8888')/Files/add(url='Budget C88-8888.xlsm';overwrite=true;)/@TargetFileName='Budget C88-8888.xlsm'\" is not valid."}}} I have tried a number of 'urls':

{... []_api/Web/GetFolderByServerRelativeUrl('/sites/path/part/item/foldername/C88-8888')/Files/add(url='Budget%20C88-8888.xlsm';overwrite=true;) ...}

{... [] _api/Web/GetFolderByServerRelativeUrl('/sites/path/part/item/foldername')/Files/add(overwrite=true;url='/sites/path/part/item/foldername/#arguments.filename#')/?@TargetLibrary='#arguments.libraryPath#'@TargetFileName='#arguments.filename#'"; ...}

and various versions, including the line immediately above with 'filename')?@TargetLibrary (The / present or not)

I am using :

  • Accept: application/json; odata=verbose
  • content-type: application/xml
  • header=binaryStringRequestBody
  • I am using the Digest
  • I am using the content length, access token, and digests.
  • posting x-http-methods PUT and POST.
  • body of: binary and toBase64(binary)

The target structure is [site]/{Library}/{Folder}/(Adding file here)

I am having success with getMetaData, @value for content, but for the life of me I can't figure out why the uploading of files is being rejected.

I noticed that the last step had spaces in the url, using URLEncodedFormat() to replace spaces with %20 did NOT resolve the issue. G

  • Can you post what is the error message which I see you excluded? I am talking about the text between the curly brackets: "message": {...} is not valid.
    – Mihail
    Commented Jun 16, 2016 at 21:26
  • I included several examples right below the error message. I get the same message for each of the items between the brackets. I removed the first part of the url to protect my employer. Thanks. \n<br /> I am getting most things, its just the post/putting of files that I am having trouble with getting it to work. Commented Jun 17, 2016 at 12:52
  • Ok, I was able to use basically the same code as above to upload/attach an Excel file to a List/List Item. So why does upload work for lists but not folders. (Obviously I had to use /Lists/Items(1)/AttachmentFiles/Add) Commented Jun 22, 2016 at 13:15

1 Answer 1


Well, it looks like I was doing a few things wrong.

The ColdFusion language I use passes arguments as a structure, the order does not matter. This appears to not be the case for Sharepoint. ex: files/add(overwrite=true,url='#arguments.filename#') is not the same as files/add( url='#arguments.filename#'; overwrite=true; )

I also had [;] semicolons where I needed [,] commas.

All extraneous spaces need to be removed, other spaces need [%20] encoding. Dashes and underlines if encoded show up encoded, wrong. just replace spaces.

I hope this helps someone else.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.