Cannot get API call to to work

I am a newbie trying to learn PS. I thought an easy learning opportunity would be to create a script to check ARIN’s API for a list of IPs (sourceip.txt) and output the results to a list apioutput.txt. While I worked through all the errors I had been receiving, I cannot get the output to work. Any assistance would be greatly appreciated.

$url_base = ""
$iplist = Get-Content -Path .\sourceIP.txt
$ips = $iplist -split "," -replace '["]'
foreach ($item in $ips){
Write-Output $item
#Write-Output $ips
$url = $url_base + $item
Write-Output $url
$header = @{"Accept" = "application/json"}
$response = Invoke-Webrequest -uri $url -Method "Get" -Headers $header
$ | ConvertTo-Json
Write-Output $ | Out-File -FilePath .\apioutput.txt

Welcome to the forum. :wave:t4:

Unfortunately …

is not helpful at all. :wink: What does that mean? If you get error messages you should share them completely (formatted as code, please)

How does you input file look like? And what do you expect your output file to look like? (When you poast sample data format it as code as well, please).

I do not receive any errors or output, using Visual Studio Code. My input file looks like this (though I’ve substituted my IP list with random, private IP for the sake of an example:

I am not getting output to show you, but it would be a json version of this from Arin:

Net Range -
Handle	NET-142-250-0-0-1
Parent	NET142 (NET-142-0-0-0-0)
Net Type	Direct Allocation
Origin AS	AS15169
Organization	Google LLC (GOGL)
Registration Date	2012-05-24
Last Updated	2012-05-24
RESTful Link
See Also	Related POC records.
See Also	Related organization's POC records.
See Also	Related delegations.

Look at the output of

$response.content | ConvertFrom-Json | Select-Object -ExpandProperty net

You’ve got some work ahead of you to extract the desired info out of the object returned. There are several different nested properties.

@xmlns               : @{ns3=; ns2=;
@copyrightNotice     : Copyright 1997-2022, American Registry for Internet Numbers, Ltd.
@inaccuracyReportUrl :
@termsOfUse          :
registrationDate     : @{$=2016-02-01T15:18:40-05:00}
rdapRef              : @{$=}
ref                  : @{$=}
endAddress           : @{$=}
handle               : @{$=NET-151-101-0-0-1}
name                 : @{$=SKYCA-3}
netBlocks            : @{netBlock=}
resources            : @{@copyrightNotice=Copyright 1997-2022, American Registry for Internet Numbers, Ltd.;
                       @termsOfUse=; limitExceeded=}
orgRef               : @{@handle=SKYCA-3; @name=Fastly; $=}
parentNetRef         : @{@handle=NET-151-0-0-0-0; @name=RIPE-ERX-151;
startAddress         : @{$=}
updateDate           : @{$=2021-12-14T20:28:34-05:00}
version              : @{$=4}
1 Like

Huuuiii … you’ve been faster than me. :+1:t4: :wink:

… and …

Happy birthday!! :clap:t4: :wink: :partying_face: :love_you_gesture:t4: :heart: :birthday: :champagne: :beers:

Thank you very much, Olaf!