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

Import API Not Working


Joyce Jeng1709160760

Question

I have a customer who is trying to leverage the import API for their CVAD Service Standard site, after getting the API access token, they were able to call getme API but they could not call any of the image related API. (e.g. get Site API) They included their error log and source code as they are not sure what they are doing wrong. Can someone provide a some feedback? See below for details.

 

 

-----------------ERROR LOG-------------------------------------------------------------------------------------------------------------------------------------------------

=== Getting Assess Token ... ===

=== Assess Token Got===

=== Getting Me ... ===

{'Customers': [{'Id': 'XXXXXXXXXX',

                'Name': None,

                'Sites': [{'Id': 'XXXXXXXXXXXXXXXXXXXXXXXXXX',

                           'Name': 'cloudxdsite'}]}],

'DisplayName': 'XXXXXX',

'ExpiryTime': '5:25:34 AM',

'RefreshExpirationTime': '4:25:34 PM',

'UserId': 'XXXXXXXXXXXXXXXXXXXXXXX',

'VerifiedEmail': 'XXXXXX@XXXX.com'}

=== Me Got===

=== Getting Sited ID ... ===

{'detail': 'Access denied',

'parameters': [{'name': 'message',

                 'value': 'User is not authenticated for the specified '

                          'resource'},

                {'name': 'entityType',

                 'value': 'https://catalogs.apps.cloud.com/customer'},

                {'name': 'id', 'value': '47cbslfratdq'}],

'type': 'https://errors-api.cloud.com/common/authorization'}

Traceback (most recent call last):

  File "C:\Users\azureuser\Desktop\api-script.py", line 50, in <module>

    response.raise_for_status()

  File "C:\Users\azureuser\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\models.py", line 943, in raise_for_status

    raise HTTPError(http_error_msg, response=self)

requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://api-us.cloud.com/catalogservice/47cbslfratdq/sites

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

 

-----------------SOURCE CODE--------------------------------------------------------------------------------------------------------------------------------------------

import requests

from pprint import pprint

 

CLIENT_ID = 'aaaaaaa'

CLIENT_SECRET = 'bbbbbbb'

CUSTOMER_ID = 'XXXXXXXXXXXXXX'

 

TOKEN_URL = 'https://api-us.cloud.com/cctrustoauth2/root/tokens/clients'

 

# get access token

print('=== Getting Assess Token ... === ')

response = requests.post(TOKEN_URL, data={

    'grant_type': 'client_credentials',

    'client_id': CLIENT_ID,

    'client_secret': CLIENT_SECRET

})

token = response.json()

response.raise_for_status()

print('=== Assess Token Got===')

 

# get me

print('=== Getting Me ... === ')

ME_URL = 'https://api-us.cloud.com/cvadapis/me'

response = requests.get(ME_URL, headers={

    'Accept': 'application/json',

    'Content-Type': 'application/json',

    'Authorization': f'CwsAuth Bearer={token["access_token"]}',

    'Citrix-CustomerId': CUSTOMER_ID

})

pprint(response.json())

response.raise_for_status()

print('=== Me Got===')

 

# get sites id

print('=== Getting Sited ID ... === ')

SITES_URL = f'https://api-us.cloud.com/catalogservice/{CUSTOMER_ID}/sites'

response = requests.get(SITES_URL, headers={

    'Accept': 'application/json',

    'Content-Type': 'application/json',

    'Authorization': f'CwsAuth Bearer={token["access_token"]}'

})

pprint(response.json())

response.raise_for_status()

print('=== Sites ID Got===')

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

Link to comment

7 answers to this question

Recommended Posts

  • 1

The customer was receiving a 403 after making the API call since the customer was in the APS region and invoking an US instance of the service. 

The correct host name to be used would be https://api-ap-s.cloud.com/ followed by the path for the specific API.

 

Following are the host names to be used depending on the region: 

US  -  https://api-us.cloud.com

APS  -  https://api-ap-s.cloud.com

EU  -  https://api-eu.cloud.com

 

 

  • Like 1
Link to comment
  • 0

Hello Joyce,

 

The second API called is a Virtual Apps Essentials API and uses a different auth scheme (Cws Bearer=xxx). Check here for details:

https://developer.cloud.com/citrixworkspace/virtual-apps-essentials/apis/Sites/Sites_GetSiteIds

 

