-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Labels
Breaking API ChangePR will require a bump to the major version num in next release. Look here to see the change(s).PR will require a bump to the major version num in next release. Look here to see the change(s).bug
Description
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"]}
go-github/github/users_social_accounts.go
Lines 50 to 64 in 9e7e51b
| 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
go-github/github/users_social_accounts.go
Lines 71 to 79 in 9e7e51b
| 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.
gmlewis
Metadata
Metadata
Assignees
Labels
Breaking API ChangePR will require a bump to the major version num in next release. Look here to see the change(s).PR will require a bump to the major version num in next release. Look here to see the change(s).bug