He folks, I was looking for information on accessing the web API from python. Between other info in this list the https://vda.li/en/posts/2015/05/28/talking-to-freeipa-api-with-sessions/ blog post and a little trial and error I got it working. The following python script logs in with a username and password then retrieves all the users in the development group and prints the uid.
I hope this helps some folks out, and saves some time. *#! /usr/bin/env python *__author__ = *'michaelluich' *author_email = *'[email protected] <[email protected]>'*, *import *requests*import *json baseurl = *'https://identity1.corp.actifio.com/ipa/session/ <https://identity1.corp.actifio.com/ipa/session/>' * *# Fill in your details here to be posted to the login form. *payload = { *'user'*: *'USERNAME'*, *'password'*: *'PASSWORD' *} *# Use 'with' to ensure the session context is closed after use. **with *requests.Session() *as *s: *#Login to the server * headers = {*'referer'*: *'https://identity1.corp.actifio.com/ipa/ <https://identity1.corp.actifio.com/ipa/>'*, *"Content-Type" *: *"application/x-www-form-urlencoded"*, *"Accept" *:*"text/plain"*, } p = s.post(baseurl+*"login_password"*, verify=False, data=payload, headers=headers) *# print the html returned or something more intelligent to see if it's a successful login page. * *if *p.status_code != 200: *print **"Login Problem" * exit(77) *# Get the user list. ** # The payload information can be found by running ipa -vv user-find. * payload = { *"id"*: 0, *"method"*: *"user_find"*, *"params"*: [ [ *#null * ], { *"all"*: *"false"*, *"in_group"*: [ *"development" * ], *"no_members"*: *"false"*, *"pkey_only"*: *"false"*, *"raw"*: *"false"*, *"version"*: *"2.156"*, *"whoami"*: *"false" * } ] } headers = {*'referer'*: *'https://identity1.corp.actifio.com/ipa/ <https://identity1.corp.actifio.com/ipa/>'*, *'Content-Type'*: *'application/json'*, *'Accept'*: *'applicaton/json'*, } r = s.post(baseurl+*"json"*, verify=False, data=json.dumps(payload), headers=headers) userJson=json.loads(r.text) *for *object *in *userJson[*'result'*][*'result'*]: *print *object[*'uid'*] -- <http://www.actifio.com/> *Michael Luich* *Senior DevOps **Engineer* *e* [email protected] 333 Wyman Street, Waltham, MA 02451 <http://twitter.com/actifio> <http://www.linkedin.com/company/399246> <https://plus.google.com/102870897962348937868/posts> <http://www.youtube.com/user/actifio> <http://www.actifio.com/> *Manage, access, and protect your data with a single platform that saves you time, money, and complexity.*
-- Manage your subscription for the Freeipa-users mailing list: https://www.redhat.com/mailman/listinfo/freeipa-users Go to http://freeipa.org for more info on the project
