Post-Migrator/services/wordpress/create-user.go

38 lines
982 B
Go

package wordpress
import (
"encoding/json"
"federated.computer/wp-sync-slowtwitch/utilities"
)
type CreateUser struct {
Username string `json:"username"`
Email string `json:"email"`
Roles string `json:"roles"`
Password string `json:"password"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
}
type CreateUserResponse struct {
Id int `json:"id"`
Username string `json:"username"`
Email string `json:"email"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
}
func (parameters *CreateUser) Execute(baseUrl, user, pass string) (CreateUserResponse, error) {
endpoint := baseUrl + "wp-json/wp/v2/users"
body, err := utilities.PostHttpRequestToWordpress(endpoint, user, pass, parameters)
if err != nil {
return CreateUserResponse{}, err
}
var userData CreateUserResponse
err = json.Unmarshal(body, &userData)
if err != nil {
return CreateUserResponse{}, err
}
return userData, nil
}