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

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.

Related

How to create a secret-text type of credential for Jenkins using Jenkins API?

So far, I'm using the credentials plugin on Jenkins and I do a POST to {JENKINS_URL}/credentials/store/system/domain/_/createCredentials using a credentials.xml that looks like this:
<com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl>
<scope>GLOBAL</scope>
<id>my-test-cred</id>
<description>This is an example from REST API</description>
<username>xyz-test</username>
<password>
xyz-yay
</password></com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl>
and it successfully creates a credential of type username:password.
But suppose I want to create a credential of type secret-text which would hold a token or a secret, like say, a GitHub token, how can I make a credentials.xml for that kind? I've searched high and low and I cannot find a definitive guide here :-(
I used successfully the class from #rkparmar's proposal with XML format to create a secret text credential in Jenkins.
<org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl>
<scope>GLOBAL</scope>
<id>testID</id>
<secret>thisIsAtest</secret>
<description>TEST</description>
</org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl>
Agree! It is difficult to find xml to credential for secret-text. If you have way to get xml from .json than please find .json below to create credentials for secret-text
curl -X POST 'http://user:token#jenkins_server:8080/credentials/store/system/domain/_/createCredentials' \
--data-urlencode 'json={
"": "0",
"credentials": {
"scope": "GLOBAL",
"id": "myid",
"secret": "mysecret",
"description": "mydescription",
"$class": "org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl"
}
}

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

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'];

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.

Rest API Testing from commandline

I am preparing a SDK, and SDK as of now, does not have CI system separately.
I want to test some REST endpoints which should be available when the user uses SDK to create the software and try to run with our framework.
I have written all the manual steps in shell script and planning to put the script as crontab to run it every few hours.
Now, for rest end point testing, I was thinking of just using curl and checking if we getting data back. but this can turn into a lot of work,as we expand the functionality. I looked into frisby framework which kind of suits my needs.
Is there any recommendation for allowing me to test rest services when the framework software is started.
Probably swat is exactly what you need. Reasons :
This is DSL for web, rest services test automation
it uses curl command line API to create http requests
it is both DSL and command line tool to run test scenarios written on DSL
it is configurable both from bash style scripts and general configs
it is very easy to start with
probably in your case curl based test cases could be easily converted into swat DSL format
(*) disclosure - I am the author of swat.
I have created a very small bash script to test JSON APIs which might be useful. It uses jq and curl as dependencies. curl for making request and jq for JSON processing.It is only designed to test JSON APIs.
Link: api-test
Every API call you want to run is stored in a JSON file with format below:
{
"name": "My API test",
"testCases": {
"test_case_1": {
"path": "/path_1",
"method": "POST",
"description": "Best POST api",
"body": {
"value": 1
},
"header": {
"X-per": "1"
}
},
}
"url": "http://myapi.com"
}
To run a test case:
api-test -f test.json run test_case_1
api-test -f test.json run all # run all API call at once.
It will produce output in an organized way
Running Case: test_case_1
Response:
200 OK
{
"name": "Ram",
"full_name": "Ram Shah"
}
META:
{
"ResponseTime": "0.078919s",
"Size": "235 Bytes"
}
It also supports automated testing of API with jq JSON comparison and normal equality/subset comparisons.