Skip to content

Graph client's batch request builder POST/PATCH request not working #833

@chandra447

Description

@chandra447

Describe the bug

I am trying to create multiple sharepoint list items in a list usign the batch request builder. Bu t throws API 400 error. Below is my implementation in the How to reproduce section

Expected behavior

I expect it to create all the records as it uses the jsonwriter and the method write_object which the actual ListItem also uses

How to reproduce

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 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)

SDK Version

No response

Latest version known to work for scenario above?

No response

Known Workarounds

No response

Debug output

Click to expand log ```
</details>


### Configuration

_No response_

### Other information

_No response_

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions