microsoftgraph / msgraph-sdk-android

Microsoft Graph SDK for Android! https://graph.microsoft.io
Other
51 stars 43 forks source link

400 : Bad Request and 403 : Forbidden #83

Closed CaramelHeaven closed 6 years ago

CaramelHeaven commented 6 years ago

But when I run it, I catch an exception:

Throwable detail: 
com.microsoft.graph.http.GraphServiceException: PATCH https://graph.microsoft.com/v1.0/sites
/lekowen.sharepoint.com,1af3e555-0d09-4bd0-9005-e1258078f5f9,d4848f16-87cf-4101-b6bd
-69f313b1a8d8/lists/621114ef-328a-4903-b923-ce6f6ad7f420/items/7/fields
SdkVersion : graph-android-v1.5.0
Authorization : Bearer eyJ0eXAiOiJKV1QiLCJub25jZSI[...]
{"id":"7","_ComplianceTagWrittenTime":"","Modified[...]
400 : Bad Request
[...]

I checked the link to the working state above (after PATCH, where what I want to change) in this and successfully changed the fields. What is the problem?

CaramelHeaven commented 6 years ago

403 : Forbidden - was resolved. I missed some permissions. 400 : Bad Request is still alive. Even if I get the FieldValueSet object and then update it without any changes, the request will still remain bad.

CaramelHeaven commented 6 years ago

FieldValueSet was resolved. The SharePoint API does not allow sending older fields, such as @ odata.etag or modified, because it updates them yourself. We can create a simple object and add some fields like this:

FieldValueSet fieldValueSet = new FieldValueSet();
        fieldValueSet.getAdditionalDataManager().put("comment", primitive);

After it, we just send this object in patch:

graphClient.getSites(SITE).getLists(idParentList).getItems().byId("7").getFields()
.buildRequest().patch(fieldValueSet);