title: Newsletter2Go REST API - How to add new recipient to list?
body: <p>Is it possible to add a new recipient via the REST API of Newsletter2Go?</p>
  
  <p>I tried it like this (snippet):</p>
  
  <pre><code>public function subscribeAction()
  {
      $this-&gt;init();
  
      $email = $this-&gt;getRequest()-&gt;getParam('email');
      $gender = $this-&gt;getRequest()-&gt;getParam('gender');
      $first_name = $this-&gt;getRequest()-&gt;getParam('first_name');
      $last_name = $this-&gt;getRequest()-&gt;getParam('last_name');
  
      $endpoint = "/recipients";
      $data = array(
          "list_id" =&gt; $this-&gt;listId,
          "email" =&gt; $email,
          "gender" =&gt; $gender,
          "first_name" =&gt; $first_name,
          "last_name" =&gt; $last_name,
      );
  
      $response = $this-&gt;curl($endpoint, $data);
  
      var_dump($response);
  }
  
  /**
   * @param $endpoint string the endpoint to call (see docs.newsletter2go.com)
   * @param $data array tha data to submit. In case of POST and PATCH its submitted as the body of the request. In case of GET and PATCH it is used as GET-Params. See docs.newsletter2go.com for supported parameters.
   * @param string $type GET,PATCH,POST,DELETE
   * @return \stdClass
   * @throws \Exception
   */
  public function curl($endpoint, $data, $type = "GET")
  {
      if (!isset($this-&gt;access_token) || strlen($this-&gt;access_token) == 0) {
          $this-&gt;getToken();
      }
      if (!isset($this-&gt;access_token) || strlen($this-&gt;access_token) == 0) {
          throw new \Exception("Authentication failed");
      }
      return $this-&gt;_curl('Bearer ' . $this-&gt;access_token, $endpoint, $data, $type);
  }
  
  private function _curl($authorization, $endpoint, $data, $type = "GET")
  {
      $ch = curl_init();
      $data_string = json_encode($data);
      $get_params = "";
      if ($type == static::METHOD_POST || $type == static::METHOD_PATCH) {
          curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
      if ($type == static::METHOD_POST) {
          curl_setopt($ch, CURLOPT_POST, true);
      }
      } else {
          if ($type == static::METHOD_GET || $type == static::METHOD_DELETE) {
              $get_params = "?" . http_build_query($data);
          } else {
              throw new \Exception("Invalid HTTP method: " . $type);
          }
      }
      curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $type);
      curl_setopt($ch, CURLOPT_URL, static::BASE_URL . $endpoint . $get_params);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($ch, CURLOPT_HTTPHEADER, array(
          'Content-Type: application/json',
          'Authorization: ' . $authorization,
          'Content-Length: ' . ($type == static::METHOD_GET || $type == static::METHOD_DELETE) ? 0 : strlen($data_string)
      ));
      if (!$this-&gt;sslVerification) {
          curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
      }
      $response = curl_exec($ch);
      curl_close($ch);
      return json_decode($response);
  }
  </code></pre>
  
  <p><a href="https://docs.newsletter2go.com/#!/Recipient/createRecipient" rel="nofollow noreferrer">https://docs.newsletter2go.com/#!/Recipient/createRecipient</a></p>
  
  <p>But I get a big response object, even though I only try to add one single recipient, and the new recipient is not added to the list.</p>
  
  <pre><code>object(stdClass)#188 (3) {
    ["status"]=&gt;
    int(200)
    ["info"]=&gt;
    object(stdClass)#169 (3) {
      ["links"]=&gt;
      object(stdClass)#43 (3) {
        ["_href"]=&gt;
        string(60) "https://api.newsletter2go.com/recipients?_limit=50&amp;_offset=0"
        ["_next"]=&gt;
        string(61) "https://api.newsletter2go.com/recipients?_limit=50&amp;_offset=50"
        ["_last"]=&gt;
        string(63) "https://api.newsletter2go.com/recipients?_limit=50&amp;_offset=3433"
      }
      ["count"]=&gt;
      int(3483)
      ["additional"]=&gt;
      object(stdClass)#167 (1) {
        ["active"]=&gt;
        int(0)
      }
    }
    ["value"]=&gt;
    array(50) {
      [0]=&gt;
      object(stdClass)#85 (2) {
        ["_href"]=&gt;
        string(49) "https://api.newsletter2go.com/recipients/n9yldrar"
        ["id"]=&gt;
        string(8) "n9yldrar"
      }
      [1]=&gt;
      object(stdClass)#185 (2) {
        ["_href"]=&gt;
        string(49) "https://api.newsletter2go.com/recipients/pgwvgwmr"
        ["id"]=&gt;
        string(8) "pgwvgwmr"
      }
                ...
      [49]=&gt;
      object(stdClass)#87 (2) {
        ["_href"]=&gt;
        string(49) "https://api.newsletter2go.com/recipients/usa0dx4n"
        ["id"]=&gt;
        string(8) "usa0dx4n"
      }
  </code></pre>