Missing closing '}' in statement block or type definition.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2019 06:12 AM
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
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2019 12:39 PM
Hi ,
You missed "}" on request.body
# 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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2019 12:40 PM
Hi ,
You missed "}" on request.body
# 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