According to API docs of AddSocialAccounts it accepts account_urls as body parameter. However, in the current implementation, accountURLs is passed directly.
It should instead be passed as:
req, err := s.client.NewRequest("POST", u, socialAccountRequest{AccountURLs: accountURLs})
or we can make a Struct for it (with struct it will be BREAKING CHANGE)
With this change, accountURLs will be sent in the correct format:
{"account_urls":["https://facebook.com/GitHub","https://www.youtube.com/@GitHub"]}
|
func (s *UsersService) AddSocialAccounts(ctx context.Context, accountURLs []string) ([]*SocialAccount, *Response, error) { |
|
u := "user/social_accounts" |
|
req, err := s.client.NewRequest("POST", u, accountURLs) |
|
if err != nil { |
|
return nil, nil, err |
|
} |
|
|
|
var accounts []*SocialAccount |
|
resp, err := s.client.Do(ctx, req, &accounts) |
|
if err != nil { |
|
return nil, resp, err |
|
} |
|
|
|
return accounts, resp, nil |
|
} |
same with DeleteSocialAccounts API docs
|
func (s *UsersService) DeleteSocialAccounts(ctx context.Context, accountURLs []string) (*Response, error) { |
|
u := "user/social_accounts" |
|
req, err := s.client.NewRequest("DELETE", u, accountURLs) |
|
if err != nil { |
|
return nil, err |
|
} |
|
|
|
return s.client.Do(ctx, req, nil) |
|
} |
To reproduce the issue:
client := github.NewClient(tc)
acc, res, err := client.Users.AddSocialAccounts(ctx, []string{"https://www.example.com"})
if err != nil {
fmt.Printf("Error adding social accounts: %v\n", err)
return
}
fmt.Printf("Added Social Accounts: %+v\n", acc)
fmt.Printf("Response: %+v\n", res)
This results in the following error:
Error adding social accounts: POST https://api.github.com/user/social_accounts: 422 Invalid request.
Invalid input: `["https://www.example.com"]` is not of type `object`. []
I can provide a PR to fix it.
According to API docs of
AddSocialAccountsit acceptsaccount_urlsas body parameter. However, in the current implementation, accountURLs is passed directly.It should instead be passed as:
or we can make a Struct for it (with struct it will be BREAKING CHANGE)
With this change, accountURLs will be sent in the correct format:
{"account_urls":["https://facebook.com/GitHub","https://www.youtube.com/@GitHub"]}go-github/github/users_social_accounts.go
Lines 50 to 64 in 9e7e51b
same with
DeleteSocialAccountsAPI docsgo-github/github/users_social_accounts.go
Lines 71 to 79 in 9e7e51b
To reproduce the issue:
This results in the following error:
I can provide a PR to fix it.