DISCUSSION
Google Drive API v3: Create Folder
CLOUD DRIVE APIs COMPARISON
Other cloud drive APIs when creating a folder, including Box API and Dropbox API, both return a conflict error if a folder of the same name already exists in parent folder.
However, Google Drive API by default allows creating folders of the same name.
QUESTION
Is there a way to return conflict error if trying to create a folder of the same name within Google Drive parent folder?
If I take the approach using API to search for folder by name first, then create folder if not exists, then this could result in a possible race condition by a parallel process doing the same task in creating a unique folder by name.
EXAMPLE
Google Drive API create folder call in curl
curl "https://www.googleapis.com/drive/v3/files" \
--request POST \
--verbose \
--write-out 'HTTPSTATUS:%{http_code}' \
--silent \
--header "authorization: Bearer [** ACCESS TOKEN **]" \
--header "cache-control: no-cache" \
--header "content-type: application/json; charset=utf-8" \
--header "Accept: application/json" \
--data '{ \
"mimeType":"application\/vnd.google-apps.folder", \
"name": "[** FOLDER NAME **]", \
"parents": ["root"] \
}'
Each call creates a new folder in Google Drive parent folder with unique folder id, however, same folder name. I wish to avoid this:
Success [HTTP status: 200]
{
"kind": "drive#file",
"id": "1mpy2-TVeZDTL8vZ6fKHTyoGoFHX-18EN",
"name": "TEST",
"mimeType": "application/vnd.google-apps.folder"
}
...
Success [HTTP status: 200]
{
"kind": "drive#file",
"id": "1iqYnEWOVFcWO3jWX1IgIv2wxtGVYruQX",
"name": "TEST",
"mimeType": "application/vnd.google-apps.folder"
}
I appreciate any assistance in getting a single call approach to either return conflict error or auto-renaming.