Getting location data from the API

The Micro.blog help documents have a topic on adding location data using the micropub endpoint, but I can’t find any information on retrieving that information via the API.

I can see coordinates sent with a post in Micro.blog’s post list view and coordinates are available via front matter in the post.

I’ve tried getting the post from both the /micropub endpoint and /xmlrpc endpoint, but both endpoints only have the standard fields (e.g content, published date, post status).

Is there a way to request additional fields? Ideally I’d like to be able to get any fields that are available in front matter using the API.

In the Micropub spec there is information on requesting specific properties, so I thought it might be possible to request non-default properties that way. For example:

https://micro.blog/micropub?q=source&properties[]=content&properties[]=location&properties[]=published&url=https://example.micro.blog/2019/10/27/texas-capitol-grounds.html

Would return:

{
    "type": "h-entry",
    "properties": {
        "content": [
            "Texas Book Festival."
        ],
        "published": [
            "2019-10-27T14:51:32-0500"
        ],
        "location": [
            {
                "name": [
                    "Texas Capitol Grounds"
                ],
                "url": [
                    "https://foursquare.com/v/4d8a30f199c2a1cd53508bd7"
                ],
                "latitude": [
                    30.273892650534542
                ],
                "longitude": [
                    -97.74060666521329
                ]
            }
        ]
    }
}

Is this available through any APIs?

Sorry, this is an oversight. I’m working on adding location to the Micropub responses.

1 Like

This change has been made. Let me know if the Micropub responses look wrong anywhere. It only includes location if the latitude and longitude are set, in which case it includes them for all responses, no need to request those properties.

1 Like

This is great. Thank you for making that adjustment so quickly. Two follow up questions :slight_smile:

  • Is it possible to get location_url and location_name added to posts front matter? This would be nice to have access to in a template to, for example, add a friendly name in the post list or show a map w/ a link back to the venue.
  • Are there any plans to support location via XML-RPC so posts from Mars Edit could include, for example: location_latitude, location_longitude, location_url, location_name as custom fields that get added to post the same way it would for Micropub?

Yes, not sure why name and URL weren’t included. I think I’m going to restructure the front matter a little, to have a new location field with fields name, url, etc. In other words, accessed via .Params.location.latitude instead of underscores.

For MarsEdit, would this be accessed from MarsEdit’s support for custom server fields? I wasn’t actually sure if that worked with Micro.blog… If it does, that sounds like it would be good to support for locations.

Yes, not sure why name and URL weren’t included. I think I’m going to restructure the front matter a little, to have a new location field with fields name , url , etc. In other words, accessed via .Params.location.latitude instead of underscores.

Thank you, that structure makes sense to me.

For MarsEdit, would this be accessed from MarsEdit’s support for custom server fields? I wasn’t actually sure if that worked with Micro.blog… If it does, that sounds like it would be good to support for locations.

Yes, that is what I was thinking, but it doesn’t currently work with Micro.blog. I think Micro.blog would have to be updated to support the custom fields member structure. An example POST request would look like this (with the location_* fields updated to match whatever field names Micro.blog would expect):

<?xml version="1.0" encoding="utf-8"?>
<methodCall>
    <methodName>microblog.newPost</methodName>
    <params>
        <param>
            <value>
                <string>[blog_id]</string>
            </value>
        </param>
        <param>
            <value>
                <string>bwlng</string>
            </value>
        </param>
        <param>
            <value>
                <string>[password]</string>
            </value>
        </param>
        <param>
            <value>
                <struct>
                    <member>
                        <name>post_status</name>
                        <value>
                            <string>published</string>
                        </value>
                    </member>
                    <member>
                        <name>flNotOnHomePage</name>
                        <value>
                            <boolean>0</boolean>
                        </value>
                    </member>
                    <member>
                        <name>custom_fields</name>
                        <value>
                            <array>
                                <data>
                                    <value>
                                        <struct>
                                            <member>
                                                <name>key</name>
                                                <value>
                                                    <string>location_name</string>
                                                </value>
                                            </member>
                                            <member>
                                                <name>value</name>
                                                <value>
                                                    <string>French Truck Coffee</string>
                                                </value>
                                            </member>
                                        </struct>
                                    </value>
                                    <value>
                                        <struct>
                                            <member>
                                                <name>key</name>
                                                <value>
                                                    <string>location_url</string>
                                                </value>
                                            </member>
                                            <member>
                                                <name>value</name>
                                                <value>
                                                    <string>
                                                        https://foursquare.com/v/french-truck-coffee/5984885e123a191137fdea7e</string>
                                                </value>
                                            </member>
                                        </struct>
                                    </value>
                                    <value>
                                        <struct>
                                            <member>
                                                <name>key</name>
                                                <value>
                                                    <string>location_latitude</string>
                                                </value>
                                            </member>
                                            <member>
                                                <name>value</name>
                                                <value>
                                                    <string>30.44391</string>
                                                </value>
                                            </member>
                                        </struct>
                                    </value>
                                    <value>
                                        <struct>
                                            <member>
                                                <name>key</name>
                                                <value>
                                                    <string>location_longitude</string>
                                                </value>
                                            </member>
                                            <member>
                                                <name>value</name>
                                                <value>
                                                    <string>-91.158165</string>
                                                </value>
                                            </member>
                                        </struct>
                                    </value>
                                </data>
                            </array>
                        </value>
                    </member>
                    <member>
                        <name>description</name>
                        <value>
                            <string>A post about a location. Posted from Mars Edit.</string>
                        </value>
                    </member>
                </struct>
            </value>
        </param>
        <param>
            <value>
                <boolean>1</boolean>
            </value>
        </param>
    </params>
</methodCall>

Got it, thanks.

The front matter location fields change has been rolled out. I’ll work on the MarsEdit improvements for custom fields later, after some more testing. Looks like it will work, though.

1 Like

Is it possible to edit the location once it’s been added to the post? I’m trying to use the same syntax that works for editing fields like content and categories, but location info is not updated.

I’ve tried using the same syntax used to add the location to a post:

{
    "action": "update",
    "url": "https://example.micro.blog/2023/08/12/example.html",
    "replace": {
        "checkin": [
            {
                "type": [
                    "h-card"
                ],
                "properties": {
                    "name": [
                        "French Truck Coffee"
                    ],
                    "url": [
                        "https://example.com"
                    ],
                    "latitude": [
                        30.443910181909168
                    ],
                    "longitude": [
                        -91.15816516713376
                    ]
                }
            }
        ]
    }
}

And I’ve tried the same format that comes back from the Micropub API when querying source by URL:

{
    "action": "update",
    "url": "https://example.micro.blog/2023/08/12/example.html",
    "replace": {
        "location": [
            {
                "name": [
                    "French Truck Coffee"
                ],
                "url": [
                    "https://example.com"
                ],
                "latitude": [
                    30.44391
                ],
                "longitude": [
                    -91.158165
                ]
            }
        ]
    }
}

But neither updates the location data on the post.

Sorry, location is currently only supported when creating new posts, not when updating posts. I’ll fix this.

Thank you :slight_smile: