Oracle Cloud Infrastructure - General

Get Involved. Join the Conversation.

Topic

    Karthik Varma
    How to get the all compartments in tenancy through API ?
    Topic posted September 3, 2019 by Karthik VarmaSilver Medal: 2,000+ Points, tagged Developer Tools 
    31 Views, 1 Comment
    Title:
    How to get the all compartments in tenancy through API ?
    Content:

    I need the root compartment info as well as all other compartments in tenancy.

    Right now, I am using ListCompartments API for fetching all compartments & GetCompartment API for root compartment.

    Is there a API that returns all the compartments including root compartment?

    Comment

     

    • Richard Garsthagen

      Hi,

      The RootCompartmentID is the same as the Tenancy OCID, so you do not need to query that.

      When you set compartmentIdInSubtree to true when you ListCompartments on the Root you will get all compartments. If you are using SDK like python, make sure to use the addictional oci.pagination.list_call_get_all_results to get all pages in cause you have too many compartments that do not fit in one respond back.