none
Graph API POST to Sharepoint Online List

    질문

  • Hi All,

    I'm currently developing an application that integrates with a Sharepoint Online site. The application asks questions and submits the data to a sharepoint list on the site. Everything works fine, but if the column is a Choice - Checkbox column, I get a malformed JSON error. I've been looking everywhere for the correct way to submit data to this type of sharepoint column but have found nothing. 

    Here is an example of what the body looks like. The only item that won't submit is the "Line_x0020_Type" column, which is a Choice column that allows multiple selections. I tried sending an array of strings initially, but after a little debugging, the column formValue, if I created a list item directly from Sharepoint, was ";#CATV;#Phone;#" which I thought was strange because if I do a GET the field is displayed as an array of string elements. The below body, although reflects the formValue of the column, still does not work. Any help would be appreciated it. 

    {
      "fields": {
        "Claim_x0020__x0023_": "1111",
        "Date_x0020_of_x0020_Incident": "2018-06-14",
        "Elec_x0020_or_x0020_Gas": "Electric",
        "Claim_x0020_Type": "Low-Lines",
        "Vehicle_x0020_State": "MO",
        "Vehicle_x0020_Owner_x0020_Addres": ", , MO ",
        "Apparent_x0020_Which_x0020_Line_": "Yes",
        "Line_x0020_Type": ";#CATV;#Phone;#"
      }
    }
    2018년 6월 14일 목요일 오후 9:49

모든 응답

  • Hi,

    The Json data for Multiple Checkbox value is a string array like this:

    Not Familiar with Graph API, but for Json data to post with Rest API, this field should be set like this:

    var itemmetadata = {
            "__metadata": { "type": 'SP.Data.RestpostListItem'},
            "Title": "value change",
            "Line_x0020_Type":{'results':["Line1","Line2","Line3"]}  
        };
        
    

    Worked as expected to set value for multiple checkbox column:

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    2018년 6월 15일 금요일 오전 8:17
  • Thanks for getting back to me, Jerry. I just tried this post and received an error message: "The request is malformed or incorrect." I would think if I can post to a column of any other type besides a checkbox column, then the Graph API should be able to, but it could very well be a Graph API limitation.

    {
      "fields": {
        "Line_x0020_Type": {
    "results": ["CATV", "Phone"]
        }
      }
    }

    I also tried this which is how the field comes back when I do a GET.

    {
      "fields": {
        "Line_x0020_Type": ["Ameren / Electric", "CATV", "Phone"]
      }
    }

           
    2018년 6월 15일 금요일 오후 2:43
  • Hi Brandon,

    I am not very familiar with Graph API as this forum mainly talked about SharePoint Related question.

    For SharePoint side, we usually set field multiple field value via Rest API like this:

    <script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>
    <script type="text/javascript">
    function UpdateMetaData(){
        var listName="Restpost";
        var listItemId= 1;
        var item = {
            "__metadata": { "type": 'SP.Data.RestpostListItem'},
            "Title": "value change",
           "Line_x0020_Type":{'results':["Line1","Line2","Line3"]}    
        };
        
        $.ajax({
            url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/lists/getbytitle('" + listName + "')/items("+listItemId+")",
            type: "POST",
            contentType: "application/json;odata=verbose",
            data: JSON.stringify(item),
            headers: {
                "Accept": "application/json;odata=verbose",
                "X-RequestDigest": $("#__REQUESTDIGEST").val(),
                "X-HTTP-Method": "MERGE",
                "If-Match": "*"
            },
            success: function (data) {
                alert('Success');
                console.log(data);
            },
            error: function (data) {
                alert("Error");
                
            }
        });
    }
    </script>

    You could try this using Rest API instead of Graph API so that it could work.

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    2018년 6월 15일 금요일 오후 3:17
  • I could give that a try, but I'm going to try to find a solution using Graph first. Thanks for your help!
    2018년 6월 15일 금요일 오후 3:31
  • Hi Brandon,

    You are welcome. Please try the Rest API option like above and if there is any update of this issue, feel free to post. 

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    2018년 6월 15일 금요일 오후 3:43