github.com/schmorrison/Zoho@v1.1.4/expense/organization.go (about)

     1  package expense
     2  
     3  import (
     4  	"fmt"
     5  
     6  	zoho "github.com/schmorrison/Zoho"
     7  )
     8  
     9  // GetOrganization will return the organization data related to the logged in account
    10  // Parse this response to get organization_id field and pass this value in each expense apis
    11  // https://www.zoho.com/expense/api/v1/#organization-id
    12  //
    13  // Alternatively organization_id can also be known after login to zoho web page at
    14  // https://expense.zoho.com/app#/organizations
    15  func (c *API) GetOrganization() (data OrganizationResponse, err error) {
    16  	endpoint := zoho.Endpoint{
    17  		Name:         OrganizationsModule,
    18  		URL:          fmt.Sprintf(ExpenseAPIEndpoint+"%s", OrganizationsModule),
    19  		Method:       zoho.HTTPGet,
    20  		ResponseData: &OrganizationResponse{},
    21  	}
    22  
    23  	err = c.Zoho.HTTPRequest(&endpoint)
    24  	if err != nil {
    25  		return OrganizationResponse{}, fmt.Errorf("Failed to retrieve organization: %s", err)
    26  	}
    27  
    28  	if v, ok := endpoint.ResponseData.(*OrganizationResponse); ok {
    29  		return *v, nil
    30  	}
    31  
    32  	return OrganizationResponse{}, fmt.Errorf("Data retrieved was not 'OrganizationResponse'")
    33  }
    34  
    35  // OrganizationResponse is the data returned by GetOrganization
    36  type OrganizationResponse struct {
    37  	Code          int    `json:"code"`
    38  	Message       string `json:"message"`
    39  	Organizations []struct {
    40  		AccountCreatedDate   string `json:"account_created_date"`
    41  		ContactName          string `json:"contact_name"`
    42  		CurrencyCode         string `json:"currency_code"`
    43  		CurrencyFormat       string `json:"currency_format"`
    44  		CurrencyID           string `json:"currency_id"`
    45  		CurrencySymbol       string `json:"currency_symbol"`
    46  		Email                string `json:"email"`
    47  		FiscalYearStartMonth int    `json:"fiscal_year_start_month"`
    48  		IsDefaultOrg         bool   `json:"is_default_org"`
    49  		IsOrgActive          bool   `json:"is_org_active"`
    50  		LanguageCode         string `json:"language_code"`
    51  		Name                 string `json:"name"`
    52  		OrganizationID       string `json:"organization_id"`
    53  		PricePrecision       int    `json:"price_precision"`
    54  		TimeZone             string `json:"time_zone"`
    55  	} `json:"organizations"`
    56  }