Help with API calls for systems registered with Red Hat Subscription Management

Solution Verified - Updated -

Environment

  • Systems registered with Red Hat Subscription Management

Issue

  • There exists an API for RHN and for Red Hat Satellite
  • Where can I find documentation on the Subscription Manager API, especially for obtaining subscription management info from the Customer Portal?

Resolution

  • There is no supported API method yet. However, RHSM-web is backed by the Candlepin API.
  • REST API provides RHSM users a possible automation solution for virtual data centres and organizations that cycle through instances often.

    • Info on the Candlepin REST API can be found here.
    • Documentation on Candlepin here.
    • The project main page here.
    • The Candlepin code here.
    • And documentation on how to use it with the portal here
  • So, by referring to the Candlepin REST API for the API calls and documentation on how to use it with the portal for the URL part, we can create the API as mentioned in the diagnostic steps.

NOTE Some of the calls will not work since they are filtered, but some of the calls will work because we do consume some of the candlepin endpoints.

Diagnostic Steps

A couple of simple examples of using curl to retrieve JSON data from the API

  • Retrieve info about a consumer (authenticating using RHN username/password):
$ curl -s -u <rhn_username> -k https://subscription.rhn.redhat.com/subscription/consumers/<consumer_uuid> | python -mjson.tool
  • Retrieve info about the entitlements for a consumer (authenticating using RHN username/password):
$ curl -s -u <rhn_username> -k https://subscription.rhn.redhat.com/subscription/consumers/<consumer_uuid>/entitlements | python -mjson.tool
  • Retrieve all subscriptions for a consumer (authenticating using consumer cert/key):
$ curl --cert /etc/pki/consumer/cert.pem --key /etc/pki/consumer/key.pem -k 'https://subscription.rhn.redhat.com/subscription/pools?consumer=<consumer_uuid>&listall=true' | python -mjson.tool

Note In all the above cases the request is a GET request. The response is encoded in JSON format can be be processed further if desired. POST requests can be created with curl using the –data option (and in wget by using the –post-data option).

  • Delete the systems from portal
$ curl -i -X DELETE http://subscription.rhn.redhat.com/subscription/consumers/<consumer_uuid>
  • Update the entitlement information
$ curl -i POST http://subscription.rhn.redhat.com/subscription/entitlements/<entitlement_id>
  • Attach subscription to a system
$ curl -vku <rhn_username> -X POST 'https://subscription.rhsm.redhat.com/subscription/consumers/<consumer_uuid>/entitlements?pool=<subscription pool_id>&quantity=1'
  • Download manifest
curl -vku <rhn_username> 'https://subscription.rhsm.redhat.com/subscription/consumers/<consumer_uuid>/export' > manifest.zip

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

5 Comments

TYPO: python -mjson.tool

SHOULD BE : python -m json.tool

Link to candlepin api is now 404

Candlepin API now (2016.09.16) at http://www.candlepinproject.org/swagger/?url=candlepin/swagger-2.0.13.json#/ - let's see how long that lasts.

I don't think you should be promoting curl -k to disable https validation, if you perform the commands from a red hat registered system it's as easy as "curl --cacert /etc/rhsm/ca/redhat-uep.pem" to verify the ssl.

how do you find out what your "consumer_uuid" is? I've tried every possible number (contract number, customer number,...) that I could find in our account at access.redhat.com, but none of them worked. Is there perhaps a more up to date version of this documentation?