Copy file to another folder with REST API in OneDrive pro (Sharepoint) - rest

I'm trying to copy a file located in user's personal folder (OneDrive Pro) using REST API. The resulting link seems to become too long (???) and server returns 400 BadRequest: The length of the URL for this request exceeds the configured maxUrlLength value.
Url looks like this (HTTP verb is POST):
https://<company>-my.sharepoint.com/personal/<user>_<company>_onmicrosoft_com/_api/Web/GetFileByServerRelativeUrl('/personal/<user>_<company>_onmicrosoft_com/Documents/<Folder>/<Folder with guid-like name>/<filename>.pdf')/copyto(strnewurl='/personal/<user>_<company>_onmicrosoft_com/Documents/<Same folder>/<another guid-like name>/<same filename>.pdf',boverwrite=true)
Any help or advice on how to overcome this is highly appreciated.

Just in case if anyone else will face this problem and you will have unique id in your SP.
If first part, which is
GetFileByServerRelativeUrl('/personal/<user>_<company>_onmicrosoft_com/Documents/<Folder>/<Folder with guid-like name>/<filename>.pdf')
will be replaced with GetFileById(uniqueId) the limitation would be satisfied and copy will succeed.

Related

Using a public access token for GitHub with Neo4j

I'm trying to use LOAD CSV with a CSV file stored in GitHub. It works fine with the 10 minute, temporary token you get when viewing the raw file, but I want something that's more persistent, as I need to be able to deploy this to multiple environments. Ten minutes just won't cut it.
I figured a private access token would be the way forward, but (once again) GitHub's spectacularly poor quality documentation made this much harder than it should be.
I set up a private access token with the repo and read:org permissions and with this I can get at my files using CURL, e.g.
curl -s https://<my_token>#raw.githubusercontent.com/<my repo>/<path>/<my file>.csv
This works fine and I see the contents of my test file.
But if I try to navigate to that URL I just get a 404 error and if I use it in Neo4j with a LOAD CSV statement, I get an error couldn't load the external resource at:.
I'm basically doing this:
LOAD CSV WITH HEADERS FROM '<URL that worked in CURL>' AS row
...and it fails miserably.
Where:
LOAD CSV WITH HEADERS FROM '<URL for raw file from GitHub with 10 minute token>' AS row
works fine, so I know I can access external files, i.e. files not in the import directory.
Is this just a failing with GitHub, or am I doing something wrong?
Although I hate answering my own questions, I left this kicking around a while and nobody came back with anything that helped.
I now know a whole lot more about public access tokens than I ever wanted to, but it was all worthwhile, as it helped me get around this issue.
There's an apoc.load.jsonParams function that accepts bearer tokens. From here it didn't take too much work to get this working the same way that LOAD CSV had done.
There was one last gotcha though, I soon discovered that the URLs for the repository can't include spaces or other non-alphanumeric characters, but that's a small price to pay for success?
So this doesn't work:
LOAD CSV WITH HEADERS FROM 'https://<my_token>#raw.githubusercontent.com/<my repo>/<path>/<my file>.csv' AS row...
Instead I had to use:
CALL apoc.load.jsonParams("https://raw.githubusercontent.com/<my repo>/<path>/<my file>.json", {Authorization: "Bearer <token>"}, null) YIELD value WITH value AS row...
There's an equivalent apoc.load.csvParams procedure, but I never tested this.

Creating an attachment in SharePoint from Microsoft Forms Response - Get File Content using path not working

