[SalesForce] How to get SObject type from object Id using REST API

I have an object id that is a "parent id" of a specific Attachment object (e.g., b3KD0000119wDTlMAN). I'd like to understand what type this object belongs to, to query for it's details. It can also be a Custom Object. Currently I only work through REST API. Can this be done using REST API?

Best Answer

You can query the parent's type directly in the SOQL:

SELECT ParentId, Parent.Type FROM Attachment WHERE Id = ...

You'll get a response like this:

{
    "done": true,
    "records": [
        {
            "attributes": {
                "type": "Attachment",
                "url": "/services/data/v33.0/sobjects/Attachment/..."
            },
            "ParentId": "...",
            "Parent": {
                "attributes": {
                    "type": "Name",
                    "url": "/services/data/v33.0/sobjects/Opportunity/..."
                },
                "Type": "Opportunity"
            }
        }
    ],
    "totalSize": 1
}