How to upload file to Google drive with Postman using multipart? - rest

How could I upload file to Google Drive using Google Drive API with Postman?
I also want to set file's name and parent directory.
What have I done:
I try to upload file with following properties:
But I get 403 error:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "parseError",
"message": "Parse Error"
}
],
"code": 400,
"message": "Parse Error"
}
}

I have resolved my problem, using answer on this question: How to send application/json data along with file in postman multipart/form-data post request?.
Solution
1) create file for upload to Google Drive: test.txt;
2) create file upload-options.json with file's metadata properties in json format:
{
"name": "my-uploaded-file.txt",
"parents": ["<parent-directory-id>"]
}
3) add two form-data fields:
first - upload-options.json
second - test.txt

you should consider about permission scope of your app.
add line code below help you access full control of google driver api
const SCOPES = ['https://www.googleapis.com/auth/drive'];

Related

Script lab custom functions feature does not work

When I try to access script lab custom functions feature I am greeted with message.
Script lab -> funtions
So the issue is not even in some particular function, the whole feature does not work.
Error:
{
"stack": "RichApi.Error: There was an internal error while processing the request.\n at new n (https://appsforoffice.microsoft.com/lib/beta/hosted/excel-win32-16.01.js:26:235928)\n at n.o.processRequestExecutorResponseMessage (https://appsforoffice.microsoft.com/lib/beta/hosted/excel-win32-16.01.js:26:299150)\n at https://appsforoffice.microsoft.com/lib/beta/hosted/excel-win32-16.01.js:26:297255",
"message": "There was an internal error while processing the request.",
"name": "RichApi.Error",
"code": "GeneralException",
"traceMessages": [],
"innerError": null,
"debugInfo": {
"code": "GeneralException",
"message": "There was an internal error while processing the request.",
"errorLocation": "CustomFunctionManager.register",
"statement": "v.register(...);",
"surroundingStatements": [
"var workbook = context.workbook;",
"var v = Microsoft.ExcelServices.CustomFunctionManager.newObject();",
"// >>>>>",
"v.register(...);",
"// <<<<<"
],
"fullStatements": [
"Please enable config.extendedErrorLogging to see full statements."
]
},
"httpStatusCode": 500
}
I've had this issue. I think I've seen there are differences between 2019 standalone and Office 365 subscriptions and the office js scripts that run. In my case, I was logged into a 365 enterprise subscription which reproduces the same error described. So what I did as a work-around was simply log out. And then register the function, and then log back in again. The registered function continues to work after log in.

Why using Google Cloud Drive Rest API file.list can not get all the files?

I am using the following CURL command to retrieve all my google drive files, however, it only list a very limited part of the whole bunch of files. Why?
curl -H "Authorization: Bearer ya29.hereshouldbethemaskedaccesstokenvalue" https://www.googleapis.com/drive/v3/files
result
{
"kind": "drive#fileList",
"incompleteSearch": false,
"files": [
{
"kind": "drive#file",
id": "2fileidxxxxxxxx",
"name": "testnum",
"mimeType": "application/vnd.google-apps.folder"
},
{
"kind": "drive#file",
"id": "1fileidxxxxxxx",
"name": "test2.txt",
...
}
token scope includes
https://www.googleapis.com/auth/drive.file
https://www.googleapis.com/auth/drive.appdata
Using the Android SDK also facing the same issue.
Any help would be appreciated.
Results from files.list are paginated -- your response should include a "nextPageToken" field, and you'll have to make another call for the next page of results. See documentation here about the files list call. You may want to use one of the client libraries to make this call (see the examples at the bottom of the page)
I have the same problem when try to get list of files in Google Drive folder. This folder has more than 5000 files, but API return only two of them. The problem is -- when files in folder shared with anyone with a link, in fact it isn't shared with you until you open it. Owner of this folder must specify you as viewer.

Github REST API full example

I would like to create a new file in the my github repository by using github REST API. I've found following link, but honestly I don't understand it((
As I understand, I could do POST
url: https://api.github.com/repos/MyUserName/MyRepositoryName
headers:
Accept: application/vnd.github.v3+json
body:
{
"message": "my commit message",
"committer": {
"name": "My name",
"email": "my email"
},
"content": "base64encoded"
}
But it doesn't work. Could you please, write
1) which url should I call
2) which headers this request should contains
3) what body should be
You were close:) Lets assume, that
1) your login: YourUsername
2) your access token: 123a321
3) repository to be updated: YourRepo
4) file to be created: file.txt
5) folder that will contains new file: f1/f2
According to those assumptions your request should be following:
type : PUT
url : https://api.github.com/repos/YourUsername/YourRepo/contents/f1/f2/file.txt
headers :
{
"Content-Type" : "application/vnd.github.v3+json",
"Authorization" : "token 123a321"
}
body :
{
"message": "my commit message",
"committer": {
"name": "My name",
"email": "my email"
},
"content": "base64encoded"
}
UPD
If you write in java, you can use GitHubFileAPI library, that I recently pushed to the maven central repository.
Solution: In order to perform action on github api you can use curl
according to Github doc:
first make sure you have specific privileges and authentication token generated to your account in order to interact with Github api:
profile Settings -> Developer Settings -> Personal access tokens -> Generate new token
the command should be in http PUT method on path /repos/:owner/:repo/contents/:path
The required params for editing or adding new files (according to api)
message (String), Content (String) and sha(String), additional params are branch(String) commiter(String) and author(String)
Lets perform some curl message in order to perform your action, the simple formula for this case would be:
curl --user <userName>:<token>
--data '{"key":"value"}'
--header <HeaderType>
--request <HTTPMethod>
<fullURL>
for demonstration lets fill some details:
curl --user johnDoe:abc123!##
--data '{"message":"my message","content":"my content","sha":"abcjfhtenf736gd843ji43903"}'
--header Content-Type:application/json
--request PUT
https://api.github.com/repos/MyOrganization/MyCoolApp/contents/app/models
Verify on Github the content has been inserted correctly to your branch

