title: Validating PayPal Webhook calls with PayPal .NET SDK in Sandbox
body: <p>I've been trying to set up PayPal Webhooks (in Sandbox mode) to receive notifications about declined and successful payments.  My problem is that I can't get validation working.  Some details about my attempts:</p>
  
  <ol>
  <li>The app is an OWIN self-hosted Web API 2.</li>
  <li>Hosted as an Azure Web App, tested on Azure as well.</li>
  <li>I set the Paypal Webhook receiver URL in the Paypal dashboard to the URL of my endpoint on Azure.</li>
  <li>I used the Paypal Webhooks simulator from the Paypal dashboard to send a message to the Azure endpoint.</li>
  </ol>
  
  <p>I tried listening for Webhook calls two ways:</p>
  
  <ol>
  <li>ASP.NET Webhook Receivers (<a href="http://blogs.msdn.com/b/webdev/archive/2015/09/04/introducing-microsoft-asp-net-webhooks-preview.aspx" rel="nofollow">http://blogs.msdn.com/b/webdev/archive/2015/09/04/introducing-microsoft-asp-net-webhooks-preview.aspx</a>), which didn't work.  I get the error message "WebHook validation failed: "</li>
  <li><p>Tried creating a Web API endpoint to receive and validate the request, didn't work either. Code here:</p>
  
  <pre><code>[HttpPost]
  public async Task&lt;IHttpActionResult&gt; PaymentCaptureCompleted()
  {
      // Get the received request's headers
      NameValueCollection nvc = new NameValueCollection();
      foreach (var item in Request.Headers)
      {
          nvc.Add(item.Key, string.Join(",", item.Value));
      }
  
      // Get the received request's body
      var requestBody = await Request.Content.ReadAsStringAsync();
  
      var isValid = WebhookEvent.ValidateReceivedEvent(Api, nvc, requestBody, ConfigurationManager.AppSettings["paypal.webhook.id"]);
  
      if (isValid)
      {
          return Ok();
      }
      else
      {
          return BadRequest("Could not validate request");
      }
  }
  </code></pre></li>
  </ol>
  
  <p>There are a lot more details to this of course, but I'm not sure how much information is required to answer my question.  Just let me know what you need and I'll edit this question.</p>