@@ -18,26 +18,33 @@ type BillingAccount struct {
1818}
1919
2020// BillingAccountResponse is a response from the server to a billing account request.
21- type BillingAccountResponse struct {
22- BillingAccount
21+ type BillingAccountsResponse struct {
22+ BillingAccounts [] BillingAccount `json:"resources"`
2323 ServerResponseError
2424}
2525
26- // getBillingAccount retrieves a billing account by name.
26+ // getBillingAccount retrieves a billing account by name or number .
2727func getBillingAccount (c plugin.CliConnection , name string ) (BillingAccount , error ) {
28- accURL := url .QueryEscape (fmt .Sprintf ("/custom/accounts?q=name:%s" , name ))
28+ expression := url .QueryEscape ("name_number:" + name )
29+ accURL := fmt .Sprintf ("/custom/accounts?q=%s" , expression )
2930 resLines , err := c .CliCommandWithoutTerminalOutput ("curl" , accURL )
3031
3132 if err != nil {
3233 return BillingAccount {}, errors .Wrap (err , "Billing Account not found" )
3334 }
3435
3536 resString := strings .Join (resLines , "" )
36- var res BillingAccountResponse
37+ var res BillingAccountsResponse
3738 err = json .Unmarshal ([]byte (resString ), & res )
3839 if err != nil {
3940 return BillingAccount {}, errors .Wrap (err , "Couldn't read JSON response from server" )
4041 }
4142
42- return res .BillingAccount , nil
43+ if len (res .BillingAccounts ) == 0 {
44+ return BillingAccount {}, errors .New ("Billing account not found" )
45+ } else if len (res .BillingAccounts ) > 1 {
46+ return BillingAccount {}, errors .New ("Multiple billing accounts found - retry with the account's number or full name" )
47+ }
48+
49+ return res .BillingAccounts [0 ], nil
4350}
0 commit comments