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

How to make it support Japanese in CVAD REST API


hongzhi hui

Question

HI,
I need to create an application folder by a japanese name with CVAD REST API
It works well when the folder name is English,but When I change the name to Japannese I got the follow Error
the detailed error:

-------------------------------------------------------
"{
  "ErrorMessage": "The object name must not exceed 64 characters; it cannot contain ASCII control characters or any of the following: \\/;:#.*?=|[]()\"'.",
  "SdkErrorId": "InvalidLeafName",
  "ErrorType": "ScriptException",
  "ErrorDetails": "Transaction ID: f34081bb-8d7a-44aa-8ef3-f5da94cce576\r\nAction Name: CreateApplicationFolder\r\n\r\nAn error occurred. Contact Citrix Technical Support, and provide the transaction ID above.\r\n\r\nException:\r\n    DesktopStudio_ErrorId : InvalidLeafName\r\n    Error Source : CitrixBrokerService\r\n    Sdk Error Message : The name of the object must not exceed 64 characters in length and may not contain any ASCII control characters or any of the following: \\/;:#.*?=|[]()\"'\r\n    Sdk Error ID : Citrix.XDPowerShell.Broker.InvalidLeafName,Citrix.Broker.Admin.SDK.NewBrokerAdminFolderCommand\r\n    ErrorCategory : NotSpecified\r\n    DesktopStudio_PowerShellHistory : Create Folder '????' in the folder ''\r\n    7/16/2021 11:41:34 AM\r\n    \r\n    Get-LogSite  -AdminAddress \"localhost:9097\" -BearerToken ********\r\n    Start-LogHighLevelOperation  -AdminAddress \"localhost:9097\" -BearerToken ******** -Source \"Studio\" -StartTime \"7/16/2021 11:41:34 AM\" -Text \"Create Folder `'????`' in the folder `'`'\"\r\n    New-BrokerAdminFolder  -AdminAddress \"localhost:9097\" -BearerToken ******** -FolderName \"????\" -LoggingId \"1af35f2f-c2a6-43da-a080-f55c3b9eb787\"\r\n    New-BrokerAdminFolder : The name of the object must not exceed 64 characters in length and may not contain any ASCII control characters or any of the following: \\/;:#.*?=|[]()\"'\r\n    \t+ CategoryInfo : InvalidArgument: (:) [New-BrokerAdminFolder], SdkOperationException\r\n    \t+ FullyQualifiedErrorId : Citrix.XDPowerShell.Broker.InvalidLeafName,Citrix.Broker.Admin.SDK.NewBrokerAdminFolderCommand\r\n    Stop-LogHighLevelOperation  -AdminAddress \"localhost:9097\" -BearerToken ******** -EndTime \"7/16/2021 11:41:34 AM\" -HighLevelOperationId \"1af35f2f-c2a6-43da-a080-f55c3b9eb787\" -IsSuccessful $False\r\n    \r\n    \r\n",
  "SupportLink": null,
  "ErrorReportXml": null,
  "ErrorReport": null
}"

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

my source is bellow

----------------------------------------------------------
**function GetSites and function GetBearerToken are omitted.

function CreateApplicationFolder {
  param (
      [Parameter(Mandatory=$true)]
      [string] $customerid,
      [Parameter(Mandatory=$true)]
      [string] $siteid,
      [Parameter(Mandatory=$true)]
      [string] $bearerToken,
      [Parameter(Mandatory=$true)]
      [string] $application
  )
  $requestUri = [string]::Format("https://api-us.cloud.com/cvadapis/{0}/ApplicationFolders", $siteid)
  $headers = @{
      "Accept" = "application/json";
      "Authorization" = "CWSAuth Bearer=$bearerToken";
      "Citrix-CustomerId" = $customerid;
      "Content-Type" = "application/json;charset=utf-8";
  }

  $response = Invoke-RestMethod -Uri $requestUri -Method POST -Headers $headers -Body $application
  return $response
}

#--------------------------
$customerId = "AAAAAAA"
$clientId = "BBBBBBB" 
$clientSecret = "CCCCCCC" 

$bearerToken = GetBearerToken $clientId $clientSecret
$sites = GetSites $customerId $bearerToken 
$siteId = $sites.Sites[0].Id

# works well when it was english name
$ApplicationFolder='RestapiTest'

# not work when it was japanese name
#$ApplicationFolder='共通管理'

 $body = @{
  'Name'=$ApplicationFolder
  'ParentId'=0
  }
  $Appbody= $body | ConvertTo-Json

 $GetResult=CreateApplicationFolder $customerid $siteid $bearerToken $Appbody

-----------------------------------------------end------------------------------------------------------------

I guess the reason maybe about decode. could anyone help how to correct the source to support japanese
thank you

Link to comment

2 answers to this question

Recommended Posts

  • 1

CVAD Rest API is support to create folder with a japanese name.

Its a bug in the ConvertTo-JSON where powershell is not able to convert special character containing data to UTF-8 format. All these characters are being left with Unicode format. That is the reason data was failing to send. Below is the correct code for body:

 

**function GetSites and function GetBearerToken are omitted.

function CreateApplicationFolder {
  param (
      [Parameter(Mandatory=$true)]
      [string] $customerid,
      [Parameter(Mandatory=$true)]
      [string] $siteid,
      [Parameter(Mandatory=$true)]
      [string] $bearerToken,
      [Parameter(Mandatory=$true)]
      [string] $application
  )
  $requestUri = [string]::Format("https://api-us.cloud.com/cvadapis/{0}/ApplicationFolders", $siteid)
  $headers = @{
      "Accept" = "application/json";
      "Authorization" = "CWSAuth Bearer=$bearerToken";
      "Citrix-CustomerId" = $customerid;
      "Content-Type" = "application/json;charset=utf-8";
  }

 $body = ([System.Text.Encoding]::UTF8.GetBytes( $application))

  $response = Invoke-RestMethod -Uri $requestUri -Method POST -Headers $headers -Body $body
  return $response
}

 

reference https://social.technet.microsoft.com/Forums/lync/en-US/726ecbbf-3a65-4385-b520-eae93fd7e3e9/converttojson-cmdlet-is-not-working-with-other-language-characters-like-etcneed?forum=winserverpowershell

 

 

 

  • Like 1
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...