Missing closing '}' in statement block or type definition.

Patrick Delaney
Kilo Contributor

I'm trying to create a powershell script that will create Change Requests. I am using the REST explorer to generate the sample powershell script. But it is erroring out. After doing some google searches it appears that the REST explorer example is broken for the request.body section.  I made it very simple to start, just add 2 fields, but I get the following error:

# Print response
$response.RawContent
Missing closing '}' in statement block or type definition.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingEndCurlyBrace

 

Here is my script:

# Eg. User name="admin", Password="admin" for this code sample.
$user = "username removed"
$pass = "userpassword removed"

# Build auth header
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user, $pass)))

# Set proper headers
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add('Authorization',('Basic {0}' -f $base64AuthInfo))
$headers.Add('Accept','application/json')
$headers.Add('Content-Type','application/json')

# Specify endpoint uri
$uri = "https://xxxxxxhelpdesk.service-now.com/api/now/table/change_request"

# Specify HTTP method
$method = "post"

# Specify request body
{request.body ? "$body = \"" :""}}{
\"category\": \"software code deployment\",
\"short_description\": \"This is the Short Description.\"
}"

# Send HTTP request
# $response = Invoke-WebRequest -Headers $headers -Method $method -Uri $uri -Body $body

# Print response
$response.RawContent

Any thoughts

2 REPLIES 2

Nitin Panchal1
Tera Contributor

Hi , 

 

You missed "}" on request.body

# Specify request body
{request.body ? "$body = \"" :""}}{
\"category\": \"software code deployment\",
\"short_description\": \"This is the Short Description.\"
}"}
 
Here is whole script. 
# Eg. User name="admin", Password="admin" for this code sample.
$user = "username removed"
$pass = "userpassword removed"

# Build auth header
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user, $pass)))

# Set proper headers
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add('Authorization',('Basic {0}' -f $base64AuthInfo))
$headers.Add('Accept','application/json')
$headers.Add('Content-Type','application/json')

# Specify endpoint uri
$uri = "https://xxxxxxhelpdesk.service-now.com/api/now/table/change_request"

# Specify HTTP method
$method = "post"

# Specify request body
{request.body ? "$body = \"" :""}}{
\"category\": \"software code deployment\",
\"short_description\": \"This is the Short Description.\"
}"}

# Send HTTP request
# $response = Invoke-WebRequest -Headers $headers -Method $method -Uri $uri -Body $body

# Print response
$response.RawContent

 

Please mark correct answer/helpful if it helped you.

 

Thanks,

Nitin

Nitin Panchal
Tera Guru

Hi , 

 

You missed "}" on request.body

# Specify request body
{request.body ? "$body = \"" :""}}{
\"category\": \"software code deployment\",
\"short_description\": \"This is the Short Description.\"
}"}
 
Here is whole script. 
# Eg. User name="admin", Password="admin" for this code sample.
$user = "username removed"
$pass = "userpassword removed"

# Build auth header
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user, $pass)))

# Set proper headers
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add('Authorization',('Basic {0}' -f $base64AuthInfo))
$headers.Add('Accept','application/json')
$headers.Add('Content-Type','application/json')

# Specify endpoint uri
$uri = "https://xxxxxxhelpdesk.service-now.com/api/now/table/change_request"

# Specify HTTP method
$method = "post"

# Specify request body
{request.body ? "$body = \"" :""}}{
\"category\": \"software code deployment\",
\"short_description\": \"This is the Short Description.\"
}"}

# Send HTTP request
# $response = Invoke-WebRequest -Headers $headers -Method $method -Uri $uri -Body $body

# Print response
$response.RawContent

 

Please mark correct answer/helpful if it helped you.

 

Thanks,

Nitin