I'm trying to get started with the Bing dataflow API called from Python to batch geocode addresses. For simplicity, I'm using csv input format. I've consistently encountered a 400 status code, "One or more parameters are not valid." To try to get a working example, I'm using Microsoft's sample csv input data copied directly from the docs (web page: Geocode Dataflow Sample Input and Output Data Version 2.0). Here is my test code:
def _testApiCall():
payload = "Bing Spatial Data Services, 2.0\n"
payload += "Id, GeocodeRequest/Culture, *plus the rest of the long line of field names*"
payload += "1,en-US,,One Microsoft Way,WA,,,,Redmond,98052\n"
payload += "3,en-US,One Microsoft Way, Redmond, Wa\n"
payload += "4,en-gb"
url = f"https://spatial.virtualearth.net/REST/v1/dataflows/geocode?input=csv&output=json&key={bingMapsKey}"
response = requests.post(url, data=payload.encode('utf-8'))
with open("response.json", "w") as response_file:
json.dump(response.json(), response_file, indent=4)
the response file always contains:
{
"authenticationResultCode": "ValidCredentials",
"brandLogoUri": ...,
"copyright": ...,
"errorDetails": [
"One or more parameters are not valid.",
": The data uploaded in this request was missing or invalid."
],
"resourceSets": [],
"statusCode": 400,
"statusDescription": "Bad Request",
"traceId": "a45bd0371d8e4a55b5e415305710ef80|BN00006676|0.0.0.0"
}
Can't figure out what I'm doing wrong, or what parameters it's referring to.
I've reduced the code to the bare minimum for the call, and replicated MS's sample data. My API key is validated so apparently the URL is basically OK. Was expecting the normal result with a job ID and links to download data. Can't seem to get beyond this status 400 failure. What am i missing? Thanks.