I am trying to add contents and an attachment from a Form to a SharePoint list. However, the Get file content using path action in my flow is failing. The error I'm receiving says "Unauthorized" and in the file content box, I receive the following message:
"status": 401,
"message": "A potentially dangerous Request.Path value was detected from the client (?).",
"source": "apidod.connectorp.svc.ms"
The file path is as follows (minus the front of the path):
sites/HSMWINGATLANTIC_Supply_Requests/Shared%20Documents/Forms/AllItems.aspx?newTargetListUrl=%2Fsites%2FHSMWINGATLANTIC%5FSupply%5FRequests%2FShared%20Documents&viewpath=%2Fsites%2FHSMWINGATLANTIC%5FSupply%5FRequests%2FShared%20Documents%2FForms%2FAllItems%2Easpx&id=%2Fsites%2FHSMWINGATLANTIC%5FSupply%5FRequests%2FShared%20Documents%2FApps%2FMicrosoft%20Forms%20Fairfax%2FVehicle%20Rental%20Request%2FSupporting%20Documents&viewid=55590b8b%2D4994%2D4e8b%2D804b%2D24f4774c21e920220815 - HSM-40 Truck Request for 15 AUG 20_Charles Power 1.pdf
c.d.power
For that Get File content using path you would need a relative path without the site url part. You can actually extract the correct path with an expression.
In the example below I retrieve the link property from the Attachment question answer value. I use a json function to turn it into an array, since Microsoft returns a string value for some reason ;)
After that I use nthindexof to determine at which forward slash (starting position of string) I need to slice with a slice function, in this case the 7th instance, which is index 6.
This should retrieve the part which we need for a get file content using path action. With a decodeUriComponent function I make sure the %20 is turned back into space characters.
Make sure you update the question id to your question id.
decodeUriComponent(slice(json(outputs('Get_response_details')?['body/re67e0cfcd95d488593347d93f2728204'])[0]['link'], nthindexof(json(outputs('Get_response_details')?['body/re67e0cfcd95d488593347d93f2728204'])[0]['link'], '/', 6)))
I found the solution to the issue. This wasn’t working because it is a group form and form responses are sent to the group’s SharePoint site; not the user’s OneDrive. Therefore, the Get file content action should be using the SharePoint connector instead of OneDrive.

how to upload file in Advanced Rest Client

I am trying to use post method in this add Attachment to SAP ODATA service (URL), then I am getting the error
"Key 'file_name' not given".
I used Multippart/form-data and given file_name (with single cotes and with out it) still the error is same.
Any idea where to give file_name?
Thanks.

Github Search API filename only returns 1 result

I'm trying to search for all projects (or at least several thousand) from the github search API. I've gotten everything else to work, except the filters on filename.
For example, sending the following request to the search API only returns 1 result:
https://api.github.com/search/code?q=django+in:requirements.txt+filename:requirements.txt+language:python+org:openmicroscopy
Likewise, sending the following
https://api.github.com/search/repositories?q=filename:Makefile&per_page=100
only returns 1 result as well. I'm willing to bet that there is more than 1 repo on github with a Makefile or a dependency on Django. I must be doing something wrong, but I can't seem to figure out what it is.
According to this post on Github's developer site to support the expected volume of requests, they have added restrictions to code queries which requires us to specify set of users, organizations, or repositories with the query. Read about considerations for code search at this link
Now, about your search API requests, in the first one the in qualifier is provided with file name requirements.txt which is wrong.
The documentation states that in should be provided with file to restrict the search to the file contents, path to restrict the search to the file path or both.
Like this, in:file, in:path, in:file,path
So, if you want to search in file contents the correct API call should be
https://api.github.com/search/code?q=django+in:file+filename:requirements.txt+org:openmicroscopy
I removed the language qualifier since you are searching in a .txt file and doing this improved the result.
Checkout this URL, it will produce same results on the website,
https://github.com/search?utf8=%E2%9C%93&q=org%3Aopenmicroscopy+django+in%3Afile+filename%3Arequirements.txt&type=Code
Your second query is a repository search, it cannot not take a filename as qualifier you should see this link for available qualifiers.

fields parameter not working with graph batch requests

I have moved my graph requests to a batch, and noticed that when more than one request parameter is passed, the request fails with error 400.
For example, this works when not batched:
facebook->api('/me/friends?limit=5000&fields=id')
But when the same graph url is moved to a batch request, I get a 400 error.
When I remove one of the parameters (either fields or limit), it works:
/me/friends?fields=id
/me/friends?limit=10
Anyone knows if this is a bug or should be like this for some reason?
Finally found the answer to my problem. It appears that the & char must be escaped with %26 in order for this to work.
So my code sample should be:
facebook->api('/me/friends?limit=5000%26fields=id')
Wish this was documented...