Source Response coming as a String

:bangbang: Please be sure you’ve read the docs and API specs before asking for help. Also, please be sure you’ve searched the forum for your answer before you create a new topic.

Hi,
I am trying to list the sources in my DEV tenant using the /v3/sources api using Powershell. Since my tenant has more than 400 sources, I was using the offset to list the first 250 ,parse and then listing the rest and parse.
While parsing the response, I was able to parse the first 250 sources to get the IDs and Name, however it did not work for the rest.
For troubleshooting, I started listing the sources one by one and found that for one source the response.GetType() is System.String rather than System.Object and that’s why it was breaking.
I tried to convert the string response into Json object as respsoneJSon= response | ConvertFrom-Json but that is also not working.

I wanted to understand why this source has a different response type compared to others and how we can handle it in powershell? I can’t skip the source as I need the sourceId for further processing of script.

Note- The source in IDN is direct connector and in healthy state. From postman, able to get the source too.

I believe you have everything setup, So whenever you are doing the pagination save the response to a file and then call this method. I am also using this same exact thing and it works in this case for me.

function getAllSources() {
	#Response File Created By API    
    $inputFile = "./Source_Export.json" #this contains my source information i.e 250 sources information saved to this file.
    $sourceContent = Get-Content $inputFile -Raw | ConvertFrom-Json
	
    foreach ($singleSource in $sourceContent) {			
		#Get the Source ID
		$sourceID = $singleSource.id
		$sourceName = $singleSource.name
		<# SOME OTHER PROCESS RUNNING HERE #>
		
		#display that in screen as well.
		Write-Host "$sourceName  = $sourceID"
    }
	
    #Delete the created "./Source_Export.json" file from response
    Remove-Item $inputFile
}

Letme know if this works. :slight_smile:

Thanks for the response. I will try that. But do you have an idea why the response is coming as String for just one source ?

HI Neeraj,
I tried your way too but that also did not work. In your case, was there any response of String type?