1

Have a function to update a field in Netbox via API. The same data works on the Django web interface so I know it's not that, just something in my script that I'm doing wrong.

def change_allocated_server_status(api_token="", limit="",jira_access=""):
    api_token_here = "Token " + api_token
    headers = {'Authorization': api_token_here}
    params = {'limit': limit}

    sites = "https://my-url.com/api/dcim/devices/?role=server-planned"
    session = requests.Session()
    site_response = session.get(sites, headers=headers, params=params)
    site_results = site_response.json()['results']

    allocated_servers = get_devices_by_dc_loca(api_token, limit, jira_access)

    url = "https://my-url.com/api/dcim/devices/239"


    update = {
            "device_role": 41
    }

    change = requests.patch(url, headers=headers, data=update)
    change_results = change.json()
    print change_results

The output of print change_results is

{u'status': 2, u'device_role': 40, u'name': u'device-name', u'site': 1, u'comments': u'', u'rack': 4, u'asset_tag': None, u'platform': None, u'primary_ip4': None, u'device_type': 7, u'primary_ip6': None, u'custom_fields': {}, u'position': 5, u'serial': u'', u'face': 0, u'id': 239, u'tenant': 1}

device_role isn't being changed. Doing a print change.status_code returns 200 so I know I'm hitting the API without a authentication problem, just guessing it's something simple I'm missing

1 Answer 1

2

Was missing a '/' from the end of my url, stopping the PATCH from being called but throwing no error.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.