Proximity beacon API, Invalid JSON payload received

335 views Asked by At

Can someone help me with this. I'm new to Eddystone Beacon and this is my first time to use a Google Cloud API (Proximity beacon api). I'm trying to add a Nearby Notification to one of my registered beacons (that can be done in google beacon dashboard) via Proximity Beacon API and wondering why am I getting this error:

{ "error": { "code": 400, "message": "Invalid JSON payload received. Unknown name \"{\"attachmentName\":\"beacon_eddystone\",\"data\":\"eyJ0aXRsZSI6IlNJTSBUZXN0IiwidXJsIjoiaHR0cDpcL1wvd3d3LnN1cmlnYW9pbnRlcm5ldG1hcmtldGluZy5jb20ifQ\": Cannot bind query parameter. Field '{\"attachmentName\":\"beacon_eddystone\",\"data\":\"eyJ0aXRsZSI6IlNJTSBUZXN0IiwidXJsIjoiaHR0cDpcL1wvd3d3LnN1cmlnYW9pbnRlcm5ldG1hcmtldGluZy5jb20ifQ' could not be found in request message.", "status": "INVALID_ARGUMENT", "details": [ { "@type": "type.googleapis.com/google.rpc.BadRequest","fieldViolations": [ { "description": "Invalid JSON payload received. Unknown name \"{\"attachmentName\":\"beacon_eddystone\",\"data\":\"eyJ0aXRsZSI6IlNJTSBUZXN0IiwidXJsIjoiaHR0cDpcL1wvd3d3LnN1cmlnYW9pbnRlcm5ldG1hcmtldGluZy5jb20ifQ\": Cannot bind query parameter. Field '{\"attachmentName\":\"beacon_eddystone\",\"data\":\"eyJ0aXRsZSI6IlNJTSBUZXN0IiwidXJsIjoiaHR0cDpcL1wvd3d3LnN1cmlnYW9pbnRlcm5ldG1hcmtldGluZy5jb20ifQ' could not be found in request message." } ] } ] } } 

I made an HttpRequest using cURL in php and here's the code:

$array = array();
$array['title'] = "SIM Test";
$array['url'] = "http://www.surigaointernetmarketing.com";
$data = base64_encode(json_encode($array));

//echo $data;

$curl = curl_init(); 

curl_setopt_array($curl, array( 
    CURLOPT_URL => 'https://proximitybeacon.googleapis.com/v1beta1/beacons/<my-beacon-name>/attachments?projectId=<my-project-id>', 
    CURLOPT_RETURNTRANSFER => true, 
    CURLOPT_ENCODING => "", 
    CURLOPT_MAXREDIRS => 10, 
    CURLOPT_TIMEOUT => 30, 
    CURLOPT_HTTP_VERSION => 
    CURL_HTTP_VERSION_1_1, 
    CURLOPT_CUSTOMREQUEST => 'POST', 
    CURLOPT_POSTFIELDS => '{"attachmentName":"beacon_eddystone","data":"'.$data.'","namespacedType":"com.google.nearby/en"}', 
    CURLOPT_HTTPHEADER => array( "authorization: Bearer <my-bearer-token>" ),)); 

$response = curl_exec($curl); 
$err = curl_error($curl); 
curl_close($curl); 

if ($err)
    echo "cURL Error #:" . $err; 
else
    echo $response;

I got the code from here. And followed the instructions in the Get Started with the Proximity Beacon REST API. There must be a mistake in the http request body (CURLOPT_POSTFIELDS). And I couldn't figure it out why, please help.

0

There are 0 answers