# Events API Error

**URL:** <https://community.hubspot.com/t/events-api-error/81509>\
**Category:** APIs & Integrations\
**Tags:** events\
**Created:** [May 18, 2023, 3:36pm UTC](https://community.hubspot.com/t/events-api-error/81509 "2023-05-18T15:36:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![DRead](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dread/32/194267_2.png) [@DRead](https://community.hubspot.com/u/DRead)\
**Post date:** [May 18, 2023, 3:36pm UTC](https://community.hubspot.com/t/events-api-error/81509/1 "2023-05-18T15:36:44Z")

</div>

```lia-code-sample
const eventType = 'pe23232_xyz';
const contactId = event.object.objectId;

const response = await hubspotClient.events.eventsApi.getPage(
null,
null,
'contact',
contactId,
eventType,
null,
null,
1,
['-occurredAt'],
undefined,
);

status: error

message: Invalid input JSON on line -1, column -1: Cannot construct instance of `com.hubspot.apiutils.core.models.time.Iso8601Instant`, problem: Failed to parse {{ timestamp }} as an ISO8601 string

x-trace: 2BE1D0C8D83B574BC80E3F8504A788F0434370B83D000000000000000000

If I fallback to the direct API call using the SDK, it works

const response = await hubspotClient.apiRequest({
method: 'GET',
path: `/events/v3/events`,
qs: {
eventType,
objectType: 'contact',
objectId: contactId,
limit: 1,
sort: ['-occurredAt'],
},
});

const events = await response.json();

```

---

<div class="post-metadata">

**Author:** ![himanshurauthan](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/himanshurauthan/32/53076_2.png) [@himanshurauthan](https://community.hubspot.com/u/himanshurauthan)\
**Post date:** [May 19, 2023, 9:10am UTC](https://community.hubspot.com/t/events-api-error/81509/2 "2023-05-19T09:10:49Z")

</div>

Hello @DRead  
Make sure you are providing a valid ISO8601 formatted timestamp value for the {{ timestamp }} placeholder. The timestamp should be in the format YYYY-MM-DDTHH:mm:ssZ, where YYYY represents the year, MM represents the month, DD represents the day, HH represents the hour, mm represents the minute, ss represents the second, and Z represents the timezone offset.

you can provide the timestamp as a string in the format ‘2023-05-19T12:00:00Z’.

Here’s an updated code snippet for the HubSpot Events API call using the SDK

```lia-code-sample
const eventType = 'pe23232_xyz';
const contactId = event.object.objectId;
const timestamp = '2023-05-19T12:00:00Z'; // Replace this with a valid ISO8601 timestamp

const response = await hubspotClient.events.eventsApi.getPage(
 null,
 null,
 'contact',
 contactId,
 eventType,
 null,
 null,
 1,
 ['-occurredAt'],
 timestamp
);

const events = response.results; // Assuming the response object has a `results` property containing the events

console.log(events);

```

Make sure to replace ‘2023-05-19T12:00:00Z’ with the actual valid timestamp value in your code.

---

<div class="post-metadata">

**Author:** ![DRead](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dread/32/194267_2.png) [@DRead](https://community.hubspot.com/u/DRead)\
**Post date:** [May 19, 2023, 2:47pm UTC](https://community.hubspot.com/t/events-api-error/81509/3 "2023-05-19T14:47:50Z")

</div>

The last argument to the function is a “Context” parameter not a timestamp.

---

<div class="post-metadata">

**Author:** ![DRead](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dread/32/194267_2.png) [@DRead](https://community.hubspot.com/u/DRead)\
**Post date:** [May 19, 2023, 2:47pm UTC](https://community.hubspot.com/t/events-api-error/81509/4 "2023-05-19T14:47:27Z")

</div>

Found the issue, if I replace all nulls with undefined it works.
