How to integrate the webhook with php?

634 views
Skip to first unread message

Geovane Krüger

unread,
May 25, 2021, 8:22:32 PM5/25/21
to Strava API
Would anyone have an example of how to integrate the webhook with php?

I have tried everything that my knowledge allows, but I have not succeeded until today.

Thank you very much.

Richard Mayhew

unread,
May 25, 2021, 8:30:41 PM5/25/21
to Geovane Krüger, Strava API
You can take the input data and convert to a normal $_POST array using the following:

$_POST = json_decode(file_get_contents('php://input'), true);

You can then read the data as you would with a normal post e.g. $_POST['object_id'].

Cheers,
Richard



--
You received this message because you are subscribed to the Google Groups "Strava API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to strava-api+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/strava-api/8eb6fe25-c570-4569-9153-e21a07955aban%40googlegroups.com.

Geovane Krüger

unread,
May 26, 2021, 7:21:52 AM5/26/21
to Strava API
But where or where should I do this?

I have a file where I tried to make "Subscription Creation Request"

<code>
Cria o cURL
$curl = curl_init();

Seta algumas opções
curl_setopt_array($curl, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_SSL_VERIFYPEER => true,
    CURLOPT_CUSTOMREQUEST => 'GET',
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => [
        'client_id' => $clientId,
        'client_secret' => $clientSecret,
        'callback_url'  => $callback,
        'verify_token'  => $tokenVerify,
    ]
]);

curl_error($curl);

Envia a requisição e salva a resposta
$response = curl_exec($curl);

Fecha a requisição e limpa a memória
curl_close($curl);

print_r($response);
</code>


But this me return:
stdClass Object ( [message] => Record Not Found [errors] => Array ( [0] => stdClass Object ( [resource] => resource [field] => path [code] => invalid ) ) )

I don't understand how I proceed with the "Subscription Validation Request"
For example, my callback url could be

But how do I capture or respond to "Callback Validation"




Richard Mayhew

unread,
May 27, 2021, 7:07:50 AM5/27/21
to Geovane Krüger, Strava API
The guide gives details of the URL to call and the post variables:  https://developers.strava.com/docs/webhooks/

You can either do this in PHP or send a curl request from a terminal.

You just need your callback url to pick up the response data in code and send a 200 response e.g.

    $response = $_GET['hub_challenge'];
    echo '{ "hub.challenge":"'.$response.'"}';

Then all future activities will be pushed to your webhook url


Reply all
Reply to author
Forward
0 new messages