# Using RC API with PHP

**URL:** <https://forums.rocket.chat/t/using-rc-api-with-php/2301>\
**Category:** Community Support\
**Created:** [October 21, 2018, 12:17pm UTC](https://forums.rocket.chat/t/using-rc-api-with-php/2301 "2018-10-21T12:17:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![edmond](https://avatars.discourse-cdn.com/v4/letter/e/fbc32d/32.png) [@edmond](https://forums.rocket.chat/u/edmond)\
**Post date:** [October 21, 2018, 12:17pm UTC](https://forums.rocket.chat/t/using-rc-api-with-php/2301/1 "2018-10-21T12:17:14Z")

</div>

I wrote the following PHP code and I always obtain Response HTTP Status Code : 400 Response HTTP Body : 400 Bad Request400 Bad Request when I run it . What goes wrong:

// create curl resource  
$ch = curl\_init();  
// set url  
curl\_setopt($ch, CURLOPT\_URL, ‘[https://myRCserver/api/v1/login](https://myRCserver/api/v1/login) -d “user=john&password=doe”’);

```
    //return the transfer as a string 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

    // $resp contains the output string 
    $resp = curl_exec($ch); 
    if(!$resp) {
        die('Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch));
      } else {
        echo "Response HTTP Status Code : " . curl_getinfo($ch, CURLINFO_HTTP_CODE);
        echo "\nResponse HTTP Body : " . $resp;
      }
    echo $resp ;

    // close curl resource to free up system resources 
    curl_close($ch);
```
