Jump to content
Welcome to our new Citrix community!
  • 1

Issues on POST/PATCH API


Sara Cianfarra

Question

Hi,
we have some issue on POST/PATCH API, while GET API works fine.

One of the API that we are trying to use in order to update Machine Catalog is this:
https://developer.cloud.com/citrixworkspace/virtual-apps-and-desktops/cvad-rest-apis/apis/MachineCatalogs-APIs/MachineCatalogs_UpdateMachineCatalog

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Attached you have a python we are using for extracting info from CitrixCloud to be able, later, to POST the request to change Machine Catalog.

I removed relevant information from it:

customer_id = "PutHereYOUR"
client_id = "PutHereYOURClient_id"
client_secret = "PutHereYOURSecret"

last part is to create the POST to the url:
https://api.cloud.com/cvadapis/<SiteID>/MachineCatalogs/<CatalogID>/$UpdateProvisioningScheme?async=true

but is does not work for the moment, maybe paylod is wrong, url is wrong (I see a strange $ in it, I removed), and params, or we need to overcome the warning we got also on the site trying the URL.

I’m almost sure that it is not working for the warnings we also have on trying to do it on web site, this is what I get from the request:


Traceback (most recent call last):

  File "./machine_catalog", line 104, in <module>
    response = requests.request("POST", url, data=payload, headers=headers, params=params)
  File "/usr/lib/python3/dist-packages/requests/api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 519, in request
    prep = self.prepare_request(req)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 452, in prepare_request
    p.prepare(
  File "/usr/lib/python3/dist-packages/requests/models.py", line 313, in prepare
    self.prepare_url(url, params)
  File "/usr/lib/python3/dist-packages/requests/models.py", line 431, in prepare_url
    enc_params = self._encode_params(params)
  File "/usr/lib/python3/dist-packages/requests/models.py", line 97, in _encode_params
    for k, vs in to_key_val_list(data):
ValueError: too many values to unpack (expected 2)

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

 

Thanks,

Regards

citrix_machine_catalog.txt

Link to comment

3 answers to this question

Recommended Posts

  • 1

Hello Sara,

 

These are two different operations about updating machine catalog. To update the overall information about a catalog, use method 'PATCH' and URL 'https://api.cloud.com/cvadapis/{siteid}/MachineCatalogs/{nameOrId}'.

 

To update the hard disk image used to provision virtual machines, use method 'POST' and URL 'https://api.cloud.com/cvadapis/<SiteID>/MachineCatalogs/<CatalogID>/$UpdateProvisioningScheme'. The $ sign is needed and indicates a special action instead of creation.

 

Looked at your script and it seems to be updating the provisioning scheme information, so the target URL shall be 'https://api.cloud.com/cvadapis/<SiteID>/MachineCatalogs/<CatalogID>/$UpdateProvisioningScheme'. Request parameters are just like other API calls.

  • Like 1
Link to comment
  • 1

Hi Sara,

 

As @Hao Chen mentioned, you need those '$' signs - they are part of the API. The '$' signifies that you are performing the UpdateProvisioningScheme operation on a machine catalog, rather than manipulating an UpdateProvisioningScheme resource.


Having said that, it looks like your script isn't getting as far as calling the API. It's failing in the requests library with the error, 'ValueError: too many values to unpack (expected 2)'. Given that the failure is in _encode_params, I suspect that you are not correctly passing the header. In fact, your code has params set as a nested tuple:

params = (
    ("async", "true"))

Requests is expecting a dict, so you should set params like this:

params = {"async": "true"}

If you make this change, and restore the '$' to the URL, the script should get further.

 

Also, I notice in your Python script you just print response.text. You should also print response.status_code - this will give you more information on the nature of the error.

 

Since you are specifying async as true, a successful status code will be 202, and the Location response header will point to the job status API. You can access this with:

response.headers['Location']

Hope this helps!

  • Like 1
Link to comment
  • 0

Thanks for the quick reply.

Our issue, at the moment, is that PATCH and POST APIs seems don't work on our platform (eg. we don't receive any error message if we try one of your APIs via web as well).

No error if we use GET APIs (that work correctly).

Could you help us to understand if we need to do something to enable PATCH or POST APIs for our user or environment? Or for using PATCH and POST APIs are required other activities from our sites?

 

Thanks,

Regards

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...