Getting Started
Welcome to the HappyPathology API!
This guide will help you get up and running quickly.
Prerequisites
Section titled “Prerequisites”Before you begin, ensure you have:
- A signing key pair for the dev and one for prod environment (contact support if you don’t have one)
- A basic understanding of REST APIs and how to make http requestes including setting headers
- A basic understanding of JWT (JSON Web Tokens) and how to sign them
- A secure way to store your private key and access them from your application (for example AWS secrets manager, or GGP secrets manager)
Recommended tools
Section titled “Recommended tools”To manually make API requests and experiment with the API, we recommend using one of the following tools:
To manually create or view and validate JWTs, we recommend using one of the following tools:
How to create a signing key pair
Section titled “How to create a signing key pair”- First generate the private keys (one for dev and one for prod) using the following command:
ssh-keygen -t rsa -b 4096 -m PEM -f dev-happypathology-jwtRS256.keyssh-keygen -t rsa -b 4096 -m PEM -f prod-happypathology-jwtRS256.key- Then generate the public keys (one for dev and one for prod) using the following command:
openssl rsa -in dev-happypathology-jwtRS256.key -pubout -outform PEM -out dev-happypathology-jwtRS256.key.pubopenssl rsa -in prod-happypathology-jwtRS256.key -pubout -outform PEM -out prod-happypathology-jwtRS256.key.pub- Print the private key and public key to the console to visually verify that they look correct:
cat dev-happypathology-jwtRS256.keycat dev-happypathology-jwtRS256.key.pub
cat prod-happypathology-jwtRS256.keycat prod-happypathology-jwtRS256.key.pubor copy them to clipboard safely (without changing the line breaks or whitespace) using the following command:
# on macOS on at a timecat dev-happypathology-jwtRS256.key | pbcopy# now paste it to AWS Console secrets manager or Google Cloud secrets manager for your DEV environmentcat dev-happypathology-jwtRS256.key.pub | pbcopy# now paste it to AWS Console secrets manager or Google Cloud secrets manager for your DEV environmentcat prod-happypathology-jwtRS256.key | pbcopy# now paste it to AWS Console secrets manager or Google Cloud secrets manager for your PROD environmentcat prod-happypathology-jwtRS256.key.pub | pbcopy# now paste it to AWS Console secrets manager or Google Cloud secrets manager for your PROD environment
# on Linuxcat dev-happypathology-jwtRS256.key | xclip -selection clipboard# now paste it to AWS Console secrets manager or Google Cloud secrets manager for your DEV environmentcat dev-happypathology-jwtRS256.key.pub | xclip -selection clipboard# now paste it to AWS Console secrets manager or Google Cloud secrets manager for your DEV environmentcat prod-happypathology-jwtRS256.key | xclip -selection clipboard# now paste it to AWS Console secrets manager or Google Cloud secrets manager for your PROD environmentcat prod-happypathology-jwtRS256.key.pub | xclip -selection clipboard# now paste it to AWS Console secrets manager or Google Cloud secrets manager for your PROD environment-
Store the private keys in a secure location (like paste it from the clipboard to AWS Console secrets manager or Google Cloud secrets manager)
-
Send the public keys to us via email or through the support chat. As the name implies, the public key is public and does not need to be kept secret or treated as sensitive information.
Sign a JWT
Section titled “Sign a JWT”To sign a JWT, you will use your private key (for the corresponding environment, dev or prod). It is best if you use a JWT library for your programming language of choice. You can find a list of JWT libraries for your programming language of choice on the JWT.io website.
To sign the JWT you need:
- your private key (see above)
- your organization ID (you will receive this when you share your public key with us)
- your user ID (you will receive this when you share your public key with us)
- your key ID (you will receive this when you share your public key with us)
- audience (api.happypathology.com)
- expiration time (you can set it to 1 hour or less)
- issued at (current time)
for exmple if you are using Go, you can use the jwx library.
package main
import ( "crypto/x509" "encoding/pem" "fmt" "io/ioutil" "log" "math/rand" "os" "time"
"github.com/lestrrat-go/jwx/jwa" "github.com/lestrrat-go/jwx/jwk" "github.com/lestrrat-go/jwx/jwt")
// V1 examplefunc generateAuthToken() string { _PRIVATE_KEY_, err := ioutil.ReadFile("dev-happypathology-jwtRS256.key") if err != nil { log.Fatal(err) }
// create a new jwt issued := time.Now() exp := time.Now().Add(time.Hour) j := jwt.NewBuilder() j.Audience([]string{"api.happypathology.com"}) j.Expiration(exp) j.IssuedAt(issued) j.Issuer("Your Organization ID") j.JwtID(fmt.Sprintf("%d", time.Now().UnixNano())) j.Subject("Your User ID") j.Claim("kid", "Your Key ID")
token, err := j.Build() if err != nil { log.Fatal(err) } block, _ := pem.Decode(_PRIVATE_KEY_) key, err := x509.ParsePKCS1PrivateKey(block.Bytes) if err != nil { log.Fatalf("%v", err) }
kk, err := jwk.New(key) if err != nil { log.Fatal(err) } signedT, err := jwt.Sign(token, jwa.RS256, kk) if err != nil { log.Fatal(err) } return string(signedT)}Connectivity
Section titled “Connectivity”To verify your connectivity, you can make a GET request to the /heartbeat endpoint.
# dev# using curliecurlie https://dev.api.happypathology.com/heartbeat# or using curlcurl https://dev.api.happypathology.com/heartbeat
# prod# using curliecurlie https://api.happypathology.com/heartbeat# or using curlcurl https://api.happypathology.com/heartbeatYou will see a response similar to the following:
{ "status": 200, "results": { "delta": "30.603047ms", "heartbeat": "636483da28d5f7b0f701", "request_timestamp": 1764725619, "status": 200, "user-agent": "curl/8.7.1", "version": "happy_api.386.explicit-impersonation-request-check.f6b326f" }, "debug_info": { "delta": "30.643443ms", "version": "happy_api.386.explicit-impersonation-request-check.f6b326f" }}This is the shape of all responses from the API that return a json response.
Authentication
Section titled “Authentication”All authenticated API requests require an Authorization header to be included in the request.
The Authorization header should be in the format Bearer SIGNED_JWT.
The SIGNED_JWT should be generated using the private key of the signing key pair.
Before you can make requests, you must have already shared your public key with us.
Making your first authenticated request
Section titled “Making your first authenticated request”Here is a simple example to verify your connectivity:
# curliecurlie POST https://dev.api.happypathology.com/auth/hello "Authorization:Bearer eyJhbGciOiJS ...."# curlcurl https://api.happypathology.com/v1/auth/hello -H "Authorization:Bearer SIGNED_JWT"{ "status": 200, "results": { "auth_info": "Hello there!" }, "debug_info": { "delta": "54.156211ms", "version": "happy_api.386.explicit-impersonation-request-check.f6b326f" }}