How generate a Citrix Cloud bearer token and use it on a PowerShell API query
book
Article ID: CTX564718
calendar_today
Updated On:
Description
This article outlines the steps to generate a Citrix Cloud bearer token and use it on a PowerShell API query.
Instructions
Generate Citrix Cloud bearer token using Citrix DaaS (formerly Citrix Virtual Apps and Desktops service) PowerShell SDK as follows:
1-Download the Remote PowerShell SDK from here.
2-Install the SDK on any computer in your resource location.
3-Open a PowerShell command prompt. (administrator rights are not required)
4-Add the Citrix snap-ins:
asnp citrix*.
5-Execute the cmdlet,
Get-XdAuthentication, it prompts you for Citrix Cloud authentication.
6-On successful authentication, the bearer token is stored in the current PowerShell session.
7-Execute the cmdlet,
Get-Variable to list all the variables in the current PowerShell session.
8-The list contains a variable,
GLOBAL:XDAuthToken containing bearer token as value.
9-Copy the bearer token value to be used in the OData query.
**Copy the value of the $GLOBAL:XDAuthToken and use it in the command below (CWSAuth bearer=)**
**Make sure the formatting is correct, there should be not spaces**
Example: PS C:\> $headers = @{"Authorization" = "CWSAuth bearer=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9........<TheWholeToken>....."; "Citrix-CustomerId" = "<Your Customer ID>"}PS C:\> $headers = @{"Authorization" = "<BearerToken>”; "Citrix-CustomerId" = "<Your Customer Id>"}
PS C:\> $url = 'https://{ApiGatewayEndpoint}/Users'
PS C:\> $result = Invoke-WebRequest -Uri $url -Headers $headers
PS C:\> $result.Content > <Path-to-Output-File>
Environment
The above mentioned sample code is provided to you as is with no representations, warranties or conditions of any kind. You may use, modify and distribute it at your own risk. CITRIX DISCLAIMS ALL WARRANTIES WHATSOEVER, EXPRESS, IMPLIED, WRITTEN, ORAL OR STATUTORY, INCLUDING WITHOUT LIMITATION WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NONINFRINGEMENT. Without limiting the generality of the foregoing, you acknowledge and agree that (a) the sample code may exhibit errors, design flaws or other problems, possibly resulting in loss of data or damage to property; (b) it may not be possible to make the sample code fully functional; and (c) Citrix may, without notice or liability to you, cease to make available the current version and/or any future versions of the sample code. In no event should the code be used to support ultra-hazardous activities, including but not limited to life support or blasting activities. NEITHER CITRIX NOR ITS AFFILIATES OR AGENTS WILL BE LIABLE, UNDER BREACH OF CONTRACT OR ANY OTHER THEORY OF LIABILITY, FOR ANY DAMAGES WHATSOEVER ARISING FROM USE OF THE SAMPLE CODE, INCLUDING WITHOUT LIMITATION DIRECT, SPECIAL, INCIDENTAL, PUNITIVE, CONSEQUENTIAL OR OTHER DAMAGES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Although the copyright in the code belongs to Citrix, any distribution of the sample code should include only your own standard copyright attribution, and not that of Citrix. You agree to indemnify and defend Citrix against any and all claims arising from your use, modification or distribution of the sample code.
Additional Information
You can find more Odata info in our sites:
Citrix Cloud API overview - https://developer.cloud.com/citrix-cloud/citrix-cloud-api-overview/docs/get-started-with-citrix-cloud-apis
Accessing monitor service data in Citrix Cloud - https://developer.cloud.com/citrixworkspace/citrix-daas/accessing-monitor-service-data-in-citrix-cloud/docs/overview
About Citrix Monitor Service API - https://developer-docs.citrix.com/en-us/monitor-service-odata-api/current-release/
APIs and SDKs Forum - https://discussions.citrix.com/forum/1750-apis-and-sdks/
Was this article helpful?
thumb_up
Yes
thumb_down
No