I’m trying to POST some data to my table but I’m getting this error:
{“code”:8002,“message”:"Could not parse request with message: , status code 404, headers POST /6FB0xxxxxxxxxxxxxxx…
I’m not exactly sure what it means other than something is wrong.
My Php (I think) is okay, but maybe I guess there is a problem?
Note: I have columns in my table for both “email” and “score”.
$APP_ID=$_POST["applicationId"];//comes from C2 post data
$SECRET_KEY=$_POST["secretKey"];
$SUBMITTED_SCORE=$_POST["submittedScore"];
//https://api.backendless.com/<application-id>/<api-key>/<operation-specific-path>
// Get cURL resource
$curl = curl_init();
// Set some options - we are passing in a useragent too here
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://api.backendless.com/'.$APP_ID.'/'.$SECRET_KEY.'/data/Leaderboard_Game01/',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => array(
email => 'simon@bla.com',
score => ''.$SUBMITTED_SCORE
)
));
// Send the request & save response to $resp
$resp = curl_exec($curl);
echo ''.$resp;
// Close request to clear up some resources
curl_close($curl);
Hi Simon,
Does it help if you remove the trailing slash in URL?
CURLOPT_URL => 'https://api.backendless.com/'.$APP_ID.'/'.$SECRET_KEY.'/data/Leaderboard_Game01',
If I do that I get the error:
{“code”:17000,“message”:“JSON parse error: ‘Wrong JSON or ContentType.’.”}
Add a header ‘Content-Type:application/json’
Now I’m getting this error. Some mess up in the PHP which I’ll admit I really don’t understand:
Error:
{“code”:8002,“message”:"Could not parse request with message: Error decoding json body: com.fasterxml.jackson.core.JsonParseException: Unexpected character (’-’ (code 45)) in numeric value: expected digit (0-9) to follow minus sign,
My code:
$APP_ID=$_POST["applicationId"];//comes from C2 post data
$SECRET_KEY=$_POST["secretKey"];
$SUBMITTED_SCORE=$_POST["submittedScore"];
//https://api.backendless.com/<application-id>/<api-key>/<operation-specific-path>
// Get cURL resource
$curl = curl_init();
//$headers = []
// Set some options - we are passing in a useragent too here
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://api.backendless.com/'.$APP_ID.'/'.$SECRET_KEY.'/data/Leaderboard_Game01',
CURLOPT_USERAGENT => 'Codular Sample cURL Request',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => array(
email => 'simonblacom',
score => '333'.$SUBMITTED_SCORE
),
CURLOPT_HTTPHEADER =>array('Content-Type: application/json'),
));
// Send the request & save response to $resp
$resp = curl_exec($curl);
echo ''.$resp;
// Close request to clear up some resources
curl_close($curl);
I figured it out. I had to json_encode my POSTFIELDS. Eg:
CURLOPT_POSTFIELDS => json_encode(array(
email => 'simonblacom',
score => '333'.$SUBMITTED_SCORE))