Array Performance and Data Protection
1752793 Members
6174 Online
108789 Solutions
New Discussion юеВ

Re: Rest API Get Snapshot Collection: Cannot index into a null array.

 
SOLVED
Go to solution
adamscabana128
Occasional Contributor

Rest API Get Snapshot Collection: Cannot index into a null array.

Hi All.

I have a powershell script using the REST API to refresh dev/qa environments.

The refresh has been working great for some time.  All of the sudden today I had 2 machines fail with  Cannot index into a null array.

Here is the snippet of code:

$prod_array = @();

$ProdVolume_array = @();

$topsnapshot_array = @();

$uri = "https://" + $ArrayIP + "snapshot_collections/detail"

$snaplist = Invoke-RestMethod -Uri $uri -Method get -Header $header

$prod_array += $snaplist.data 

$ProdVolume_array = $prod_array | select snapshots_list, name, creation_time |where-object name -like $ProdVolumeCollection* | sort-object -Property creation_time -descending

$topsnapshot_array = $ProdVolume_array[0].snapshots_list


$snaplist does have information in it.  when I look at $prod_array and $ProdVolume_array I see nothing.  I don't understand why.

Thanks,

Jeff

4 REPLIES 4
jcates98
Trusted Contributor

Re: Rest API Get Snapshot Collection: Cannot index into a null array.

Hey Jeff,

Are you certain that $snaplist contains valid data?  Depending on what value $ArrayIP has, I see a potential error. If it's simply the IP/hostname of the array as I expect it might be, then I suggest that you change this line:

$uri = "https://" + $ArrayIP + "snapshot_collections/detail"


to instead be


$uri = "https://" + $ArrayIP + ":5392/v1/snapshot_collections/detail"

Otherwise, when you invoke the API in the following line, you are likely to get an error. The only other thing that jumps out is that I don't know what $ProdVolumeCollection looks like here. If it's invalid, then $ProdVolume_array would wind up being empty.

Cheers,

Julian

rshekar42
Advisor

Re: Rest API Get Snapshot Collection: Cannot index into a null array.

Not sure about the snapshot_collections failure, but the snapshots object failed with this error:

Invoke-RestMethod : The remote server returned an error: (400) Bad Request.


snapshots objectset does not support listing all objects. The complete response for this error would be some thing like this:


{

   "messages":[

      {

         "code":"SM_http_bad_request",

         "text":"The request could not be understood by the server."

      },

      {

         "code":"SM_missing_arg",

         "arguments":{

            "arg":"vol_id"

         },

         "text":"Missing the argument 'vol_id' in the request."

      }

   ]

}


You will have to provide the id of a particular volume to list the snapshots. For e.g. you can use a query URL like this:


https://<array-ip>:5392/v1/snapshots/detail?vol_id=0611f49156c08fdc81000000000000000000000007

adamscabana128
Occasional Contributor
Solution

Re: Rest API Get Snapshot Collection: Cannot index into a null array.

I may have found the problem:

changing

$ProdVolume_array = $prod_array | select snapshots_list, name, creation_time |where-object name -like $ProdVolumeCollection* | sort-object -Property creation_time -descending


to:

$ProdVolume_array = $prod_array | select * |where-object volcoll_name -eq $ProdVolumeCollection | sort-object -Property creation_time -descending


In some local testing this appears to take care of the issue, but I need to validate.


I'm still not sure why it all of the sudden failed.

adamscabana128
Occasional Contributor

Re: Rest API Get Snapshot Collection: Cannot index into a null array.

This has corrected the problem.