github.com/schmorrison/Zoho@v1.1.4/README.md (about)

     1  [![](https://godoc.org/github.com/schmorrison/Zoho?status.svg)](http://godoc.org/github.com/schmorrison/Zoho)
     2  
     3  # Golang API Wrapper for Zoho Services
     4  
     5  This repo is an attempt to build a comprehensive API wrapper for Zoho Services.
     6  
     7  This will be a long project, with alot of boilerplate code that may benefit from code generation. Pull requests would be appreciated.
     8  
     9  - [ ] [Books](https://github.com/schmorrison/Zoho/tree/master/books)
    10  - [ ] [Bookings](https://github.com/schmorrison/Zoho/tree/master/bookings)
    11  - [ ] Campaigns
    12  - [ ] Cliq
    13  - [ ] Creator
    14  - [ ] [CRM](https://github.com/schmorrison/Zoho/tree/master/crm)
    15  - [ ] Desk
    16  - [ ] Docs
    17  - [ ] [Expense](https://github.com/schmorrison/Zoho/tree/master/expense)
    18  - [ ] Inventory
    19  - [ ] [Invoice](https://github.com/schmorrison/Zoho/tree/master/invoice)
    20  - [ ] Mail
    21  - [ ] Meeting
    22  - [ ] People
    23  - [ ] [Recruit](https://github.com/schmorrison/Zoho/tree/master/recruit)
    24  - [ ] Reports
    25  - [x] [Shifts](https://github.com/schmorrison/Zoho/tree/master/shifts)
    26  - [ ] [Subscriptions](https://github.com/schmorrison/Zoho/tree/master/subscriptions)
    27  
    28  The API's should ideally be useful and obvious. However, as it stands, the Zoho CRM API returns alot of dynamically typed fields which became incredibly difficult to parse, which eventually resulted in an implementation using reflect and a type switch to cast/convert the value from Zoho into the expected value for the struct. I expect this to be the case for alot of Zoho services.
    29  
    30  I will try to comment the code religously, and will read up on Go Doc so the generated documentation is useful for users.
    31  
    32  - [ ] Write a TODO list
    33  - [ ] Read up on writing Go Doc comments
    34  - [ ] Comment code religously
    35  - [ ] Write extensive unit tests
    36  - [ ] Start versioning commits to prevent major breaks
    37  
    38  ## A special thanks to Contributors
    39  
    40  - Thanks to @ashishsnigam for pull request #7.
    41  - Thanks to @beatscode for pull requests #10, #11, #12, #13, #18, & #19.
    42  - Thanks to @meyskens for pull request #14.
    43  - Thanks to @vazha for pull request #17.
    44  - Thanks to @VincentK-Titandc for pull request #21
    45  - Thanks to @rollulus for pull request #23
    46  - Thanks to @bondar-pavel for pull request #25 & #27
    47  - Thanks to @ysahil97 for PR #28, #34, #37 & #40
    48  - Thanks to @sfunkhouser for PR #39
    49  - Thanks to @Bibi40k for PR #42
    50  - Thanks to @ArneZsng for PR #44 & #45
    51  
    52  ## Requirements
    53  
    54  Golang v1.13 or above is required, follow the [official documentation](https://golang.org/doc/install) to install it on your system.
    55  The project uses go vendoring mode (aka. vgo) for dependencies management.
    56  
    57  ## Usage
    58  
    59  It is reasonable to assume that each API may provide different implementation, however they should all use the common methods available in Zoho.
    60  
    61  ### Getting the Zoho struct and starting oAuth2 flow
    62  
    63      import (
    64          "github.com/schmorrison/Zoho"
    65          "log"
    66      )
    67  
    68      func main() {
    69          z := zoho.New()
    70  
    71          // to start oAuth2 flow
    72          scopes := []zoho.ScopeString{
    73              zoho.BuildScope(zoho.Crm, zoho.ModulesScope, zoho.AllMethod, zoho.NoOp),
    74          }
    75  
    76          // The authorization request will provide a link that must be clicked on or pasted into a browser.
    77          // Sometimes it will show the consent screen, upon consenting it will redirect to the redirectURL (currently the server doesn't return a value to the browser once getting the code)
    78          // The redirectURL provided here must match the URL provided when generating the clientID/secret
    79          // if the provided redirectURL is a localhost domain, the function will create a server on that port (use non-privileged port), and wait for the redirect to occur.
    80          // if the redirect provides the authorization code in the URL parameter "code", then the server catches it and provides it to the function for generating AccessToken and RefreshToken
    81  
    82          if err := z.AuthorizationCodeRequest("yourClientID", "yourClientSecret", scopes, "http://localhost:8080/oauthredirect"); err != nil {
    83              log.Fatal(err)
    84          }
    85      }
    86  
    87  Alternatively, you may not want to have to click on the link. Perhaps you are running a script on cron, or otherwise. In these case you will want to generate the authorization code manually. This can be done by going to the zoho accounts developer console, and clicking the kebab icon (3 vertical dots) beside the specified token. Click on the 'Self-Client' option, it will prompt you to enter your scopes, and an expiry time. Then it will show you your authorization code.
    88  
    89  That code can be used to request Access and Request tokens as so.
    90  
    91      import (
    92          "log"
    93          "github.com/schmorrison/Zoho"
    94      )
    95  
    96      func main() {
    97          z := zoho.New()
    98  
    99          // to start oAuth2 flow
   100          scopes := []zoho.ScopeString{
   101              zoho.BuildScope(zoho.Crm, zoho.ModulesScope, zoho.AllMethod, zoho.NoOp),
   102          }
   103  
   104          if err := z.GenerateTokenRequest("yourClientID", "yourClientSecret", "authorizationCode", "redirectURL"); err != nil {
   105              log.Fatal(err)
   106          }
   107  
   108      }
   109  
   110  Your Zoho struct now has the oAuth token for that service/scope combination.
   111  
   112  Check the Readme in each services directory for information about using that service