microsoftgraph / microsoftgraph/msgraph-beta-sdk-python

Resource not found for the segment 'partner'

Open
#764 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status:waiting-for-triage type:bug
Dominant language
Python
Stars
44
Forks
16
Avg merge
20h 39m
Merged PRs (30d)
3

Description

Describe the bug

I am encountering an error attempting to perform a "List" or "Get" operation for Partner Security Alerts.

https://learn.microsoft.com/en-us/graph/api/partner-security-partnersecurityalert-list-securityalerts?view=graph-rest-beta&tabs=python

Expected behavior

A response object should be returned as indicated in the Microsoft docs:

https://learn.microsoft.com/en-us/graph/api/partner-security-partnersecurityalert-get?view=graph-rest-beta&tabs=python#response-1

{
  "id": "d8b202fc-a216-3404-69ef-bdffa445eff6",
  "displayName": "Action Required: Virtual machine connecting to crypto currency mining pool Detected",
  "description": "Analysis of Azure resource network activity detected the resource was connecting to a crypto currency mining pool. This would often be an indication that your Azure resource is compromised.",
  "alertType": "networkConnectionsToCryptoMiningPools",
  "status": "active",
  "severity": "high",
  "confidenceLevel": "medium",
  "customerTenantId": "1889e718-414b-4bad-8bbe-c1135bd39a41",
  "subscriptionId": "5f6e6521-6e5f-4b0b-80aa-bd44fad7a398",
  "valueAddedResellerTenantId": "c296b2ce-8cd1-4346-9e82-d8eccca70d65",
  "catalogOfferId": "MS-AZR-0017G",
  "detectedDateTime": "2024-01-23T16:03:33.05Z",
  "firstObservedDateTime": "2024-01-23T16:03:33.05Z",
  "lastObservedDateTime": "2024-01-23T16:03:33.05Z",
  "resolvedReason": "fraud",
  "resolvedOnDateTime": "2024-02-23T16:03:33.05Z",
  "resolvedBy": "danas@contoso.com",
  "isTest": false,
  "affectedResources": [
    {
      "resourceId": "/subscriptions/subscription-id/resourceGroups/resourcegroup-name/providers/Microsoft.Compute/virtualMachines/vm-name",
      "resourceType": "AzureResource"
    }
  ],
  "activityLogs": [
    {
      "statusFrom": "active",
      "statusTo": "investigating",
      "updatedBy": "samanthab@contoso.com",
      "updatedDateTime": "2023-08-10T08:47:10.8454142Z"
    },
    {
      "statusFrom": "investigating",
      "statusTo": "resolved",
      "updatedBy": "samanthab@contoso.com",
      "updatedDateTime": "2023-08-10T08:47:25.2089246Z"
    }
  ],
  "additionalDetails": {
    "VM_IP": "[  \"vm-ip\"]",
    "MiningPool_IP": "[  \"mining-pool-ip\"]",
    "ConnectionCount": "5",
    "CryptoCurrencyMiningPoolDomainName": "pool-name.com"
  }
}
How to reproduce
  1. Installed the msgraph-beta-sdk using pip
  2. Attempted to run the below code snippets :
### List all active security alerts

from msgraph_beta import GraphServiceClient
from azure.identity import DefaultAzureCredential
from azure.identity.aio import ClientSecretCredential
from azure.keyvault.secrets import SecretClient
import asyncio
import json


def main():

    alerts = asyncio.run(list_security_alerts())

    print(alerts)


async def list_security_alerts():
    """Returns a list of all active security alerts"""


    credential = DefaultAzureCredential()

    
    secret_client = SecretClient(
        vault_url="https://kv-demo-zan-prod-004.vault.azure.net/", credential=credential
    )

    client_id = secret_client.get_secret(
        "clientId"
    ).value
    client_secret = secret_client.get_secret(
        "clientSecret"
    ).value
    tenant_id = secret_client.get_secret(
        "tenantId"
    ).value

    credentials = ClientSecretCredential(tenant_id, client_id, client_secret)

    scopes = ["https://graph.microsoft.com/.default"]

    graph_client = GraphServiceClient(credentials=credentials, scopes=scopes)

    result = await graph_client.security.partner.security_alerts.get()

    active_alerts = [item.id for item in result.value if item.status == "active"]

    return active_alerts


