Call the gRPC API
The Partner API answers gRPC at partner.api.sasha.eu:443, over TLS. It covers embed, lookup, jobs and Records, and adds two streaming operations: WatchJob and chunked media upload. This guide makes each call with buf curl (external link), which needs no generated code. A gRPC client generated from the same protos sends the same requests. Every RPC, message, and error is in the gRPC API reference.
Before you start
You need:
- Your Client ID and Client Secret (see Get access).
- The
bufCLI (external link).
--protocol grpc makes buf curl speak gRPC, and buf reads the schema through the server's reflection, so you need no copy of the protos.
Get an access token
Call AuthenticateWithClientCredential with your credentials. Replace <client-id> and <client-secret> with the Client ID and Client Secret from Get access:
buf curl --protocol grpc \
--data '{"clientId": "<client-id>", "clientSecret": "<client-secret>"}' \
https://partner.api.sasha.eu/sasha.partnerapi.v1.PartnerAPI/AuthenticateWithClientCredential
The response carries accessToken and expiresIn, the token's lifetime in seconds. Keep the token for the commands below:
export TOKEN="<the accessToken value>"
Reuse a token until it expires rather than asking for one per call. Handle token expiration shows how to refresh it.
Send the token with every call
Every other RPC needs the token in the Authorization metadata, as Bearer <token>. With buf curl the metadata is a header. This call submits an image for protection:
buf curl --protocol grpc \
-H "Authorization: Bearer $TOKEN" \
--data '{"mediaUrl": "https://example.com/photo.jpg", "mediaMimeType": "image/jpeg"}' \
https://partner.api.sasha.eu/sasha.partnerapi.v1.PartnerAPI/EmbedSignatureFromURL
The response holds the new job. Keep its jobId: SASHA protects the image in the background, and the job reports the result.
To send a file rather than a URL, stream it with EmbedSignatureFromData in chunks of at least 1 KiB, within the upload limits. SASHA joins the chunks into one file.
Follow the job
WatchJob sends the job's current state, then each change, and closes the stream when the job finishes, so you do not need to poll. Replace <job-id> with the jobId from the submit response:
buf curl --protocol grpc \
-H "Authorization: Bearer $TOKEN" \
--data '{"jobId": "<job-id>"}' \
https://partner.api.sasha.eu/sasha.partnerapi.v1.PartnerAPI/WatchJob
The job has finished when job.status is STATUS_COMPLETED or STATUS_FAILED. A completed embed job carries outputUrl, the URL of the protected image, which is valid until outputUrlExpiresAt, and the signatureId it was given. A failed job carries error.code and error.message.
A stream can end with an error before the job finishes, for example when the connection drops. Call WatchJob again: it only reads the job, so a repeat is safe, and it starts with the job's current state.
GetJob reads the job once, for a client that cannot hold a stream open:
buf curl --protocol grpc \
-H "Authorization: Bearer $TOKEN" \
--data '{"jobId": "<job-id>"}' \
https://partner.api.sasha.eu/sasha.partnerapi.v1.PartnerAPI/GetJob
Common failures
UNAUTHENTICATED with the reason TOKEN_EXPIRED | The token has expired. | Get a new token and send the call again. |
UNAUTHENTICATED without a reason | The Authorization metadata is missing, or the token is not valid. | Check that the metadata is Bearer followed by the whole accessToken. |
PERMISSION_DENIED | The Client ID is not allowed, or the token lacks the permission the RPC needs. | Check the Client ID and Client Secret, or ask SASHA to grant the permission. |
NOT_FOUND from WatchJob | No job has that jobId, or the job belongs to another Partner. | Check that you send the jobId from the submit response. |
UNAVAILABLE with the reason MEDIA_STAGING_FULL | SASHA is holding as much submitted media as it can. No job was created. | Wait the number of seconds in the retry-after trailer, then send the same request again, as Media waiting to be processed describes. |
UNAVAILABLE with 429 Too Many Requests in the status message | The rate limit rejected the call before it reached the API. The call did no work. | Send the call again with the backoff in Recover from a rejection. |
A reason is a google.rpc.ErrorInfo with the domain partner-api.sasha.eu, in the grpc-status-details-bin trailer. Each RPC's errors are listed under it in the reference.