Strava API returning "malformed request" on webhook registration

908 Views Asked by At

I'm trying to use Strava events, so i have to register a webhook. All fine.

1) I make a post request to initiate the process of registering the webhook.

    curl -X POST https://api.strava.com/api/v3/push_subscriptions \
    -F client_id=MY_APP_ID \
    -F client_secret=MY_CLIENT_SECRET \
    -F 'callback_url=MY_DOMAIN/webhook/strava' \
    -F 'verify_token=MY_VERIFY_TOKEN'

2) I have my route setup

    Route::match(['get', 'post'], '/webhook/strava', 'StravaController@webhook');

3) My controller returns valid json response with code 200 and all the data needed

    public function webhook(Request $request)
    {
        Log::info($request->input('hub.challenge'));

        return response()->json([
            'hub.challenge' => $request->input('hub.challenge')
        ], 200);
    }

But when i make the post it returns:

{"message":"Bad Request","errors":[{"resource":"PushSubscription","field":"challenge response","code":"challenge response malformed"}]}

Details: I noticed that the log statement is not fired. So maybe it's saying malformed becouse it's returning {"hub.challenge": null}. But i think in that case, the error message would be different.

Thank you guys!

2

There are 2 best solutions below

0
On

use underscore. like this

$mode = $request->get('hub_mode');
$token = $request->get('hub_verify_token');
$challenge = $request->get('hub_challenge');
0
On

Following Code response worked for me:

return response()->json([
    'hub.challenge' => Input::get('hub.challenge',Input::get("hub_challenge",TRUE))
], 200);