Get business service dependencies with pdpyras

I just learned about pdpyras and would like to use it for the convenience it brings. One of my first tasks is to get the business service hierarchy we built in PD.

I am able to get the data via python requests from
(e.g. response = requests.request(“GET”, url, headers=headers))

Upon trying this in pdpyras…
df_bsvcs = pd.DataFrame(session.rget(’/service_dependencies/business_services/ABCD1EF’))

I receive the following PDClientError:
PDClientError: Cannot extract object; expected top-level property “ABCD1EF”, but could not find it in the response schema. Response body={“relationships”:[{“dependent_service”:{“id”:“ABCD1EF”,“relationships”:null,“type”:"business_servic

It’s probably my unfamiliarity with pdpyras. Appreciate any help.

Hello Emmanuel,

I think what is happening is that the response for /service_dependencies/business_services/ doesn’t return the id of the business service being queried in the response, which rget expects in order to create the dictionary.

I believe it would work OK if you just didn’t use the rget method.
This might help you :

Please review Basic getting and consider just constructing a dictionary with your own code rather than using rget . Of course this depends on your use case.



Glad you’ve found pdpyras! Here’s a simple example that may help you get started.

staticBS = 'P123456'

    response = session.get('/service_dependencies/business_services/'+staticBS)

    if response.ok:
        rels = response.json()['relationships']

    for svcDep in rels:
        print('---------START SERVICE DEP---------')

        relID = svcDep['id']

        depService = svcDep['dependent_service']

       # iterate here into business/technical dep relationship

        supService = svcDep['supporting_service']

       # iterate here into business/technical dep relationship

        print('---------END SERVICE DEP---------')

except pdpyras.PDClientError as e:


Thanks for your response and taking time to share an example.
Very helpful in moving me forward with pdpyras.

Thanks for pointing this out Chiedu.

For the record, to provide more details about why this happens: the r* and *_all methods (i.e. rget and iter_all) were built around certain patterns that hold true in most of the REST API resources but not for all of them (there are some newer endpoints that are exceptions to this). In this example, the URL structure /service_dependencies/business_services/{id} is a break from the pattern because the expected structure would have the second path node be an ID, i.e. /users/{id}/contact_methods.

If you receive the error “Cannot extract object” you should be using the plain get, post, put and delete methods instead.

See this note on how to distinguish which endpoints are supported: