CreateAPIKey generates an API key for the user ID provided. CreateToken should be used over CreateAPIKey. CreateToken allows better tracking of the token's usage and allows for custom expiration. Only use CreateAPIKey if you want to emulate the session created for a browser like login.
(ctx context.Context, user string)
| 83 | // Only use CreateAPIKey if you want to emulate the session created for |
| 84 | // a browser like login. |
| 85 | func (c *Client) CreateAPIKey(ctx context.Context, user string) (GenerateAPIKeyResponse, error) { |
| 86 | res, err := c.Request(ctx, http.MethodPost, fmt.Sprintf("/api/v2/users/%s/keys", user), nil) |
| 87 | if err != nil { |
| 88 | return GenerateAPIKeyResponse{}, err |
| 89 | } |
| 90 | defer res.Body.Close() |
| 91 | if res.StatusCode > http.StatusCreated { |
| 92 | return GenerateAPIKeyResponse{}, ReadBodyAsError(res) |
| 93 | } |
| 94 | |
| 95 | var apiKey GenerateAPIKeyResponse |
| 96 | return apiKey, json.NewDecoder(res.Body).Decode(&apiKey) |
| 97 | } |
| 98 | |
| 99 | type TokensFilter struct { |
| 100 | IncludeAll bool `json:"include_all"` |