Skip to content

Bug: AddSocialAccounts and DeleteSocialAccounts of UsersService return Invalid input #3921

@Not-Dhananjay-Mishra

Description

@Not-Dhananjay-Mishra

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.

Metadata

Metadata

Labels

Breaking API ChangePR will require a bump to the major version num in next release. Look here to see the change(s).bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions