Creating a SharePoint list item with a geolocation field
In previous article, I showed how to create a SharePoint list with a hyperlink field using the Microsoft Graph API.
The 'trick' is to use the Prefer: apiversion=2.1 header to enforce the request to be routed to the beta version of the internal SharePoint API.
For geolocation field, I will start with a different approach. Let's create a SharePoint list with a geolocation field directly in the web browser.
While you type the address of your location, the SharePoint internally calls some https://outlook.office365.com/SchedulingB2/api/v1.0/me/findmeetinglocations endpoint to get the suggestions.

When you retreive the geolocation field using the Microsoft Graph API, you will see what properties are returned for the geolocation field and what's need to be filled when creating a new geolocation field.
GET /v1.0/sites/{site_id}/lists/{list_id}/items/{item_id}/fields
The response:
{
"Title": "Project1",
"ProjectUrl": {
"Description": "Project 1 Home Site",
"Url": "https://www.project-1.com"
},
"Location": {
"address": {
"city": "Praha 10",
"countryOrRegion": "Czechia",
"postalCode": "140 00",
"state": "Capital City of Prague",
"street": "Vyskočilova 1561/4a",
"type": "Unknown"
},
"coordinates": {
"latitude": 50.0482,
"longitude": 14.4573
},
"displayName": "Microsoft",
"locationUri": "https://www.bingapis.com/api/v6/localbusinesses/YN8046x576897103687762284",
"uniqueId": "https://www.bingapis.com/api/v6/localbusinesses/YN8046x576897103687762284"
},
"CountryOrRegion": "Czechia",
"State": "Capital City of Prague",
"City": "Praha 10",
"PostalCode": "140 00",
"Street": "Vyskočilova 1561/4a",
"GeoLoc": {
"latitude": 50.0482,
"longitude": 14.4573
},
"DispName": "Microsoft",
...
}
From the response, it's clear that the geolocation field requires information about the address and coordinates. The two big unknowns are uniqueId and locationUri properties. These properties contain some Bing API endpoint, but the Bing API itself is something which is not publically documented.
You may notice that the field also contains separate columns for CountryOrRegion, State, City, PostalCode, Street, GeoLoc, and DispName. These columns are read-only and automatically populated based on the geolocation field.
Let's try to create a SharePoint list item with the same geolocation field using the Microsoft Graph API, but without uniqueId and locationUri.
POST /v1.0/sites/{site_id}/lists/{list_id}/items/{item_id}/fields
Prefer: apiversion=2.1
{
"fields": {
"Title": "Project2",
"ProjectUrl": {
"Description": "Project 2 home site",
"Url": "https://www.project2.com"
},
"Location": {
"address": {
"city": "Praha 10",
"countryOrRegion": "Czechia",
"postalCode": "140 00",
"state": "Capital City of Prague",
"street": "Vyskočilova 1561/4a",
"type": "Unknown"
},
"coordinates": {
"latitude": 50.0482,
"longitude": 14.4573
},
"displayName": "Microsoft",
"locationUri": "",
"uniqueId": ""
}
}
}
Item is created, but when you check the SharePoint list, you will see that read-only columns CountryOrRegion, State, City, PostalCode, and Street are not populated.

Even if you try to edit the item, you will see that the location field is empty.

What's wrong? After some research, I've found out that properties for the Address inside the Location are case sensitive.
If the POST request body contains address properties that start with lowercase letters then read-only columns CountryOrRegion, State, City, PostalCode, and Street are not populated.
"Location": {
"address": {
"city": "Praha 10",
"countryOrRegion": "Czechia",
"postalCode": "140 00",
"state": "Capital City of Prague",
"street": "Vyskočilova 1561/4a",
"type": "Unknown"
}
The solution is to use capital letters for address properties.
"Location": {
"Address": {
"City": "Praha 10",
"CountryOrRegion": "Czechia",
"PostalCode": "140 00",
"State": "Capital City of Prague",
"Street": "Vyskočilova 1561/4a",
"Type": "Unknown"
}
So, the correct POST request including the request body is
POST /v1.0/sites/{site_id}/lists/{list_id}/items/{item_id}/fields
Prefer: apiversion=2.1
{
"fields": {
"Title": "Project2",
"ProjectUrl": {
"Description": "Project 2 home site",
"Url": "https://www.project2.com"
},
"Location": {
"Address": {
"City": "Praha 10",
"CountryOrRegion": "Czechia",
"PostalCode": "140 00",
"State": "Capital City of Prague",
"Street": "Vyskočilova 1561/4a",
"Type": "Unknown"
},
"coordinates": {
"latitude": 50.0482,
"longitude": 14.4573
},
"displayName": "Microsoft",
"locationUri": "",
"uniqueId": ""
}
}
}
Conclusion
At the moment, it's possible to create a geolocation field of a SharePoint list item using the Microsoft Graph API if you add the Prefer: apiversion=2.1 header to your request, but when specifying the address in the request body, all properties must start with capital letters.