univ-of-utah-marriott-library-apple / python-jamf

`python-jamf` is a library for connecting to a Jamf Server. It maps Jamf Pro records to a Record class. It is the basis for the `jctl` tool to automate patch management & packages and many other items.
MIT License
55 stars 16 forks source link

how to format put for specific ID of computer and static group IP #30

Closed grainofric3 closed 3 years ago

grainofric3 commented 3 years ago

so far i get the computers for a user (sometimes singular, sometimes multiple), but im trying to figure out the appropriate api.put command for it.

i usually work in bash so i know there the command ends with "$serial" https://JSS.jamfcloud.com/JSSResource/computergroups/id/{id} -X PUT >", but now sure how to translate it to python.

uurazzle commented 3 years ago

Hi @grainofric3 :

Thanks for your feedback and interest in our project.

Sorry, to be clear is your question specific to using the python-jamf or jctl tools?

Or is it general usage of the Jamf Classic API?

If it general usage of the Jamf classic API, it might be better addressed or timely posting to the MacAdmin #jamf-api channel to get community input/suggestions.

We are working the python-jamf or jctl tools on the side and have dedicated little time to these projects and can't currently address general Jamf API questions that TBH would be better addressed by the above MacAdmin slack channel or directly via Jamf technical support.

I hope you understand.

magnusviri commented 3 years ago

@grainofric3

The syntax will change in the future, but here's how you do it now. Note, the 'put' is currently broken. I'm hoping I push the fix right after I post this reply.

import jamf
api = jamf.API()

# Create a new completely empty computer record
new_record = jamf.records.Computers().post(0, "")
new_id = new_record['computer']['id']

# Get the data structure
new_record = jamf.records.Computers().get(new_id)

# Change the computer name
new_record['general']['name'] = "M1 XServe (Ultra secret model)"

# Save it
new_record = jamf.records.Computers().put(new_id, new_record)

# View the data structure
from pprint import pprint
pprint(new_record)
magnusviri commented 3 years ago

Ok, the fix is merged.

magnusviri commented 3 years ago

Whoops, my comment was about computers and I now realize you asked about adding computers to static computer groups. This works (I tested with real data, so I don't know what it will do with bad data--we are really early along in our library...). I have pushed a change in the syntax that hasn't been merged yet. This only works in python_jamf 0.4.9.

data = {
    'computer_additions': [
       { 'computer': { 'serial_number': 'C01234567890' }, },
       { 'computer': { 'name': 'jtb345-03' }, },
       { 'computer': { 'id': '345' }, },
    ]
};

import jamf
api = jamf.API()
jamf.records.ComputerGroups(913).put(data)
magnusviri commented 3 years ago

I just added this method. It's in python-jamf 0.5.0 (if Topher hasn't merged it yet, look in my fork).

data = [
   { 'computer': { 'name': 'comp-01' }, },
   { 'computer': { 'name': 'comp-02' }, },
];
api = jamf.API()
jamf.records.ComputerGroups(913).add_computers(data)
jamf.records.ComputerGroups(913).add_computer({ 'name': 'comp-03' })
uurazzle commented 3 years ago

Hi @grainofric3:

It appears @magnusviri posts have been merged and should answer your questions. Let us know if you have any other questions or problems.