title: curl PUT request with discord API resulting bad request
body: <p>I'm using php, oauth2, and curl to connect to the Discord API and add a member to a server (guild).</p>
  <p>I have successfully authenticated the user using Oath2 with the identify, guilds, and guilds.join scope.
  I have the access_token &amp; the bot token needed.</p>
  <p>From my understanding in the Discord API docs:
  <a href="https://discord.com/developers/docs/resources/guild#add-guild-member" rel="nofollow noreferrer">https://discord.com/developers/docs/resources/guild#add-guild-member</a></p>
  <p>I need to use a PUT request with the access_token (with guilds.join scope) and headers with Authentication: Bot Token to the endpoint: <a href="https://discordapp.com/api/guilds/GUILDID/members/USERID" rel="nofollow noreferrer">https://discordapp.com/api/guilds/GUILDID/members/USERID</a></p>
  <p>I have done this but receive a 400 Bad Request error.
  I am not sure what the problem could be.</p>
  <p>Config</p>
  <pre><code>define('OAUTH2_CLIENT_ID', 'REDACTED');
  define('OAUTH2_CLIENT_SECRET', 'REDACTED');
  
  $guildid = REDACTED
  
  $authorizeURL = 'https://discord.com/api/oauth2/authorize?client_id=REDACTED&amp;permissions=0&amp;redirect_uri=https%3A%2F%2FREDACTED%2Findex.php%3Faction%3Ddiscord&amp;response_type=code&amp;scope=identify%20guilds%20guilds.join%20bot';
  $tokenURL = 'https://discordapp.com/api/oauth2/token';
  $apiURLBase = 'https://discordapp.com/api/users/@me';
  $apiURLGuilds = 'https://discordapp.com/api/users/@me/guilds';
  $apiURLJoin = 'https://discordapp.com/api/guilds/'. $guildid . '/members/';
  
  </code></pre>
  <p>join function</p>
  <pre><code>function joinapiRequest($url,$userid) {
    $url = $url.$userid;
  
    $params = 'access_token='.session('access_token');
    
  
  
    $ch = curl_init($url);
  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
    curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
  
    $bottoken = redacted;
    $headers[] = 'Authorization: Bot ' . $bottoken;
    $headers[] = 'Content-Type: application/json';
    $headers[] = 'Content-Length: '.strlen($params);
    
    
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  
    $http = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    $response = curl_exec($ch);
  
    echo 'join guild response &lt;br /&gt;';
    var_dump($response);
    
  
    if($http == 201){
      return true;
    } else {
      return false;
    }
  
  
  }
  </code></pre>
  <p>response</p>
  <pre><code>string(42) &quot;{&quot;message&quot;: &quot;400: Bad Request&quot;, &quot;code&quot;: 0}&quot; 
  
  </code></pre>
  <p>Any help would be much appreciated.</p>