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

     1  package invoice
     2  
     3  import (
     4  	"fmt"
     5  
     6  	zoho "github.com/schmorrison/Zoho"
     7  )
     8  
     9  func (c *API) ListItems() (data ListItemsResponse, err error) {
    10  
    11  	endpoint := zoho.Endpoint{
    12  		Name:         ItemsModule,
    13  		URL:          fmt.Sprintf("https://invoice.zoho.%s/api/v3/%s", c.ZohoTLD, ItemsModule),
    14  		Method:       zoho.HTTPGet,
    15  		ResponseData: &ListItemsResponse{},
    16  		URLParameters: map[string]zoho.Parameter{
    17  			"filter_by": "",
    18  		},
    19  		BodyFormat: zoho.JSON_STRING,
    20  		Headers: map[string]string{
    21  			InvoiceAPIEndpointHeader: c.OrganizationID,
    22  		},
    23  	}
    24  
    25  	/*for k, v := range params {
    26  	  	endpoint.URLParameters[k] = v
    27  	  }
    28  	*/
    29  
    30  	err = c.Zoho.HTTPRequest(&endpoint)
    31  	if err != nil {
    32  		return ListItemsResponse{}, fmt.Errorf("Failed to retrieve expense reports: %s", err)
    33  	}
    34  
    35  	if v, ok := endpoint.ResponseData.(*ListItemsResponse); ok {
    36  		// Check if the request succeeded
    37  		if v.Code != 0 {
    38  			return *v, fmt.Errorf("Failed to list items: %s", v.Message)
    39  		}
    40  		return *v, nil
    41  	}
    42  	return ListItemsResponse{}, fmt.Errorf("Data retrieved was not 'ListContactsResponse'")
    43  }
    44  
    45  type ListItemsResponse struct {
    46  	Code    int    `json:"code"`
    47  	Message string `json:"message"`
    48  	Items   []struct {
    49  		ItemID        string  `json:"item_id"`
    50  		Name          string  `json:"name"`
    51  		Status        string  `json:"status"`
    52  		Description   string  `json:"description"`
    53  		Rate          float64 `json:"rate"`
    54  		Unit          string  `json:"unit"`
    55  		TaxID         string  `json:"tax_id"`
    56  		TaxName       string  `json:"tax_name"`
    57  		TaxPercentage float64 `json:"tax_percentage"`
    58  		TaxType       string  `json:"tax_type"`
    59  		SKU           string  `json:"sku"`
    60  		ProductType   string  `json:"product_type"`
    61  	} `json:"items"`
    62  }