Upload a file to my github repo from postman

I would like to upload a file to my Github repo from Postman. What I have tried is:
Generate token from PAT: https://github.com/settings/tokens.
Method PUT URL: https://github.com/username/test2/info/lfs/objects/cd00e292c5970d3c5e2f0ffa5171e555bc46bfc4faddfb4a418b6840b86e79a2
Body is a 1 MB file.
I am receiving the following error: Your browser did something unexpected. Please contact us if the problem persists.
According to the API Reference you can't simply PUT a file to that URL. Rather, you need to encode the file as Base64, and put it within a JSON object with the following inputs:
{
"message": "my commit message",
"committer": {
"name": "Scott Chacon",
"email": "schacon#gmail.com"
},
"content": "bXkgbmV3IGZpbGUgY29udGVudHM="
}

Google Storage API - Retrieve object with "/" in name

When I try to retrieve an object with a "/" in the name I get all of the file information and metadata in the response, but the link to the file itself just points to "not found". This applies to both in my code, and using the API Explorer on their website.
For example, a file named "testfolder/test.txt". It shows up in the Developer Console correctly as a pseudo-folder named "testfolder/" and a file inside named "test.txt", but when do a Get on "testfolder/test.txt", or List with prefix of "testfolder/" I run into the issue mentioned above.
I can retrieve the object file fine in gsutil and from the console. I can also retrieve the object file fine with the API if I use a symbol other than "/". It's just something about the "/" causing the link from the API response to not point to the file correctly.
Request:
GET https://www.googleapis.com/storage/v1/b/dschaffertestbucket/o/testfolder%2Ftest.txt?key={YOUR_API_KEY}
Response:
200 OK
{
"kind": "storage#object",
"id": "dschaffertestbucket/testfolder/test.txt/1429992872601000",
"selfLink": "https://www.googleapis.com/storage/v1/b/dschaffertestbucket/o/testfolder%2Ftest.txt",
"name": "testfolder/test.txt",
"bucket": "dschaffertestbucket",
"generation": "1429992872601000",
"metageneration": "1",
"contentType": "application/octet-stream",
"updated": "2015-04-25T20:14:32.600Z",
"storageClass": "STANDARD",
"size": "14",
"md5Hash": "vLrQ6JkgmdfYKJKKN1ebFQ==",
"mediaLink": "https://www.googleapis.com/download/storage/v1/b/dschaffertestbucket/o/testfolder%2Ftest.txt?generation=1429992872601000&alt=media",
"owner": {
"entity": "user-00b4903a971fb6d48e9e442442b7892dfc55f81ce026106122cb58989d926f00",
"entityId": "00b4903a971fb6d48e9e442442b7892dfc55f81ce026106122cb58989d926f00"
},
"crc32c": "Qcfj8Q==",
"etag": "CKjLz8miksUCEAE="
}
In this article you can find that Cloud Storage doesn't have a file hierarchy like Windows and Linux, and that 'gsutil' and Cloud Storage APIs simply give the illusion of one.
In your case it would be easier to just avoid including the "/" character in your file names, or use a different character instead.