I've been working on creating Google Classroom Classwork programmatically using the Google PHP api client services library. I am able to successfully create coursework, using: courses_courseWork->create, and passing a coursework object.
However, I can't seem to create a Course work object with a due date but no due time. Creating without a due date works fine, but if I just set a due date, it says that a due time object ( Google_Service_Classroom_TimeOfDay ) must also be sent. I've tried creating without setting hours / minutes / seconds / nanos, I've tried setting them to null, and I've tried unsetting the object properties after creating it.
When I look at a created ClassWork object (through the web interface, with no due date), the dueTime object property is just an empty array. I cannot for the life of me figure out how to pass that when creating with the API.
Thank you!
Your question is a little old, but in case someone else is having this issue, if you set a dueDate, you must also set a dueTime. This is a requirement from the API:
dueDate: object(Date):
Optional date, in UTC, that submissions for this course work are due.
This must be specified if dueTime is specified.
dueTime: object(TimeOfDay):
Optional time of day, in UTC, that submissions for this course work are due.
This must be specified if dueDate is specified.
See: https://developers.google.com/classroom/reference/rest/v1/courses.courseWork#CourseWorkState
Also, as noted, all create
request dates and times should be converted to UTC. Depending on how your app is set up, this can quickly get a bit complicated...
It may be easiest to use a library like moment.js or luxon, etc. to manipulate the dates.
(I used moment.js, converted the moment datetime object to UTC, then converted the moment object .toArray
, which I iterated through to create dueDate and dueTime objects for the request)