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

Add Batch to graph client #915

Merged
merged 5 commits into from
Oct 2, 2024
Merged

Conversation

shemogumbe
Copy link
Collaborator

@shemogumbe shemogumbe commented Oct 2, 2024

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
@baywet
Copy link
Member

baywet commented Oct 2, 2024

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
Member

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
7 checks passed
@shemogumbe shemogumbe deleted the shem/add_batch_to_graph_client branch October 2, 2024 15:12
@shemogumbe
Copy link
Collaborator 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

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
Copy link
Member

baywet commented Feb 18, 2025

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

@chandra447
Copy link

chandra447 commented Feb 18, 2025

@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
Copy link
Member

baywet commented Feb 18, 2025

Can you please open a new issue?

@chandra447
Copy link

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