Search for legislators that represent a given area


#1

I am implementing the search legislators by Lat and Long , but I am unable to pass the query parameter and getting below error after running php curl request

{"errors":[{"message":"Must provide query string."}]}

My php code is following

$post= array();
//required fields start
$post['latitude']           = "40.7460022";
$post['longitude']            = "-73.9584642";
$post['first']            = 100;
//required fields End



$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => "https://openstates.org/graphql",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($post),
CURLOPT_HTTPHEADER => array(
    "Cache-Control: no-cache",
    "Content-Type: application/json",
    "Postman-Token: 9f158d1c-92ea-4482-aaff-ac8283ccce20",
    "X-API-KEY: xxxxxxxxxxxxxxxxxxxxxxxxxxx"
),
));

$response = curl_exec($curl);
echo "<pre>";
print_r($response);
echo "</pre>";
$err = curl_error($curl);

curl_close($curl);

Can anyone help which thing I am missing thanks


#2

Your request body is not graphql. You probably have never used it for anything before; it’s quite different from the API’s you are used to. In my other response, I pointed at one blog post of mine; after seeing this, I’d suggest starting with the prior post.