Unable to connect to Servicenow Instance from MIDServer

shuheih
Tera Contributor

I`m trying to get table information using PowerShell stored in the MIDServer.


It performs fine on development and testing instances, but gives an error on production instances.
I was able to register an ECC Queue with Servicenow and run PowerShell,
but an error occurred when sending an API request from MidServer to Servicenow, and processing was not possible.

 

The error message I'm encountering is: "remote name can not be resolved"

 

I've also verified that the URL, API user and user permissions are correct.
I also confirmed that the scripts stored in MidServer function normally when executed from a PC.

 

I can't pinpoint the cause, I'd appreciate some help.

 

$INSTANCE  = $args[0]
$TABLE_NAME = $args[1]
$QUERY  = $args[2]

Write-Host "Instance: ${INSTANCE}, Table Name: ${TABLE_NAME}, Query: ${QUERY}"

# folder_path
$FOLDER_PATH = ""

# SSL/TLS
[Net.ServicePointManager]::SecurityProtocol = @([Net.SecurityProtocolType]::Ssl3,[Net.SecurityProtocolType]::Tls,
[Net.SecurityProtocolType]::Tls11,[Net.SecurityProtocolType]::Tls12)

# Base64
$head_auth = @{
	Authorization= "Basic Base64="
}

# conf table
$table_folder_path = Join-Path $FOLDER_PATH $TABLE_NAME
try {
	if ( -not ( Test-Path $table_folder_path ) ) {
		Write-Host "We have not a Table directory and make directory."
		New-Item -Path $table_folder_path -ItemType Directory
	}
}
catch {
	Write-Host "Error make a table directory: $_"
}

# get table sysid
try {
	if ( $QUERY -eq "none" ) {
		Write-Host "Wa are going to download attachments of all records."               
		$response = Invoke-WebRequest -Uri "https://${INSTANCE}.service-now.com/api/now/table/${TABLE_NAME}?sysparm_fields=sys_id"`
			-Method "GET"`
			-Headers $head_auth
	}
	else {
		Write-Host "Wa are going to download attachments of query records."
		$response = Invoke-WebRequest -Uri "https://${INSTANCE}.service-now.com/api/now/table/${TABLE_NAME}?sysparm_query=${QUERY}&sysparm_fields=sys_id"`
			-Method "GET"`
			-Headers $head_auth
	}

	$stream = $response.RawContentStream
	$reader = New-Object System.IO.StreamReader($stream, [System.Text.Encoding]::UTF8)

	$json = $reader.ReadToEnd()
	$reader.Close()
	$response.RawContentStream.Close()

	$records_json = $json | ConvertFrom-Json
}
catch {
	Write-Host "Error get table info: $_"
	return
}

 

4 REPLIES 4

Ct111
Tera Sage

if it is just happening in PROD. can you crosscheck if some port is blocked by firewall.

I believe DNS related is PORT 53 usually.

 

Also check below articles just for reference:

LINK1

LINK2

shuheih
Tera Contributor

Thank u for reply.

A MID Server seems like there are restrictions in the proxy, so I would like to specifically register an additional DNS server.
Where is your current DNS server?

Bhuvan
Kilo Patron

@shuheih 

 

'remote name can not be resolved' is typically a DNS resolution issue.

 

Do a nslookup to ServiceNow instance from MID server and make sure name resolution is successful. If it does not work, check with your Network team. Once DNS resolution is successful, script should work fine.

 

Bhuvan_0-1756082332413.png

If this helped to answer your query, please mark it helpful & accept the solution.

 

Thanks,

Bhuvan

@shuheih 

 

Did you get a chance to review this ?

 

If my response helped to answer your query, please mark it helpful & accept the solution.

 

Thanks,

Bhuvan