Forum Discussion

gregorycox-cv's avatar
9 months ago

updating bandwidth for connection

I'm attempting to change the bandwidth using python requests

based on this https://developer.equinix.com/catalog/fabricv4#operation/updateConnectionByUuid
authorization is solid, used same headers for many other without issue.

url = f"https://api.equinix.com/fabric/v4/connections/{cid}"
headers["content-type"] = 'application/json-patch+json'
response = requests.patch(
  url,
  headers=headers,
  timeout=5,
  data=[
    {
        "op": "replace",
        "path": "/bandwidth",
        "value": bw
    }
]
 
if run as above I get this error
Traceback (most recent call last):
File "/Users/gregcox/Projects/app/main.py", line 238, in <module>
pp(update_bandwidth(vcs[0], 200))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/gregcox/Projects/app/main.py", line 208, in update_bandwidth
response = requests.patch(
^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/requests/api.py", line 145, in patch
return request("patch", url, data=data, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/requests/api.py", line 59, in request
return session.request(method=method, url=url, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/requests/sessions.py", line 575, in request
prep = self.prepare_request(req)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/requests/sessions.py", line 486, in prepare_request
p.prepare(
File "/usr/local/lib/python3.11/site-packages/requests/models.py", line 371, in prepare
self.prepare_body(data, files, json)
File "/usr/local/lib/python3.11/site-packages/requests/models.py", line 559, in prepare_body
body = self._encode_params(data)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/requests/models.py", line 121, in _encode_params
for k, vs in to_key_val_list(data):
^^^^^
ValueError: too many values to unpack (expected 2)

If I run the same as above, but change data to be a dict instead of a list I get this error
[{'correlationId': '-api',
'details': 'Please refer the contracts for correct fields',
'errorCode': 'EQ-3142558',
'errorMessage': 'Json syntax error, please check request body'}]​


  • vaibhav's avatar
    vaibhav
    Equinix Employee

    Issue: Payload was added as Form data in request 

    Solution: We need to submit JSON payload to the API call. Below is a working example.

    import requests
    cid = e7ea19ba-5d53-476d-a041-43a3004c6683
    bw= 50
    url = f"https://api.equinix.com/fabric/v4/connections/{cid}"
    headers = {}
    headers["content-type"] = 'application/json-patch+json'
    
    data=[
        {
            "op": "replace",
            "path": "/bandwidth",
            "value": bw
        }
    ]
    
    response = requests.patch(
      url,
      headers=headers,
      timeout=5,
      json=data
    )

     

  • Jantzen's avatar
    Jantzen
    Equinix Employee

    I added a few code blocks to your message to help other community members review the information. Please feel free to edit if I made any mistakes. I'll also see if I can get someone more familiar with the Fabric API to take a look. Stay tuned..