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.
Before we jump in, make sure you've got:
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
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 }
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 }
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 }
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) } }
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 }
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 }
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) } }
When deploying, make sure to:
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!