Back

Step by Step Guide to Building an Adobe Sign API Integration in Go

Aug 3, 20247 minute read

Introduction

Hey there, fellow Go enthusiast! Ready to dive into the world of digital signatures? In this guide, we'll walk through building an Adobe Sign API integration using Go. Adobe Sign's API is a powerful tool for automating document workflows, and with Go's simplicity and efficiency, we'll have this integration up and running in no time.

Prerequisites

Before we jump in, make sure you've got:

  • A Go environment set up (I know you've probably got this sorted already)
  • An Adobe Sign account with API credentials (if you don't have this, hop over to Adobe's site and get yourself set up)

Setting up the project

Let's kick things off by creating a new Go project:

mkdir adobe-sign-integration cd adobe-sign-integration go mod init github.com/yourusername/adobe-sign-integration

Now, let's grab the dependencies we'll need:

go get github.com/go-resty/resty/v2 go get golang.org/x/oauth2

Authentication

Alright, time to get our hands dirty with some code. First up, authentication:

import ( "golang.org/x/oauth2" "github.com/go-resty/resty/v2" ) func getAccessToken() (string, error) { config := &oauth2.Config{ ClientID: "YOUR_CLIENT_ID", ClientSecret: "YOUR_CLIENT_SECRET", Endpoint: oauth2.Endpoint{ AuthURL: "https://secure.echosign.com/public/oauth", TokenURL: "https://api.echosign.com/oauth/token", }, } token, err := config.PasswordCredentialsToken(context.Background(), "YOUR_USERNAME", "YOUR_PASSWORD") if err != nil { return "", err } return token.AccessToken, nil }

Basic API Requests

Now that we're authenticated, let's make a simple GET request:

func getAgreements() ([]byte, error) { client := resty.New() accessToken, err := getAccessToken() if err != nil { return nil, err } resp, err := client.R(). SetAuthToken(accessToken). Get("https://api.echosign.com/api/rest/v6/agreements") if err != nil { return nil, err } return resp.Body(), nil }

Creating and sending agreements

Time to create and send an agreement:

func createAgreement(name string, participantEmail string) error { client := resty.New() accessToken, err := getAccessToken() if err != nil { return err } agreement := map[string]interface{}{ "name": name, "participantSetsInfo": []map[string]interface{}{ { "memberInfos": []map[string]string{ {"email": participantEmail}, }, "order": 1, "role": "SIGNER", }, }, "signatureType": "ESIGN", "state": "IN_PROCESS", } _, err = client.R(). SetAuthToken(accessToken). SetBody(agreement). Post("https://api.echosign.com/api/rest/v6/agreements") return err }

Monitoring agreement status

To keep an eye on your agreement's status, you've got two options: webhooks or polling. Here's a simple polling example:

func pollAgreementStatus(agreementId string) { for { status, err := getAgreementStatus(agreementId) if err != nil { log.Printf("Error getting agreement status: %v", err) return } if status == "SIGNED" { log.Println("Agreement signed!") return } time.Sleep(30 * time.Second) } }

Handling signatures

Once your agreement is signed, you'll want to retrieve the signed document:

func getSignedDocument(agreementId string) ([]byte, error) { client := resty.New() accessToken, err := getAccessToken() if err != nil { return nil, err } resp, err := client.R(). SetAuthToken(accessToken). Get(fmt.Sprintf("https://api.echosign.com/api/rest/v6/agreements/%s/combinedDocument", agreementId)) if err != nil { return nil, err } return resp.Body(), nil }

Error handling and best practices

Remember to handle rate limits and implement retries. Here's a quick example:

func makeAPIRequest(url string) ([]byte, error) { client := resty.New(). SetRetryCount(3). SetRetryWaitTime(5 * time.Second). SetRetryMaxWaitTime(20 * time.Second) resp, err := client.R(). SetAuthToken(getAccessToken()). Get(url) if err != nil { return nil, err } return resp.Body(), nil }

Testing the integration

Don't forget to test your integration! Here's a simple test to get you started:

func TestCreateAgreement(t *testing.T) { err := createAgreement("Test Agreement", "[email protected]") if err != nil { t.Errorf("Failed to create agreement: %v", err) } }

Deployment considerations

When deploying, make sure to:

  • Securely store your API credentials (use environment variables or a secret management system)
  • Implement proper logging and monitoring
  • Consider using a rate limiter to avoid hitting API limits

Conclusion

And there you have it! You've just built a solid Adobe Sign API integration in Go. Remember, this is just scratching the surface - there's a lot more you can do with the Adobe Sign API. Check out their documentation for more advanced features and don't be afraid to experiment.

Happy coding, and may your signatures always be digital!