title: Github WebHooks get branch details
body: <p>I'm trying to do the following:</p>
  <ol>
  <li>Create a Github webhook (done)</li>
  <li>Create a PHP/Node application GIHook points to (done)</li>
  <li>Process response (here is where problem lies)</li>
  <li>Depending on branch commited to, make a request to dev or live server to execute update.sh (done)</li>
  </ol>
  <p>Issue is the GIHook sends me this:</p>
  <pre><code>{
  &quot;REQUEST_METHOD&quot;:&quot;GET&quot;,
  &quot;CONTENT_TYPE&quot;:&quot;application\/json&quot;,
  &quot;headers&quot;:{
  &quot;Content-Type&quot;:&quot;application\/json&quot;,
  &quot;X-Hub-Signature-256&quot;:&quot;sha256=xxxx&quot;,
  &quot;X-Hub-Signature&quot;:&quot;sha1=xxx&quot;,
  &quot;X-Github-Hook-Installation-Target-Type&quot;:&quot;repository&quot;,
  &quot;X-Github-Hook-Installation-Target-Id&quot;:&quot;xxx&quot;,
  &quot;X-Github-Hook-Id&quot;:&quot;xxx&quot;,
  &quot;X-Github-Event&quot;:&quot;push&quot;,
  &quot;X-Github-Delivery&quot;:&quot;xxx&quot;,
  &quot;Referer&quot;:&quot;webhook url called&quot;,
  &quot;Accept&quot;:&quot;*\/*&quot;,
  &quot;User-Agent&quot;:&quot;GitHub-Hookshot\/8338482&quot;,
  &quot;Connection&quot;:&quot;close&quot;,
  &quot;X-Accel-Internal&quot;:&quot;\/internal-nginx-static-location&quot;,
  &quot;X-Real-Ip&quot;:&quot;xxx&quot;,
  &quot;Host&quot;:&quot;xxxx&quot;
  },
  &quot;JSON&quot;:&quot;&quot;,
  &quot;POST&quot;:[],
  &quot;GET&quot;:[],
  &quot;payload&quot;:null
  },
  </code></pre>
  <p>Which doesn't tell me which branch was commited to.</p>
  <p>So then I read a few more bits and pieces and found there is more information to be obtained but the question is how. So I would assumeed I would call an api and passback an id or something and after some googling it looked like this was the way. So I tested:</p>
  <pre><code># :HOOK_ID = X-Github-Hook-Id
  curl -o -v - https://api.github.com/repos/:GitHubUserNameInUrl/:PrivateRepo/hooks/:HOOK_ID
  </code></pre>
  <p>and done the same with php via curl and file get contents only to all return the same result:</p>
  <pre><code>{
  &quot;message&quot;: &quot;Not Found&quot;,
  &quot;documentation_url&quot;: &quot;https://docs.github.com/rest/reference/repos#get-a-repository-webhook&quot;
  }
  </code></pre>
  <p>Anyone have an idea how to get the payload from the response the webhook gives me (PHP or Node)?</p>
  <p>Thanks</p>
  <p>D</p>
  <p>RESPONSE 1
  Thanks for that reply, but I don't get any information such as you get from your webhook. Here is the code I use to test my response data when the webhook calls my url. JSON is always &quot;&quot; and POST,GET are always empty arrays [].</p>
  <pre><code>$file = 'log.json';
  
  $dte = date(&quot;d-m-y H:i:s&quot;);
  $headers = getallheaders();
  $data = [];
  $data[&quot;date&quot;] = $dte;
  $data[&quot;REQUEST_METHOD&quot;] = $_SERVER[&quot;REQUEST_METHOD&quot;];
  $data[&quot;CONTENT_TYPE&quot;] = $_SERVER[&quot;CONTENT_TYPE&quot;];
  $data[&quot;headers&quot;] = $headers;
  $data[&quot;JSON&quot;] = json_decode(file_get_contents('php://input')); // Always null || &quot;&quot;
  $data[&quot;POST&quot;] = $_POST; // Always []
  $data[&quot;GET&quot;] = $_GET; // Always []
  
  
  $hookid = $headers[&quot;X-Github-Hook-Id&quot;];
  $data[&quot;hook_id&quot;] = $hookid;
  
  $APIUrl = &quot;https://api.github.com/repos&quot;;
  $url = $APIUrl . &quot;/GITHUB_USER/REPO/hooks/&quot;.$hookid;
  $data[&quot;callback&quot;] = $url;
  
  // Using file_get_contents
  // $result = file_get_contents($url);
  // $payload = json_decode($result, true);
  
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_URL,$url);
  $result = curl_exec($ch);
  curl_close($ch);
  $payload = json_decode($result, true);
  $data[&quot;payload&quot;] = $payload;
  
  $out = json_encode($data) . &quot;,\n&quot;;
  file_put_contents($file, $out, FILE_APPEND | LOCK_EX);
  </code></pre>