package extensions import ( "context" "encoding/json" "fmt" "io" "net/http" "net/url" "go.fifitido.net/twitch/api/endpoint" ) type SetExtensionRequiredConfigurationRequest struct { // The ID of the extension to update. ExtensionID string `json:"extension_id"` // The version of the extension to update. ExtensionVersion string `json:"extension_version"` // The required_configuration string to use with the extension. RequiredConfiguration string `json:"required_configuration"` } // Updates the extension’s required_configuration string. // Use this endpoint if your extension requires the broadcaster to configure the extension before activating it // (to require configuration, you must select Custom/My Own Service in Extension Capabilities). // For more information, // see Required Configurations: https://dev.twitch.tv/docs/extensions/building#required-configurations // and Setting Required Configuration: https://dev.twitch.tv/docs/extensions/building#setting-required-configuration-with-the-configuration-service-optional // // Requires a signed JSON Web Token (JWT) created by an EBS. For signing requirements, // see Signing the JWT: https://dev.twitch.tv/docs/extensions/building/#signing-the-jwt // The signed JWT must include the role, user_id, and exp fields // (see JWT Schema: https://dev.twitch.tv/docs/extensions/reference/#jwt-schema). // Set the role field to external and the user_id field to the ID of the user that owns the extension. func (e *Extensions) SetExtensionRequiredConfiguration(ctx context.Context, broadcasterID string, body *SetExtensionRequiredConfigurationRequest) error { v := url.Values{"broadcaster_id": {broadcasterID}} r, w := io.Pipe() go func() { if err := json.NewEncoder(w).Encode(body); err != nil { w.CloseWithError(err) } else { w.Close() } }() req, err := http.NewRequestWithContext(ctx, http.MethodPut, endpoint.Make(e.baseUrl, "extensions/required_configuration", v), r) if err != nil { return err } res, err := e.client.Do(req) if err != nil { return err } defer res.Body.Close() statusOK := res.StatusCode >= 200 && res.StatusCode < 300 if !statusOK { return fmt.Errorf("failed to set extension required configuration (%d)", res.StatusCode) } return nil }