In Bash script, I call something like that
# !/bin/bash
output=$(curl -L -H "Authorization: token MY_TOKEN" https://MY_GITHUB_ENTERPRISE/api/v3/repos/USER_NAME/REPO/pulls/123/files)
echo $output
I receive a string from output. I want to pass this string into php code to use json_decode function. What should I do?
I'm going to write code in PHP part like this. Is it ok? Sorry for the numb question because I'm a newbie in both Bash script and PHP
#!/usr/bin/php
$json = json_decode($DATA_FROM_CURL, true);
// Some logic in php
// continue with bash script
#!/usr/bin/bash
echo ABC
**Note: I have to write all codes in a Bash script file.
UPDATE 1 Thank for Felipe Valdes's suggestion, I updated my code like this. However, I got the return
{"message":"Bad credentials","documentation_url":"https://developer.github.com/enterprise/2.8/v3"}
My code:
#!/usr/bin/php
<?php
// create curl resource
$ch = curl_init();
$TOKEN = 'abclaldslsl';
$header = array();
$header[] = 'Content-length: 0';
$header[] = 'Content-type: application/json';
$header[] = 'Authorization: token'.TOKEN;
// set url
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_URL, "https://MY_GITHUB_ENTERPRISE/api/v3/repos/USER_NAME/REPO/pulls/123/files");
//return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// $output contains the output string
$output = curl_exec($ch);
// close curl resource to free up system resources
curl_close($ch);
print_r($output);
?>