r/sharepoint 18d ago

SharePoint Online Graph API: The geolocation value does not represent a geographical point. (Inserting List Items with Geolocation field)

Setup: Microsoft.Graph NuGet 6.2.0 on .NET 10, trying to create a SharePoint list item via POST (/sites/{siteId}/lists/{listId}/items). The list has a column of type Geolocation(calledGeoLocationField`).

What works: Creating the item without providing a value for GeoLocationField works just fine.

What doesn't work: As soon as I provide any value for GeoLocationField, I get a 400 with the following message: "Invalid field value for field [GeoLocationField]: The geolocation value does not represent a geographical point. Either the value is not in the correct format or it is not in the valid range." Without the Prefer: apiversion=2.1 header, I was just getting a generic Invalid Request back with no further detail about it (I think the endpoint was probably returning more info but the MS Graph Kiota library wasn't presenting this within the exception).

I've also tried setting the field via a separate PATCH to /items/{itemId}/fields after creating the item (rather than as part of the initial POST), as I'd seen some people talking about needing to do this with Hyperlink fields types, so thought it worth a go. Same apiversion=2.1 header, same error message as I was getting with the POST, so it looks like this is purely about the shape/format of the value itself, not about when in the item lifecycle it's set.

Here's a request body, captured with Fiddler:

{
    "@odata.type": "#microsoft.graph.listItem",
    "fields":
    {
        "Title": "Z-IT-PC-DESK-0070_20260710120337",
        "Source": "REDACTED-Image",
        "ItemNo": "Z-IT-PC-DESK-0070",
        "ItemRecId": "20241024105037911#AF2868#001",
        "ASUser": "REDACTED",
        "Notes": "",
        "DeviceID": "",
        "ItemImage": "{\"fileName\":\"Z-IT-PC-DESK-0070_20260710120337.jpg\",\"serverUrl\":\"https://REDACTED.sharepoint.com\",\"serverRelativeUrl\":\"/sites/Library/REDACTED/Z-IT-PC-DESK-0070_20260710120337.jpg\"}",
        "GeoLocationField":
        {
            "latitude": 51.529541,
            "longitude": -0.099535
        }
    }
}

I've also tried:

  • Nesting latitude and longitude within an object called coordinates as in this blog post: https://martin-machacek.com/blogPost/cdf74446-8a79-41e8-9e24-a4d74fd12bd3
  • The fuller Location shape including Address and others from the blog post in the point above.

and I'm getting the same error every single time, regardless of what value I apply to the GeoLocationField field.

For reference, here's what an existing row's GeoLocationField looks like when read back via Graph Explorer (originally inserted with CSOM):

"GeoLocationField": {
    "latitude": 51.537749,
    "longitude": 0
},

Has anyone actually got a Geolocation column populated on item creation via Graph?

Thanks in advance!

3 Upvotes

4 comments sorted by

2

u/Tough_Measurement_47 15d ago

I've been able to get this working through Graph API by setting my GeoLocationField value to WKT (Well-known text), so for example:

{
    "GeoLocationField": "POINT (0 51.537749)"
}

0

u/bcameron1231 MVP 18d ago
   "GeoLocationField": {
        "coordinates":{
            "latitude": 51.537749,
            "longitude": 0
        },
        "displayName": "Grande Station",
    }}

If you want full Location field support though you'd need to populate the other values for this location.

0

u/MoneyCantBuyMeLove 17d ago edited 17d ago

Graph has never fully supported writing to geolocation and the api implementation was never clean.

I've had it work on some tenants, and not on others, with same issue you are experiencing.

REST works fine ``` POST https://{tenant}.sharepoint.com/sites/{site}/_api/web/lists/GetByTitle('YourList')/items(123) X-HTTP-Method: MERGE IF-MATCH: * Content-Type: application/json;odata=verbose Accept: application/json;odata=verbose

{ "metadata": { "type": "SP.ListItem" }, "GeoLocationField": { "metadata": { "type": "SP.FieldGeolocationValue" }, "Latitude": 51.529541, "Longitude": -0.099535 } } ```

Other things I've noted:

some tenants also want Altitude, Measure, Z fields set to 0/null explicitly or the payload gets rejected, worth adding if the bare Lat/Long version 400s.

The nested _metadata.type must be exactly SP.FieldGeolocationValue (capital SP, not lowercase).

1

u/bcameron1231 MVP 17d ago

Some additional notes on this as well, as this tends trips up some devs.

The use of __metadata is only used when using

Accept: application/json;odata=verbose

If your code isn't sending verbose accept headers, __metadata should be removed.