Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Take on - Microsoft Graph API_Test contribution #38376

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ def __init__(self,
self.ms_client = MicrosoftClient(**client_args) # type: ignore[arg-type]

def generic_request(
self,
resource: str,
http_method: str = 'GET',
api_version: str = 'v1.0',
odata: str | None = None,
request_body: dict | None = None,
self,
resource: str,
http_method: str = 'GET',
api_version: str = 'v1.0',
odata: str | None = None,
request_body: dict | None = None,
headers: dict | None = None
):
url_suffix = urljoin(api_version, resource)
if odata:
Expand All @@ -68,6 +69,7 @@ def generic_request(
url_suffix=url_suffix,
json_data=request_body,
resp_type='resp',
headers=headers
)
return res.json() if res.content else None

Expand Down Expand Up @@ -107,6 +109,8 @@ def generic_command(client: MsGraphClient, args: dict[str, Any]) -> CommandResul
request_body = json.loads(request_body)
except json.decoder.JSONDecodeError as e:
raise ValueError(f'Invalid request body - {str(e)}')
headers = args.get('headers')

http_method = args.get('http_method', 'GET')

response = client.generic_request(
Expand All @@ -115,6 +119,7 @@ def generic_command(client: MsGraphClient, args: dict[str, Any]) -> CommandResul
api_version=args.get('api_version', 'v1.0'),
odata=args.get('odata', ''),
request_body=request_body,
headers=dict(subString.split(":") for subString in headers.split(',')) if headers else None
)

if not response:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ configuration:
hidden: true
- display: Use a self-deployed Azure Application
name: self_deployed
section: Connect
required: false
type: 8
additionalinfo: Select this checkbox if you are using a self-deployed Azure application.
Expand Down Expand Up @@ -167,6 +168,9 @@ script:
predefined:
- 'true'
- 'false'
- name: headers
description: 'A comma separated list of headers to send in the GET request, for example: ConsistencyLevel:eventual,User-Agent:MyApp/1.0.'
isArray: true
description: Run a Microsoft Graph API query.
name: msgraph-api-request
- description: Run this command to start the authorization process and follow the instructions in the command results.
Expand All @@ -182,7 +186,7 @@ script:
- description: Generate the login URL used for Authorization code flow.
name: msgraph-api-generate-login-url
arguments: []
dockerimage: demisto/crypto:1.0.0.114611
dockerimage: demisto/crypto:1.0.0.2005673
runonce: false
script: '-'
subtype: python3
Expand Down
24 changes: 13 additions & 11 deletions Packs/MicrosoftGraphAPI/Integrations/MicrosoftGraphAPI/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,23 +100,25 @@ Should be used after running the ***msgraph-api-auth-start*** command.
Tests connectivity to Microsoft.

### msgraph-api-request

***
Run a Microsoft Graph API query.


#### Base Command

`msgraph-api`
`msgraph-api-request`

#### Input

| **Argument Name** | **Description** | **Required** |
|-------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------|
| resource | The resource in Microsoft Graph to refer. | Required |
| http_method | The HTTP method used for the request to Microsoft Graph. Possible values are: "GET", "POST", "DELETE", "PUT", or "PATCH". Default is "GET". | Optional |
| api_version | The version of the Microsoft Graph API to use. Possible values are: "v1.0" or "beta". Default is "v1.0". | Optional |
| request_body | The request body (required for POST queries). | Optional |
| odata | OData system query options, e.g. $filter=startswith(givenName, 'J'). For more details see https://docs.microsoft.com/en-us/graph/query-parameters. It is recommended to use the $top query option to limit the result. | Optional |
| populate_context | If "true", will populate the API response to the context data. Default is "true". | Optional |
| **Argument Name** | **Description** | **Required** |
| --- | --- | --- |
| resource | The resource in Microsoft Graph to refer. | Required |
| http_method | The HTTP method used for the request to Microsoft Graph. Possible values are: "GET", "POST", "DELETE", "PUT", or "PATCH". Possible values are: GET, POST, DELETE, PUT, PATCH. Default is GET. | Optional |
| api_version | The version of the Microsoft Graph API to use. Possible values are: "v1.0" or "beta". Default is "v1.0. Possible values are: v1.0, beta. Default is v1.0. | Optional |
| request_body | The request body (required for POST queries). | Optional |
| odata | OData system query options, e.g. $filter=startswith(givenName, 'J'). For more details see https://docs.microsoft.com/en-us/graph/query-parameters. It is recommended to use the $top query option to limit the result. | Optional |
| populate_context | If "true" will populate the API response to the context data. Possible values are "true" or "false". Default is "true". Possible values are: true, false. Default is true. | Optional |
| headers | A comma separated list of headers to send in the GET request, for example: ConsistencyLevel:eventual,User-Agent:MyApp/1.0. | Optional |

#### Context Output

Expand Down Expand Up @@ -175,4 +177,4 @@ We can see that according to the [HTTP request](https://docs.microsoft.com/en-us
- The HTTP method is ***GET***
- The resource is ***/applications***

So in order to list all the applications using the integration, we would run the command: `!msgraph-api resource=/applications http_method=GET`
So in order to list all the applications using the integration, we would run the command: `!msgraph-api resource=/applications http_method=GET`
7 changes: 7 additions & 0 deletions Packs/MicrosoftGraphAPI/ReleaseNotes/1_1_53.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

#### Integrations

##### Microsoft Graph API
- Updated the Docker image to: *demisto/crypto:1.0.0.2005673*.

- Added the **headers** argument to the ***msgraph-api-request*** command.
2 changes: 1 addition & 1 deletion Packs/MicrosoftGraphAPI/pack_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Microsoft Graph API",
"description": "Use the Microsoft Graph API integration to interact with Microsoft APIs that do not have dedicated integrations in Cortex XSOAR, for example, Mail Single-User, etc.",
"support": "xsoar",
"currentVersion": "1.1.52",
"currentVersion": "1.1.53",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down
Loading