PHP Curl with JSON data

878

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

curl https://www.bitrise.io/app/[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 = 'https://www.bitrise.io/app/[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);
    curl_close($ch); 
    var_dump($response);

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

Thank you.

407

Answer

Solution:

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

   $contact = json_decode(file_get_contents("https://api.xxxxx.com/contacts/v1/search/query"));
    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 = 'https://api.xxxx.com/contacts/v1/contact/vid/' . $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.
        @curl_close($ch);

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

Source

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.