Upload Multiple Choice Fields item in SharePoint with Microsoft Graph

Tourmente T 40 Reputation points
2024-01-29T16:57:49.0733333+00:00

Hi, Trying to add a new entry to a SharePoint list through a Python script using Microsoft Graph returns an error in the case of Multiple Choice Fields : "General exception while processing". The correct formulation of the post request for this type of item is not specified on this documentation : https://learn.microsoft.com/en-us/graph/api/listitem-create?view=graph-rest-1.0&tabs=python. Thank you for your help.

Microsoft 365 and Office | SharePoint | For business | Windows
Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

Accepted answer
  1. Sourabh Gupta 800 Reputation points Microsoft External Staff
    2024-02-03T13:21:18.22+00:00

    Hi Tourmente T, Thanks for reaching out.

    I guess you can do this with beta version (Give it a try with V1.0). Your fields should look like this.

    {
      "fields": {
        "******@odata.type": "Collection(Edm.String)",
        "choice_checkboxes":["cb1","cb2"]
      }
    }
    

    or another example like this

    "******@odata.type": "Collection(Edm.Int32)",
    "ProductsLookupId":[6,7,8]
    

    or

    {
      "fields": {
        "******@odata.type": "Collection(Edm.Int32)",
        "Weight": 32,
      }
    }
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. TourmenteT 30 Reputation points
    2024-02-06T14:03:18.9066667+00:00

    Hi, Thanks for your answer. I tried the following formulation which have returned the same error.

    request_body = ListItem(
    	        fields = FieldValueSet(
    		        additional_data = {
                        "Field1": {
                            "Field1@Odatatype": "Collection(Edm.Int32)",
                            "Field1":["test","test","test"]
    					}
    				}
    
    request_body = ListItem(
    	        fields = FieldValueSet(
    		        additional_data = {
                        "Field1": ["test", "test", "test"]
    				}
    

    As well as these value formulation : ["test, test, test"] "test, test, test" This is the error:

    msgraph.generated.models.o_data_errors.o_data_error.ODataError:
            APIError
            Code: 400
            message: None
            error: MainError(additional_data={}, code='invalidRequest', details=None, inner_error=InnerError(additional_data={'date': DateTime(2024, 2, 6, 13, 56, 43, tzinfo=Timezone('UTC'))}, client_request_id='0af25118-2d29-4072-933c-bb1c125acd1b', date=None, odata_type=None, request_id='0cb2c84e-9ab4-4037-8bd0-8e2b41109450'), message='Invalid request', target=None)
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.