Skip to content

Add Batch to graph client#915

Merged
shemogumbe merged 5 commits into
mainfrom
shem/add_batch_to_graph_client
Oct 2, 2024
Merged

Add Batch to graph client#915
shemogumbe merged 5 commits into
mainfrom
shem/add_batch_to_graph_client

Conversation

@shemogumbe

@shemogumbe shemogumbe commented Oct 2, 2024

Copy link
Copy Markdown
Contributor

Leads to this usage:

batch_content = BatchRequestContent(batch_request_content)


async def test_batch():
    batch_result = await client.batch.post(batch_request_content=batch_content)
    for response in batch_result.responses.values():
        print(response.status)
        print(response.body)
        print(response.headers)


asyncio.run(test_batch())

@shemogumbe shemogumbe requested a review from a team as a code owner October 2, 2024 10:05
Comment thread msgraph/graph_service_client.py
Comment thread msgraph/graph_service_client.py Outdated
@baywet

baywet commented Oct 2, 2024

Copy link
Copy Markdown
Member

Thank you for making the changes!
@shemogumbe make sure you squash this one when merging it, with a proper conventional commit message so the release triggers properly

@andrueastman

Copy link
Copy Markdown
Contributor

We'll also need a similar PR in the beta lib too https://github.com/microsoftgraph/msgraph-beta-sdk-python

@shemogumbe shemogumbe merged commit 5e24963 into main Oct 2, 2024
@shemogumbe shemogumbe deleted the shem/add_batch_to_graph_client branch October 2, 2024 15:12
@shemogumbe

Copy link
Copy Markdown
Contributor Author

Thank you for making the changes! @shemogumbe make sure you squash this one when merging it, with a proper conventional commit message so the release triggers properly

Mered before seeing this, will do another branch to trigger the release

@chandra447

Copy link
Copy Markdown

does the batch thing only work for the get methods , i have tested with the post methods to create new records in a sharepoint list, i get the api call error.

@baywet

baywet commented Feb 18, 2025

Copy link
Copy Markdown
Member

@chandra447 it should work for any operation to the exception of the ones that need to upload or download files

@chandra447

chandra447 commented Feb 18, 2025

Copy link
Copy Markdown

@baywet this is how i am doing this, but it throws api 400 error for the post,patch, following the same for the get requests dosen't throw any error

creds = ClientSecretCredential(
        tenant_id=settings.tenant_id, client_id=settings.app_id, client_secret=settings.client_secret
    )

client = GraphServiceClient(credentials=credentials, scopes=['https://graph.microsoft.com/.default'])

request_body = ListItem(
	fields = FieldValueSet(
		additional_data = {
				"title" : "Widget",
				"color" : "Purple",
				"weight" : 32,
		}
	),
)
request_info1: RequestInformation = client.sites.by_site_id(settings.site_id)
            .lists.by_list_id(settings.list_id)
            .items.to_post_request_information(body=request_body)

batch_request_content: BatchRequestContent = BatchRequestContent()
# using the setter requests setter
 batch_request_content.requests = [
        BatchRequestItem(
            request_information=request_info1,
        ),
    ]

batch_response_content: BatchResponseContent = await client.batch.post(
        batch_request_content=batch_request_content
    )

 for response in batch_response_content.responses.values():
        print(response.status)
        print(response.body)
        print(response.headers)

@baywet

baywet commented Feb 18, 2025

Copy link
Copy Markdown
Member

Can you please open a new issue?

@chandra447

Copy link
Copy Markdown

i have created a new issue outlining this
microsoftgraph/msgraph-sdk-python-core#833

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants