github.com/schmorrison/Zoho@v1.1.4/invoice/list_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/#Invoices_List_invoices
    10  //func (c *API) ListInvoices(request interface{}, OrganizationID string, params map[string]zoho.Parameter) (data ListInvoicesResponse, err error) {
    11  func (c *API) ListInvoices() (data ListInvoicesResponse, err error) {
    12  
    13  	endpoint := zoho.Endpoint{
    14  		Name:          InvoicesModule,
    15  		URL:           fmt.Sprintf("https://invoice.zoho.%s/api/v3/%s", c.ZohoTLD, InvoicesModule),
    16  		Method:        zoho.HTTPGet,
    17  		ResponseData:  &ListInvoicesResponse{},
    18  		URLParameters: map[string]zoho.Parameter{
    19  			//"filter_by": "",
    20  		},
    21  		BodyFormat: zoho.JSON_STRING,
    22  		Headers: map[string]string{
    23  			InvoiceAPIEndpointHeader: c.OrganizationID,
    24  		},
    25  	}
    26  
    27  	/*for k, v := range params {
    28  		endpoint.URLParameters[k] = v
    29  	}
    30  	*/
    31  
    32  	err = c.Zoho.HTTPRequest(&endpoint)
    33  	if err != nil {
    34  		return ListInvoicesResponse{}, fmt.Errorf("Failed to retrieve expense reports: %s", err)
    35  	}
    36  
    37  	if v, ok := endpoint.ResponseData.(*ListInvoicesResponse); ok {
    38  		// Check if the request succeeded
    39  		if v.Code != 0 {
    40  			return *v, fmt.Errorf("Failed to list invoices: %s", v.Message)
    41  		}
    42  		return *v, nil
    43  	}
    44  	return ListInvoicesResponse{}, fmt.Errorf("Data retrieved was not 'ListInvoicesResponse'")
    45  }
    46  
    47  // ListContactsResponse is the data returned by GetExpenseReports
    48  type ListInvoicesResponse struct {
    49  	Code     int    `json:"code"`
    50  	Message  string `json:"message"`
    51  	Invoices []struct {
    52  		InvoiceID            string  `json:"invoice_id"`
    53  		AchPaymentInitiated  bool    `json:"ach_payment_initiated"`
    54  		CustomerName         string  `json:"customer_name"`
    55  		CustomerID           string  `json:"customer_id"`
    56  		Status               string  `json:"status"`
    57  		InvoiceNumber        string  `json:"invoice_number"`
    58  		ReferenceNumber      string  `json:"reference_number"`
    59  		Date                 string  `json:"date"`
    60  		DueDate              string  `json:"due_date"`
    61  		DueDays              string  `json:"due_days"`
    62  		CurrencyID           string  `json:"currency_id"`
    63  		ScheduleTime         string  `json:"schedule_time"`
    64  		CurrencyCode         string  `json:"currency_code"`
    65  		IsViewedByClient     bool    `json:"is_viewed_by_client"`
    66  		HasAttachment        bool    `json:"has_attachment"`
    67  		ClientViewedTime     string  `json:"client_viewed_time"`
    68  		Total                float64 `json:"total"`
    69  		Balance              float64 `json:"balance"`
    70  		CreatedTime          string  `json:"created_time"`
    71  		LastModifiedTime     string  `json:"last_modified_time"`
    72  		IsEmailed            bool    `json:"is_emailed"`
    73  		RemindersSent        int64   `json:"reminders_sent"`
    74  		LastReminderSentDate string  `json:"last_reminder_sent_date"`
    75  		PaymentExpectedDate  string  `json:"payment_expected_date"`
    76  		LastPaymentDate      string  `json:"last_payment_date"`
    77  		/*CustomFields  []struct {
    78  			CustomfieldID string `json:"customfield_id"`
    79  			Label         string `json:"label"`
    80  			Value         string `json:"value"`
    81  		} `json:"custom_fields"`*/
    82  		Documents       string  `json:"documents"`
    83  		SalespersonID   string  `json:"salesperson_id"`
    84  		SalespersonName string  `json:"salesperson_name"`
    85  		ShippingCharge  float32 `json:"shipping_charge"`
    86  		Adjustment      float32 `json:"adjustment"`
    87  		WriteOffAmount  float32 `json:"write_off_amount"`
    88  		ExchangeRate    float32 `json:"exchange_rate"`
    89  	} `json:"invoices"`
    90  }