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) |
| iferr!=nil { |
| returnnil, nil, err |
| } |
| |
| varaccounts []*SocialAccount |
| resp, err:=s.client.Do(ctx, req, &accounts) |
| iferr!=nil { |
| returnnil, resp, err |
| } |
| |
| returnaccounts, resp, nil |
| } |
same with DeleteSocialAccountsAPI docs
| func (s*UsersService) DeleteSocialAccounts(ctx context.Context, accountURLs []string) (*Response, error) { |
| u:="user/social_accounts" |
| req, err:=s.client.NewRequest("DELETE", u, accountURLs) |
| iferr!=nil { |
| returnnil, err |
| } |
| |
| returns.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"})
iferr!=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.