Google Drive API: List all folders under shared drive - google-drive-api

Question on listing the folders under shared drive.
I was able to get successful response while calling the API below by passing query parameters as:
includeTeamDriveItems=true
q=‘0AATe_aghhsdfvbdfg’ in parents and mimeType = ‘application/vnd.google-apps.folder’
supportsAllDrives=true
API: https://developers.google.com/drive/api/v3/reference/files/list?apix_params=%7B%22includeTeamDriveItems%22%3Atrue%2C%22q%22%3A%22%270AATe_aghhsdfvbdfg%27%20in%20parents%20and%20mimeType%20%3D%20%27application%2Fvnd.google-apps.folder%27%22%2C%22supportsAllDrives%22%3Atrue%7D
Successful Response:
{
"kind": "drive#fileList",
"incompleteSearch": false,
"files": [
{
"kind": "drive#file",
"id": "1E-c0rNCQMlQvXNUGTKSWdPHBOwwzjtcf",
"name": "Integration",
"mimeType": "application/vnd.google-apps.folder",
"teamDriveId": "0AATe_aghhsdfvbdfg",
"driveId": "0AATe_aghhsdfvbdfg"
},
{
"kind": "drive#file",
"id": "1QOMRSPuE1msJJmyr3yJOMZsBrn3nrtAx",
"name": "Folder1",
"mimeType": "application/vnd.google-apps.folder",
"teamDriveId": "0AATe_aghhsdfvbdfg",
"driveId": "0AATe_aghhsdfvbdfg"
}
]
}
Question: From the response, it returns existing folders under the shared drive. Is it possible to also get all the sub folders under parent folders at once instead of having to pass parent folder ID under query parameters each time ? (e.g: To get all the sub folders under parent folder ‘Integration’)
Dilip

The folders just under the parent folder can be retrieved by the search query with one API call like below. In this case, 'folderId' in parents is used as the search query.
curl \
'https://www.googleapis.com/drive/v3/files?corpora=drive&driveId=driveId&includeItemsFromAllDrives=true&q=%27folderId%27%20in%20parents&supportsAllDrives=true' \
--header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
--header 'Accept: application/json' \
--compressed
And, when you want to retrieve the files under 2 folders, you can also use the following sample. In this case, 'folderIdA' in parents or 'folderIdB' in parents is used as the search query.
curl \
'https://www.googleapis.com/drive/v3/files?corpora=drive&driveId=driveId&includeItemsFromAllDrives=true&q=%27folderIdA%27%20in%20parents%20or%20%27folderIdB%27%20in%20parents&supportsAllDrives=true' \
--header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
--header 'Accept: application/json' \
--compressed
From your question, I think that you have already been done above.
In the current stage, all nested subfolders under the parent folder cannot be directly retrieved.
In this case, it is required to prepare a script.
I think that this thread will be useful.
Unfortunately, in the current stage, it seems that this is the current specification at Google side.
Note:
In the most cases, includeItemsFromAllDrives=true and supportsAllDrives=true can be used. But I had the some cases that corpora=drive and driveId=### are also required. So when in your shared Drive, the files cannot be retrieved, please try to use this.
References:
Files: list
Search for files and folders

Related

No model issue for IFC Models in the Viewer

Need help on the similar topic posted below:
Autodesk Forge Viewer gives empty model (no geometry) issue on IFC file that works in BIM360
As suggested in the article, I have added the required options for the translation, and the model creates the correct derivatives. But , still the Viewer shows the same error of "model is empty. there is no geometry for the viewer to show" Please suggest, if the Viewer also needs to be handled differently to load these "modern" conversion-based files. Thanks very much.
Thank you for your reproducible model. The translation result looks fine while using the modern conversion method. I replied to you via Forge Help. It contains a snapshot of my test.
So, could you have a try? This is the code example of how I send the translation request using the modern conversion method.
Note. if you want to override an existing translation result, please be sure to set the header parameter x-ads-force: true.
curl --location --request POST 'https://developer.api.autodesk.com/modelderivative/v2/designdata/job' \
--header 'Authorization: Bearer ' \
--header 'Content-Type: application/json' \
--header 'x-ads-force: true' \
--data '{
"input": {
"urn": "dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6bXlidWNrZXQvSUZDX0JydWVja2VfS2xpbmdlbmJlcmdfNC56aXA"
},
"output": {
"formats": [
{
"type": "svf",
"views": [
"3d"
],
"advanced": {
"conversionMethod": "modern"
}
}
]
}
}'
ref: https://forge.autodesk.com/en/docs/model-derivative/v2/reference/http/job-POST/#headers

copy contents from sample json file to index elastic aearch index json file

elastic search version i am using 6.6.1
i have created index by running following command
curl -XPUT http://localhost:9200/incident_422? -H 'Content-Type: application/json' -d #elasticsearch.json
i need to update the index file with sample json data.(sample.json)
{
"properties": {
"id185": {
"type": "byte"
},
"id255": {
"type": "text"
},
"id388": {
"type": "text"
}
}
}
I tried running the command
curl -XPUT http://localhost:9200/incident_422/mapping/_doc? -H 'Content-Type: application/json' -d #sample.json
but i get the error message saying that
{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Rejecting mapping update to [incident_422] as the final mapping would have more than 1 type: [mapping, doc]"}]
i have read somewhere that ELK 6 doesnt support more than two types.
Could anyone please tell me how this can be achieved without downgrading the version
This seems to related to the removal of mapping type, you need to specify the type name while indexing the documents.
try adding type to your index request aka http://localhost:9200/incident_422/<your-type-name> in your URL and it should solve the issue.

execute in bash command stored in variable [duplicate]

This question already has answers here:
Bash script: Use string variable in curl JSON Post data
(3 answers)
Closed 2 years ago.
I'm trying to script a mailing using a curl api (this is the base API, in mine the html part is changed with "xmessage":
curl -s \
-X POST \
--user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" \
https://api.mailjet.com/v3.1/send \
-H 'Content-Type: application/json' \
-d '{
"Messages":[
{
"From": {
"Email": "pilot#mailjet.com",
"Name": "Mailjet Pilot"
},
"To": [
{
"Email": "passenger1#mailjet.com",
"Name": "passenger 1"
}
],
"Subject": "Your email flight plan!",
"TextPart": "Dear passenger 1, welcome to Mailjet! May the delivery force be with you!",
"HTMLPart": "<h3>Dear passenger 1, welcome to Mailjet!</h3><br />May the delivery force be with you!",
"CustomCampaign": "SendAPI_campaign",
"DeduplicateCampaign": true
}
]
}'
My script look like this :
...
message=$(cat ./message.txt)
message=${message//"xdate"/$courseDate}
message=${message//"xcoursecode"/$courseCode}
message=${message//"xsubtitle"/$subtitle}
message=${message//"\r"/""}
message=${message//"\r\n"/""}
message=${message//"\n"/""}
message=${message//"\""/"\\\""}
message=${message//"'"/"&apos;"}
mailJet=$(cat ./mailjet.txt) # containing my API as described as above
mailJet=${mailJet//"xmessage"/$message}
echo $mailJet
eval $mailJet
the command "eval $mailJet" does not works but if I do a copy paste in the terminal of the "echo $mailJet" output my command works
The eval $mailJet give the following error :
{"ErrorIdentifier":"5cce36c5-373c-48ca-90b8-2b6bfc5df526","ErrorCode":"mj-0031","StatusCode":400,"ErrorMessage":"Request payload contains not valid UTF-8 encoded characters"}
Something that partially worked, was to put directly the mailJet.txt content in the script
but I'm struggling to find the syntax to replace the xmessage by what's in $message.
Like this it did not worked :
...
message=$(cat ./message.txt)
message=${message//"xdate"/$courseDate}
message=${message//"xcoursecode"/$courseCode}
message=${message//"xsubtitle"/$subtitle}
message=${message//"\r"/""}
message=${message//"\r\n"/""}
message=${message//"\n"/""}
message=${message//"\""/"\\\""}
message=${message//"'"/"&apos;"}
curl -s \
-X POST \
--user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" \
https://api.mailjet.com/v3.1/send \
-H 'Content-Type: application/json' \
-d '{
"Messages":[
{
"From": {
"Email": "pilot#mailjet.com",
"Name": "Mailjet Pilot"
},
"To": [
{
"Email": "passenger1#mailjet.com",
"Name": "passenger 1"
}
],
"Subject": "Your email flight plan!",
"TextPart": "Dear passenger 1, welcome to Mailjet! May the delivery force be with you!",
"HTMLPart": "$message", ## neither like this : "HTMLPart": "'$message'",
"CustomCampaign": "SendAPI_campaign",
"DeduplicateCampaign": true
}
]
}'
Whereas if I put any html stuff instead of $message in the curl api, the script run without any issue.
I'm stuck (and not a great bash coder or even coder at all)
Many thanks by advance for your help.
I think your problems start at
-d '{
This use of a single quote means that nothing in this section is interpreted by bash. "$message" later on will be treated as the text $ and message.
If this is the issue, then what you need to do is unquote around the variable names, but also double-quote arround them, so you write '"$message"' Or, if you need the double-quotes to appear inside the curl command "'"$message"'".
Note you can't have the ## comment either, but I assume you put that in for our benefit.

Complex object multpart json

I want to build a request in insomnia to upload person, documents and it's files
How can I put a multipart file inside a JSON object? I don't want to deal with string base64 because it's too big and too slow to travel over the network.
I have a rest api made with spring boot and kotlin that will receive this JSON file.
Here's some code for what I want to achieve:
curl --request POST \
--url http://localhost:8080/ \
--header 'content-type: multipart/form-data; boundary=--
-011000010111000001101001' \
--form 'person={
"first_name": "Foo",
"last_name": "Fighters"
}' \
--form 'document=[
{
"document_name": "test1",
"document_description":"test1",
"document_file": "multipart file1"
},
{
"document_name": "test2",
"document_description":"test2",
"document_file": "multipart file2"
},
{
"document_name": "testN",
"document_description":"testN",
"document_file": "multipart fileN"
}
]'
Where the key document_file value stands for the file itself, not a String.
Some pictures to make it clear:
Here is the overview of the multipart
Person detail:
Document detail:
I need to know what files are from what documents, and I can have 0 or many documents related to the person.
Therefore, that's why adding 1 file for each document I want to create won't work. It needs to be inside the object(just like presented in the images) that way I know that file-X is from document-X and vice-versa.
Thanks in advance!

Shopify fulfillment

The online shopify docs for fulfillment show this example:
POST /admin/orders/#{id}/fulfillments.json
{
"fulfillment": {
"tracking_number": null,
"line_items": [
{
"id": 466157049
}
]
}
}
The docs also say that not specifying an item id will cause all items to fulfill.
My postdata to that api endpoint reads:
{"fulfillment":{"tracking_number":null}}
This comes back:
{"errors":{"fulfillment":"can't be blank"}}
I have tried this:
{"fulfillment":{"tracking_number":null,"line_items":[{"id":300668234}]}}
which is a valid item id for my order. The same message comes back.
Ideas?
Are you setting your Content-Type to application/json?
Trying sending the same request using cURL
curl -X POST -H 'Content-Type: application/json' -d #fulfillment.json https://API_KEY:API_TOKEN#SHOP.myshopify.com/admin/orders/ORDER_ID/fulfillments.json
If that works, it means you aren't sending your request correctly.
curl -H "Content-Type: application/json" -X POST -d '{"fulfillment": {"tracking_number": "123456789","notify_customer": true}}' https://API_KEY:TOKEN#SHOP.myshopify.com/admin/orders/ORDER_ID/fulfillments.json
This is the working example of updating tracking number for an order. It took me a minute to realize that the ORDER_ID is the long form shopify order id. It should be about 9 to 10 digits.