1

I am trying to list out projects using resourcemanager api. I am using the below code.

from google.cloud import resourcemanager
from google.cloud.resourcemanager import ProjectsClient
from google.oauth2 import service_account
path_json_file = "C:\\Users\\######\\Downloads\\dev-####-analyt-datal-svc- db.json"
credentials = service_account.Credentials.from_service_account_file(path_json_file)
client =resourcemanager.ProjectsClient(credentials=credentials)
print(client)
request = resourcemanager.ListProjectsRequest(
   parent="###-amea-fldr/###-amea-analytics-fldr/##-amea-analytics-dev-fldr",
)
page_result = client.list_projects(request=request)
print(page_result)

I am using service account authentication. It has resourcemanager.projects.list permission also.

But I am getting the below error.

raise _InactiveRpcError(state)
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
status = StatusCode.INVALID_ARGUMENT
details = "Request contains an invalid argument."
debug_error_string = "{"created":"@1658894641.118000000","description":"Error received 
from peer ipv6:[2404:6800:4007:809::200a]:443","file":"src/core/lib/surface/call.cc","file_line":967,"grpc_message":"Request contains an invalid argument.","grpc_status":3}"

Is this due to any error in the value passed to the argument "parent"?

Whether the way I have called the list_projects method is correct?

1 Answer 1

1

Yes, I think so.

See the definition of parent in APIs Explorer for Cloud Resource Manager v3 projects.list where you can try the API method (for your parameters) in the browser.

The parent resource can be tricky but, the example cited on this page is folder/{folder}.

I don't know because I don't have access to an org but you may be able to repeat the path i.e. /folder/{parent-folder}/folder/{child-folder}.

Try permutations in the APIs Explorer.

If it works there, it'll work using the (any) client library.

Sign up to request clarification or add additional context in comments.

2 Comments

folder/{project id of parent} worked. Thank you
I'm pleased to hear it!

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.