github.com/schmorrison/Zoho@v1.1.4/invoice/list_recurring_invoices.go (about)

     1  package invoice
     2  
     3  import (
     4  	"fmt"
     5  
     6  	zoho "github.com/schmorrison/Zoho"
     7  )
     8  
     9  //https://www.zoho.com/invoice/api/v3/#Recurring_Invoices_List_Recurring_Invoice
    10  //func (c *API) ListRecurringInvoices(request interface{}, OrganizationID string, params map[string]zoho.Parameter) (data ListRecurringInvoicesResponse, err error) {
    11  func (c *API) ListRecurringInvoices() (data ListRecurringInvoicesResponse, err error) {
    12  
    13  	endpoint := zoho.Endpoint{
    14  		Name: RecurringInvoicesModule,
    15  		URL: fmt.Sprintf(
    16  			"https://invoice.zoho.%s/api/v3/%s",
    17  			c.ZohoTLD,
    18  			RecurringInvoicesModule,
    19  		),
    20  		Method:        zoho.HTTPGet,
    21  		ResponseData:  &ListRecurringInvoicesResponse{},
    22  		URLParameters: map[string]zoho.Parameter{
    23  			//"filter_by": "",
    24  		},
    25  		BodyFormat: zoho.JSON_STRING,
    26  		Headers: map[string]string{
    27  			InvoiceAPIEndpointHeader: c.OrganizationID,
    28  		},
    29  	}
    30  
    31  	/*for k, v := range params {
    32  		endpoint.URLParameters[k] = v
    33  	}
    34  	*/
    35  
    36  	err = c.Zoho.HTTPRequest(&endpoint)
    37  	if err != nil {
    38  		return ListRecurringInvoicesResponse{}, fmt.Errorf(
    39  			"Failed to retrieve expense reports: %s",
    40  			err,
    41  		)
    42  	}
    43  
    44  	if v, ok := endpoint.ResponseData.(*ListRecurringInvoicesResponse); ok {
    45  		// Check if the request succeeded
    46  		if v.Code != 0 {
    47  			return *v, fmt.Errorf("Failed to list recurring invoices: %s", v.Message)
    48  		}
    49  		return *v, nil
    50  	}
    51  	return ListRecurringInvoicesResponse{}, fmt.Errorf(
    52  		"Data retrieved was not 'ListRecurringInvoicesResponse'",
    53  	)
    54  }
    55  
    56  type ListRecurringInvoicesResponse struct {
    57  	Code              int    `json:"code"`
    58  	Message           string `json:"message"`
    59  	RecurringInvoices []struct {
    60  		RecurringInvoiceId  string  `json:"recurring_invoice_id"`
    61  		RecurrenceName      string  `json:"recurrence_name"`
    62  		ReferenceNumber     string  `json:"reference_number"`
    63  		Status              string  `json:"status"`
    64  		Total               float64 `json:"total"`
    65  		CustomerId          string  `json:"customer_id"`
    66  		CustomerName        string  `json:"customer_name"`
    67  		StartDate           string  `json:"start_date"`
    68  		EndDate             string  `json:"end_date"`
    69  		LastSentDate        string  `json:"last_sent_date"`
    70  		NextInvoiceDate     string  `json:"next_invoice_date"`
    71  		RecurrenceFrequency string  `json:"recurrence_frequency"`
    72  		RepeatEvery         int64   `json:"repeat_every"`
    73  	} `json:"recurring_invoices"`
    74  }