0

I can't manage to find a way to create a Google Forms in a specific directory.

All the forms I create are located at the top level of my Google Drive.

form = {
    "info": {
        "title": "My new form"
    },
}
# Prints the details of the sample form
result = form_service.forms().create(body=form).execute()
print(result)

I have tried to add the parents keyword but it doesn't work as expected (it is not listed in the Google Forms API documentation)

Is there a way to do that?

I can only think of using the form id created at the top level and assign a new parent target folder id.

I searched the documentation but I couldn't find a way to specify the parent folder at form creation.

1 Answer 1

0

The forms python library do not have a way to create the form in specific folder

YOu can use the drive API to set the folder https://developers.google.com/drive/api/guides/folder#create-file

And then create the form or any other file

try:
    # create drive api client
    service = build("drive", "v3", credentials=creds)

    file_metadata = {"name": "photo.jpg", **"parents": [folder_id]**} #the parents is the folder Id where you want to create the file
    media = MediaFileUpload(
        "download.jpeg", mimetype="image/jpeg", resumable=True
    )
    # pylint: disable=maybe-no-member
    file = (
        service.files()
        .create(body=file_metadata, media_body=media, fields="id")
        .execute()
    )
    print(f'File ID: "{file.get("id")}".')
    return file.get("id")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.