Skip to content

Fatal error when API returns "unknown" user with ID 0 #332

Description

@thomasplevy

Reproduction Steps

I believe this would happen with a conversation that is deleted and then restored (maybe?)

Image

Make a request to retrieve the conversation's threads:

$request = (new ConversationRequest)->withThreads();

Expected Behavior

I'd get the conversation with the threads that I could interact with

Actual Behavior

Fatal error:

#0 /path/to/project/vendor/webmozart/assert/src/Assert.php(853): HelpScout\\Api\\Assert\\Assert::reportInvalidArgument()
#1 /path/to/project/vendor/helpscout/api/src/Users/User.php(132): Webmozart\\Assert\\Assert::greaterThan()
#2 /path/to/project/vendor/helpscout/api/src/Users/User.php(94): HelpScout\\Api\\Users\\User->setId()
#3 /path/to/project/vendor/helpscout/api/src/Conversations/Threads/IncludesThreadDetails.php(127): HelpScout\\Api\\Users\\User->hydrate()
#4 /path/to/project/vendor/helpscout/api/src/Conversations/Threads/Thread.php(128): HelpScout\\Api\\Conversations\\Threads\\Thread->hydrateCreatedBy()
#5 /path/to/project/vendor/helpscout/api/src/Conversations/Threads/ThreadFactory.php(30): HelpScout\\Api\\Conversations\\Threads\\Thread->hydrate()
#6 /path/to/project/src/Service/HelpScoutDirectApiService.php(188): HelpScout\\Api\\Conversations\\Threads\\ThreadFactory->make()

The thread I found causing this error looks like this when I make a direct API request:

{
    "id": 123456,
    "type": "lineitem",
    "action": {
        "type": "deleted",
        "text": "unknown deleted the conversation",
        "associatedEntities": {}
    },
    "source": {
        "type": "web",
        "via": "user"
    },
    "createdBy": {
        "id": 0,
        "type": "user",
        "first": "unknown",
        "last": "unknown",
        "photoUrl": "none",
        "email": "unknown"
    },
    "to": [],
    "cc": [],
    "bcc": [],
    "createdAt": "2020-06-24T17:13:46Z",
    "_embedded": {
        "attachments": []
    },
    "_links": {
        "createdByUser": {
            "href": "https://api.helpscout.net/v2/users/0"
        }
    }
}

I've encountered this more than once and for now have just put a handler in place to use ID 1 (none@nowhere.com) if the ID 0 is passed into the hydrate method:

$this->setId((int) $data['id']);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions