Answers.Body: <p>It is pretty obvious now, but indeed the API is looking for json formatted values and I was in fact sending name:value pairs.</p>
  
  <p>Here is what the updated logic looks like for anyone who comes across this.</p>
  
  <p><strong>MyPlugin.php</strong></p>
  
  <pre><code>$client = new \Guzzle\Http\Client('http://api.site.dev/');
  $uri = 'my/endpoint/path';
  $post_data = array(
      'craft_id' =&gt; $event-&gt;params['user']-&gt;id,
      'name' =&gt; $event-&gt;params['user']-&gt;friendlyName,
      'email' =&gt; $event-&gt;params['user']-&gt;email
  );
  
  $data = json_encode($post_data);
  
  $request = $client-&gt;post($uri, array(
      'content-type' =&gt; 'application/json'
  ));
  
  $request-&gt;setBody($data);
  $response = $request-&gt;send();
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-15T21:25:16.533Z
Answers.LastActivityDate: 2016-08-15T21:25:16.533Z
Answers.UserDisplayName: Damon
Body: <p>I have a plugin that listens for new users to be created. I am then sending that user to system "B" via an API call. </p>
  
  <p>All is working fine the old fashion way, I am curious how to accomplish the same using Guzzle.</p>
  
  <pre><code>$client = new \Guzzle\Http\Client('http://api.site.dev/');
  $uri = 'my/endpoint/path';
  
  $request = $client-&gt;post($uri, array(
     'headers' =&gt; array('Content-type' =&gt; 'application/x-www-form-urlencoded'),
     'body' =&gt; array(
         'craft_id' =&gt; $event-&gt;params['user']-&gt;id,
         'name' =&gt; $event-&gt;params['user']-&gt;friendlyName,
         'email' =&gt; $event-&gt;params['user']-&gt;email
      ),
      'timeout' =&gt; 10
  ));
  
  $response = $request-&gt;send();
  </code></pre>
  
  <p>Each time I get this response/error back:</p>
  
  <pre><code>Client error response
  [status code] 422
  [reason phrase] Unprocessable Entity
  </code></pre>
  
  <p>Which tells me that system "B" isn't getting the information in the correct format. The docs aren't so great with post examples, so I'm not quite sure where I'm going down the wrong path.</p>
  
  <p>Thank you for any suggestions!</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-15T20:54:20.623Z
Comments.Text: Are the expecting the content to be JSON/XML encoded by chance?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-15T21:21:17.090Z
Comments.Text: Arg. Yep...that was the problem. Thanks Brad.
Comments.UserDisplayName: Damon
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-15T21:21:47.147Z
Comments.Text: NP! Be sure and add what worked as an answer, please. :)
Comments.UserDisplayName: Brad Bell
Tags: <plugin-development><guzzle>
Title: How do I use Guzzle to send a post request from my plugin?
ThreadText: # How do I use Guzzle to send a post request from my plugin?
  
  (Asked by: username_0 on 2016-08-15)
  
  I have a plugin that listens for new users to be created. I am then sending that user to system "B" via an API call.
  
  All is working fine the old fashion way, I am curious how to accomplish the same using Guzzle.
  
  ```
  $client = new \Guzzle\Http\Client('http://api.site.dev/');
  $uri = 'my/endpoint/path';
  
  $request = $client->post($uri, array(
     'headers' => array('Content-type' => 'application/x-www-form-urlencoded'),
     'body' => array(
         'craft_id' => $event->params['user']->id,
         'name' => $event->params['user']->friendlyName,
         'email' => $event->params['user']->email
      ),
      'timeout' => 10
  ));
  
  $response = $request->send();
  
  ```
  
  Each time I get this response/error back:
  
  ```
  Client error response
  [status code] 422
  [reason phrase] Unprocessable Entity
  
  ```
  
  Which tells me that system "B" isn't getting the information in the correct format. The docs aren't so great with post examples, so I'm not quite sure where I'm going down the wrong path.
  
  Thank you for any suggestions!
  
  **Tags:** plugin-development, guzzle
  
  > **Comments:**
  > **username_1**: Are the expecting the content to be JSON/XML encoded by chance?  
  > **username_0**: Arg. Yep...that was the problem. Thanks username_1.  
  > **username_1**: NP! Be sure and add what worked as an answer, please. :)  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2016-08-15. Score: 6 | Accepted answer
  
  It is pretty obvious now, but indeed the API is looking for json formatted values and I was in fact sending name:value pairs.
  
  Here is what the updated logic looks like for anyone who comes across this.
  
  **MyPlugin.php**
  
  ```
  $client = new \Guzzle\Http\Client('http://api.site.dev/');
  $uri = 'my/endpoint/path';
  $post_data = array(
      'craft_id' => $event->params['user']->id,
      'name' => $event->params['user']->friendlyName,
      'email' => $event->params['user']->email
  );
  
  $data = json_encode($post_data);
  
  $request = $client->post($uri, array(
      'content-type' => 'application/json'
  ));
  
  $request->setBody($data);
  $response = $request->send();
  
  ```
  
  
  ---
  
  