The response from getting Me already includes a list of Site Ids in the Sites array:

{'Customers': [{'Id': 'XXXXXXXXXX',

                'Name': None,

                'Sites': [{'Id': 'XXXXXXXXXXXXXXXXXXXXXXXXXX',

                           'Name': 'cloudxdsite'}]}],

'DisplayName': 'XXXXXX',

'ExpiryTime': '5:25:34 AM',

'RefreshExpirationTime': '4:25:34 PM',

'UserId': 'XXXXXXXXXXXXXXXXXXXXXXX',

'VerifiedEmail': 'XXXXXX@XXXX.com'}

 

We can further explore the site using other CVAD Rest APIs, e.g. Get Site info. It is recommended to use CVAD Rest APIs instead of Virtual Apps Essentials APIs as the former is actively maintained.

Link to comment
  • 0

Hi Hao,

 

To make the progress smooth, let me describe the background first.

We are studying how to use citrix api to make automation about importing custom iamge in the CVD in Azure (managed by Citrix).

 

We have identified the desired api call is https://developer.cloud.com/citrixworkspace/managed-desktops/apis/Master-Image/TemplateImage_ImportTemplateImage

And we are confusing how to fill the required parameters, for example:

a)siteId, b)cspCustomerId, c)cspSiteId, and d)azureSubscriptionId.

 

I know that would ok to get siteId from getme api, but that is not enough to invoke the import api.

Also, thanks for your remind that not to use wroing api call.

 

So, could you guide us how to invoke the import api ?

It would be nice to provide the sample as detail as possible, thanks!

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

Link to comment
  • 0

Hello Joyce,

 

cspCustomerId, cspSiteId are optional fields referring to tenantId and siteId under a partner, while azureSubscriptionId is the Azure Subscription ID to be used for storing the image. They may be related to CC APIs.

 

As I'm not the expert in managed desktops, I will invite another engineer to answer this in detail.

 

Regards,

Hao Chen

Link to comment
  • 0

Hello Joyce,

When you call https://developer.cloud.com/citrixworkspace/managed-desktops/apis/Master-Image/TemplateImage_ImportTemplateImage you will need to specify
name  -  mandatory - name of the image should be unique
vhdUri  - mandatory -  URL with or without SAS where vhd is located
azureSubscriptionId - mandatory -  has to match with linked subscription
osPlatform  - optional - default is Windows (possible values : Windows Linux)
cspCustomerId  - optional (only available in Partner/Tenant relationship where importing image in tenant scope)
cspSiteId - optional (only available in Partner/Tenant relationship where importing image in tenant scope)
To authenticate you need valid CC Bearer token.

Link to comment
  • 0
11 hours ago, Maciej Medyk said:

Hello Joyce,

When you call https://developer.cloud.com/citrixworkspace/managed-desktops/apis/Master-Image/TemplateImage_ImportTemplateImage you will need to specify
name  -  mandatory - name of the image should be unique
vhdUri  - mandatory -  URL with or without SAS where vhd is located
azureSubscriptionId - mandatory -  has to match with linked subscription
osPlatform  - optional - default is Windows (possible values : Windows Linux)
cspCustomerId  - optional (only available in Partner/Tenant relationship where importing image in tenant scope)
cspSiteId - optional (only available in Partner/Tenant relationship where importing image in tenant scope)
To authenticate you need valid CC Bearer token.

hi Maciej,

 

Thanks for your reply, but there is one thing that make us confused.

It is not marked "mandatory" for "azureSubscriptionId" in the api document.

We are curious how do know that information.

 

By the way, if we are going to setup the "azureSubscriptionId", where should we get it?

We are using CVD managed by Citrix which means we do not have subscription by ourselves.

Could you help us to find the value of Citrix managed subscription?

 

Here is the error message when invoking the import api.

If you have any finding, tell us as soon as possible, very thanks!

 

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

{

  "type": "https://errors-api.cloud.com/common/authorization",

  "detail": "Access denied",

  "parameters": [

    {

      "name": "message",

      "value": "User is not authenticated for the specified resource"

    },

    {

      "name": "entityType",

      "value": "https://catalogs.apps.cloud.com/customer"

    },

    {

      "name": "id",

      "value": "47cbslfratdq"

    }

  ]

}

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

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...