## Create signed URL tokens for videos `client.Stream.Token.New(ctx, identifier, params) (*TokenNewResponse, error)` **post** `/accounts/{account_id}/stream/{identifier}/token` Creates a signed URL token for a video. If a body is not provided in the request, a token is created with default values. ### Parameters - `identifier string` A Cloudflare-generated unique identifier for a media item. - `params TokenNewParams` - `AccountID param.Field[string]` Path param: The account identifier tag. - `ID param.Field[string]` Body param: The optional ID of a Stream signing key. If present, the `pem` field is also required. - `AccessRules param.Field[[]TokenNewParamsAccessRule]` Body param: The optional list of access rule constraints on the token. Access can be blocked or allowed based on an IP, IP range, or by country. Access rules are evaluated from first to last. If a rule matches, the associated action is applied and no further rules are evaluated. - `Action TokenNewParamsAccessRulesAction` The action to take when a request matches a rule. If the action is `block`, the signed token blocks views for viewers matching the rule. - `const TokenNewParamsAccessRulesActionAllow TokenNewParamsAccessRulesAction = "allow"` - `const TokenNewParamsAccessRulesActionBlock TokenNewParamsAccessRulesAction = "block"` - `Country []string` An array of 2-letter country codes in ISO 3166-1 Alpha-2 format used to match requests. - `IP []string` An array of IPv4 or IPV6 addresses or CIDRs used to match requests. - `Type TokenNewParamsAccessRulesType` Lists available rule types to match for requests. An `any` type matches all requests and can be used as a wildcard to apply default actions after other rules. - `const TokenNewParamsAccessRulesTypeAny TokenNewParamsAccessRulesType = "any"` - `const TokenNewParamsAccessRulesTypeIPSrc TokenNewParamsAccessRulesType = "ip.src"` - `const TokenNewParamsAccessRulesTypeIPGeoipCountry TokenNewParamsAccessRulesType = "ip.geoip.country"` - `Downloadable param.Field[bool]` Body param: The optional boolean value that enables using signed tokens to access MP4 download links for a video. - `Exp param.Field[int64]` Body param: The optional unix epoch timestamp that specficies the time after a token is not accepted. The maximum time specification is 24 hours from issuing time. If this field is not set, the default is one hour after issuing. - `Nbf param.Field[int64]` Body param: The optional unix epoch timestamp that specifies the time before a the token is not accepted. If this field is not set, the default is one hour before issuing. - `Pem param.Field[string]` Body param: The optional base64 encoded private key in PEM format associated with a Stream signing key. If present, the `id` field is also required. ### Returns - `type TokenNewResponse struct{…}` - `Token string` The signed token used with the signed URLs feature. ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" "github.com/cloudflare/cloudflare-go/stream" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) token, err := client.Stream.Token.New( context.TODO(), "ea95132c15732412d22c1476fa83f27a", stream.TokenNewParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), }, ) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", token.Token) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": { "token": "eyJhbGciOiJSUzI1NiIsImtpZCI6ImU5ZGI5OTBhODI2NjZkZDU3MWM3N2Y5NDRhNWM1YzhkIn0.eyJzdWIiOiJlYTk1MTMyYzE1NzMyNDEyZDIyYzE0NzZmYTgzZjI3YSIsImtpZCI6ImU5ZGI5OTBhODI2NjZkZDU3MWM3N2Y5NDRhNWM1YzhkIiwiZXhwIjoiMTUzNzQ2MDM2NSIsIm5iZiI6IjE1Mzc0NTMxNjUifQ.OZhqOARADn1iubK6GKcn25hN3nU-hCFF5q9w2C4yup0C4diG7aMIowiRpP-eDod8dbAJubsiFuTKrqPcmyCKWYsiv0TQueukqbQlF7HCO1TV-oF6El5-7ldJ46eD-ZQ0XgcIYEKrQOYFF8iDQbqPm3REWd6BnjKZdeVrLzuRaiSnZ9qqFpGu5dfxIY9-nZKDubJHqCr3Imtb211VIG_b9MdtO92JjvkDS-rxT_pkEfTZSafl1OU-98A7KBGtPSJHz2dHORIrUiTA6on4eIXTj9aFhGiir4rSn-rn0OjPRTtJMWIDMoQyE_fwrSYzB7MPuzL2t82BWaEbHZTfixBm5A" } } ```