<?php
$entryData = [
'category' => 'radfahren',
'date' => '2019-11-05',
'duration' => 120,
'distance' => 47230,
'nightride' => false,
'description' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit.',
];
// initialize curl ressource handle
$c = curl_init('https://winterpokal.mtb-news.de/api/v1/entries/add.json');
// send request as POST
curl_setopt($c, CURLOPT_POST, true);
// set API token and content type headers
curl_setopt(
$c,
CURLOPT_HTTPHEADER,
[
'api-token: DFHDGFEHGDHFBXCBXSRTHGBDBNBDBQETSSAG',
'content-type: application/json',
]
);
// pass data as JSON-encoded POST body
curl_setopt(
$c,
CURLOPT_POSTFIELDS,
json_encode($entryData, JSON_THROW_ON_ERROR)
)
// store the response body into a variable instead of directly printing it
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
// execute the request
$result = curl_exec($c);
if (false === $result) {
throw new RuntimeException('ERR_CURL_REQUEST_FAILED');
}
$parsed_result = json_decode($result);
if (null === $parsed_result) {
throw new RuntimeException('ERR_CANNOT_DECODE_RESPONSE');
}
print_r($parsed_result);