PHP Curl with JSON data


I work on Bitrise and I tried to use there API in PHP. So I tried to convert this shell command in PHP :

curl[APP-SLUG]/build/start.json --data '{"hook_info":{"type":"bitrise","api_token":"[API-TOKEN]"},"build_params":{"tag":"1.0.0"}}'

Someone can help me? My result is false everytime. My code used :

$data_json = '{"hook_info":{"type":"bitrise","api_token":"[API-TOKEN]"},"build_params":{"tag":"1.0.0"}}';
$url = '[APP-SLUG]/build/start.json';

$ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS,$data_json);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response  = curl_exec($ch);

Bitrise give me my "secret" url and data informations, here it's just an example pattern of url and data given.

Thank you.




The code im using with curl is as this, and the only difference is the header

   $contact = json_decode(file_get_contents(""));
    if ($contact->contacts){
        $vid = $contact->contacts['0']->vid;

        //Need to populate these varilables with values from the form.
        $str_post = '{"properties": [{"property": "resume_link", "value": "'.$link.'"}]} ';

        //replace the values in this URL with your portal ID and your form GUID
        $endpoint = '' . $vid . '/profile?hapikey=xxxx';

        $ch = @curl_init();
        @curl_setopt($ch, CURLOPT_POST, true);
        @curl_setopt($ch, CURLOPT_POSTFIELDS, $str_post);
        @curl_setopt($ch, CURLOPT_URL, $endpoint);
        @curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/javascript'));
        @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        @curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS ,4000);
        @curl_setopt($ch, CURLOPT_TIMEOUT_MS, 4000);
        $response = @curl_exec($ch);  //Log the response from HubSpot as needed.

it returns me data, are you sure the endpoint is returning true when success??

People are also looking for solutions to the problem: php - Yii: ID getting overwritten on load


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.