I am making a request to an API using its post.rest web service. I have constructed the request using Postman. I get the error message, "Parameter 'query' is required, and it must have a value." I have been trying to work this out for several days, and I'm at my wits' end. I thought I could resolve it myself, but have not been successful. It seems like I've tried at least a hundred different permutations of the code.
Here is my PHP code for the request:
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://SDMDataAccess.sc.egov.usda.gov/Tabular/post.rest",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS =>
$data = array("query" => "SELECT l.areasymbol, l.areaname, l.lkey,
musym, muname, museq, mu.mukey
FROM sacatalog sac
INNER JOIN legend l ON l.areasymbol = sac.areasymbol
AND l.areatypename = 'Non-MLRA Soil Survey Area'
INNER JOIN mapunit mu ON mu.lkey = l.lkey
AND mu.mukey IN (455997)
", "FORMAT" => "JSON"),
CURLOPT_HTTPHEADER => array(
"Cache-Control: no-cache",
"Content-Type: application/json",
"Postman-Token: 520636bc-a062-4ab8-99e7-7edaae5118b4"
),
));
file_put_contents('soil_request.txt', $data);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
I am unable to find any examples of code for submitting rest requests to this API service in their documentation or elsewhere on the internet, even though their documentation is vast.
Thank you in advance for your consideration on this. I really appreciate it.
$data = json_encode($data);