@@ -1101,7 +1101,26 @@ func InitializeOntapAPI(
1101
1101
// Based on user-configured options, we either keep the REST client or override it with a ZAPI client.
1102
1102
ontapAPI , err = api .NewRestClientFromOntapConfig (ctx , config )
1103
1103
if err != nil {
1104
- return nil , fmt .Errorf ("error creating ONTAP API client: %v" , err )
1104
+ // The creation of a REST client may fail due to various reasons.
1105
+ // One of the primary reasons could be the lack of authorization for the REST client.
1106
+ // In such cases, we attempt to fall back to ZAPI.
1107
+
1108
+ Logc (ctx ).WithField ("error" , err ).Error ("Error creating ONTAP REST API client for initial call. Falling back to ZAPI." )
1109
+
1110
+ // If the user has set the useREST flag to true, return an error.
1111
+ if config .UseREST != nil && * config .UseREST == true {
1112
+ Logc (ctx ).Error ("useREST is set to true. Returning error, instead of falling back to ZAPI." )
1113
+ return nil , fmt .Errorf ("error creating ONTAP REST API client: %v" , err )
1114
+ }
1115
+
1116
+ ontapAPI , err = api .NewZAPIClientFromOntapConfig (ctx , config , numRecords )
1117
+ if err != nil {
1118
+ return nil , fmt .Errorf ("error creating ONTAP API client: %v" , err )
1119
+ }
1120
+
1121
+ Logc (ctx ).WithField ("Backend" , config .BackendName ).Info ("Using ZAPI client" )
1122
+ Logc (ctx ).WithField ("SVM" , ontapAPI .SVMName ()).Debug ("Using SVM." )
1123
+ return ontapAPI , nil
1105
1124
}
1106
1125
1107
1126
ontapVer , err := ontapAPI .APIVersion (ctx )
0 commit comments