-2

I am trying to call below API using python. is there any solution for this?

GET https://cloudresourcemanager.googleapis.com/v2/folders

I am able to get projects list by using google-python-client library[GET https://cloudresourcemanager.googleapis.com/v1/projects]. Below is the sample code

credentials = service_account.Credentials.from_service_account_file(
filename='service_accounts.json',
scopes=['https://www.googleapis.com/auth/cloud-platform'])

service = discovery.build('cloudresourcemanager', 'v1', credentials=credentials)

But in google-python-client library to list folders is not there

How can I call through request library [a sample code] for this API (GET https://cloudresourcemanager.googleapis.com/v2/folders). I am getting problem in authentication of API.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • Yous question is pretty broad. Which folders do you want to list? Google Cloud Platform have many products inside and many of them use folders so you will need to specify which one are you interested in. The API that you are using is for Resource Management, that means that in your case you are interested in list all the folders of your organization (this folders contains projects inside of them)? Second, you can call any API with python just by using the [request library](https://realpython.com/api-integration-in-python/). Please provide us with more explanation on what do you want to achieve – Chris32 May 17 '20 at 10:38
  • @Chris32 Thanks for your comment, I have added more details to my comment. Can you please help how to authenticate GCP API through python request library. For one API sample code will be fine – Pravin Kumar Singh May 17 '20 at 12:58

1 Answers1

1

You need to use the cloudresourcemanager v2 for accessing to the folders

service = discovery.build('cloudresourcemanager', 'v2', credentials=credentials)

Your authentication mode is correct. Be sure that the service account as enough permission, I mean folder viewer and Organisation viewer of the folders that you request.

guillaume blaquiere
  • 66,369
  • 2
  • 47
  • 76