0

I want to use the Discord API for my web app written in PHP. I have an OAuth2 token and a bot token from Discord and I want to add a member to a guild with the API. Currently I'm getting the following error:

object(stdClass)#24 (1) { ["access_token"]=> array(1) { [0]=> string(22) "This field is required" } }

My code:

curl_setopt_array($request, [
                            CURLOPT_URL => "https://discordapp.com/api/guilds/[id]/members/" . $user->id,
                            CURLOPT_CUSTOMREQUEST => "PUT",
                            CURLOPT_POSTFIELDS => [
                                "access_token" => $access_token, // oauth2 access token
                            ],
                            CURLOPT_HTTPHEADER => [
                                "Authorization: Bot [token]", //bot token
                                "Content-Type: application/json",
                            ],
                            CURLOPT_RETURNTRANSFER => true,
                        ]);

I don't understand the error This field is required, since I send all the required fields. Am I missing something?

hmakholm left over Monica
  • 23,074
  • 3
  • 51
  • 73
error56
  • 1
  • 1
  • Possible duplicate of [PHP cURL HTTP PUT](https://stackoverflow.com/questions/5043525/php-curl-http-put) – misorude Jul 29 '19 at 13:35
  • Passing an array to CURLOPT_POSTFIELDS when using PUT does not seem to work, you need to provide the data in query string format explicitly yourself - https://stackoverflow.com/a/49507010/10283047 – misorude Jul 29 '19 at 13:35

0 Answers0