GraphAPI Create SharePoint ListItem, timestamp format ignored

Jan Vodolan 1 Reputation point
2021-06-22T13:52:24.273+00:00

API ignores 'Z' char - UTC indicator, or explicit zone. If posted as local (without zone info) it is parsed as UTC ... ?!?

I am unable to create a list item with DateTime field. Since documentation neither API did not comment it, I presume that dateTime format should be the same as is returned from server (full iso, e.g.: "Modified": "2021-06-22T02:35:15Z").
Unfortunatelly, the only way how to post a value is strip zone completelly )-:
The problem is in: HTTP API (REST) and java API.

Sample request:

POST https://graph.microsoft.com/v1.0/sites/siteId/lists/listId/items  
Content-Type: application/json  
Authorization: Bearer token  
  
{  
  "fields": {  
    "Title": "any title",  
    "timestamp": "2021-06-22T12:00:00"  
  }  
}  

Sample code:

Instant now = Instant  
             .now()  
             .truncatedTo(ChronoUnit.SECONDS)  
             ;  
     String timestampString = DateTimeFormatter.ISO_INSTANT.format(now);  
     System.out.println("timestampString=" + timestampString);  
  
     FieldValueSet fieldValueSet = new FieldValueSet();  
     fieldValueSet.additionalDataManager().put("timestamp", new JsonPrimitive(timestampString));  
  
     listItem.fields = fieldValueSet;  
  
     ListItem li = graphClient  
             .sites(siteId)  
             .lists(listId)  
             .items()  
             .buildRequest()  
             .post(listItem);  
  
     System.out.println("createdDateTime=" +li.createdDateTime);  
 }  

RESULT LOG:
timestampString=2021-06-22T08:58:02Z
createDateTime= 2021-06-22T01:58:02Z

HTTP requests examples:
Request: "begin": "2000-01-01T00:00:00Z"
Response: "begin": "1999-12-31T16:00:00Z"
-8h

Request: "begin": "2021-06-22T12:00:00+02:00"
Response: "begin": "2021-06-22T03:00:00Z"
-?h

Request: "begin": "2021-06-22T12:00:00Z"
Response: "begin": "2021-06-22T05:00:00Z"
-7h

Request: "begin": "2021-06-22T12:00:00"
Response: "begin": "2021-06-22T12:00:00Z"
Ignores UTC - Z char ...

See also:
https://stackoverflow.com/questions/66283825/microsoft-graph-api-insert-new-listitem-field-datetime-gap-to-8-hours
https://video2.skills-academy.com/en-us/answers/questions/188584/different-time-is-returned-when-creating-sharepoin.html?childToView=446687#answer-446687
AB#9998
https://github.com/microsoftgraph/msgraph-sdk-java/issues/813

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,006 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,971 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MichaelHan-MSFT 18,031 Reputation points
    2021-06-23T05:53:47.677+00:00

    Hi @Jan Vodolan ,

    I used to have similar issue as yours when creating listitem with DateTime field. And I found that date field in the response returned is displayed incorrectly. After creating the list item, you should use Get listItem endpoint to check the date field: https://video2.skills-academy.com/en-us/graph/api/listitem-get?view=graph-rest-1.0&tabs=http

    I opened this issue in github a few days ago: https://github.com/microsoftgraph/microsoft-graph-docs/issues/13168


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


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.