if __name__ == "__main__":
    main()


### Retrieve individual alert

from msgraph_beta import GraphServiceClient
from azure.identity import DefaultAzureCredential
from azure.identity.aio import ClientSecretCredential
from azure.keyvault.secrets import SecretClient

import asyncio


def main():

    alert_id = ""

    alert = asyncio.run(get_security_alert(alert_id))
    print(alert)


async def get_security_alert(alert_id):
    """Get individual security alert"""

    credential = DefaultAzureCredential()

    secret_client = SecretClient(
        vault_url="https://kv-demo-zan-prod-004.vault.azure.net/", credential=credential
    )

    client_id = secret_client.get_secret(
        "clientId"
    ).value
    client_secret = secret_client.get_secret(
        "clientSecret"
    ).value
    tenant_id = secret_client.get_secret(
        "tenantId"
    ).value


    credentials = ClientSecretCredential(tenant_id, client_id, client_secret)

    scopes = ["https://graph.microsoft.com/.default"]

    graph_client = GraphServiceClient(credentials, scopes)

    result = await graph_client.security.partner.security_alerts.by_partner_security_alert_id(alert_id).get()

    return result


if __name__ == "__main__":
    main()

SDK Version

1.25.0

Latest version known to work for scenario above?

No response

Known Workarounds

No response

Debug output
Click to expand log ```

Traceback (most recent call last):
File "C:\Users\Developer\Partner-Center-Events\CodeSnippets\list_security_alerts.py", line 48, in
main()
File "C:\Users\Developer\Partner-Center-Events\CodeSnippets\list_security_alerts.py", line 11, in main
alerts = asyncio.run(list_security_alerts())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0\Lib\asyncio\runners.py", line 190, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0\Lib\asyncio\runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0\Lib\asyncio\base_events.py", line 654, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "C:\Users\Developer\Partner-Center-Events\CodeSnippets\list_security_alerts.py", line 40, in list_security_alerts
result = await graph_client.security.partner.security_alerts.get()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Developer\Partner-Center-Events\CodeSnippets.venv\Lib\site-packages\msgraph_beta\generated\security\partner\security_alerts\security_alerts_request_builder.py", line 69, in get
return await self.request_adapter.send_async(request_info, PartnerSecurityAlertCollectionResponse, error_mapping)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Developer\Partner-Center-Events\CodeSnippets.venv\Lib\site-packages\kiota_http\httpx_request_adapter.py", line 193, in send_async
await self.throw_failed_responses(response, error_map, parent_span, parent_span)
File "C:\Users\Developer\Partner-Center-Events\CodeSnippets.venv\Lib\site-packages\kiota_http\httpx_request_adapter.py", line 575, in throw_failed_responses
raise exc
msgraph_beta.generated.models.o_data_errors.o_data_error.ODataError:
APIError
Code: 400
message: None
error: MainError(additional_data={}, code='BadRequest', details=None, inner_error=InnerError(additional_data={}, client_request_id='redacted', date=datetime.datetime(2025, 3, 12, 13, 14, 58), odata_type=None, request_id='redacted'), message="Resource not found for the segment 'partner'.", target=None)

</details>


### Configuration


### Configuration

- OS: Windows 11
- architecture: x64

### Other information

_No response_

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the failing entry points graph_client.security.partner.security_alerts.get() and by_partner_security_alert_id(), then inspect generated/security/partner/security_alerts/security_alerts_request_builder.py. Reproduce the request against the documented Partner Security Alerts operations and compare the generated path with the Microsoft Graph documentation. Done means both list and individual-alert calls return the documented response instead of the missing-segment error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.