square / square-nodejs-sdk

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Listing bookings fails with: The response did not match the response schema.

chris-miner opened this issue · comments

commented

I did the following:

  1. used the node.js sdk to list bookings for a given month.

Expected:

  • I expected to get a list of bookings from square

Found:

  • The fetch fails with the error: "The response did not match the response schema."

Here's the whole error message:

Error: The response did not match the response schema.

Some properties are missing in the object: "service_variation_id", "service_variation_version".

Given value: {"duration_minutes":60,"team_member_id":"WaNoY7Hn7J5czATdrqcn","any_team_member":false,"intermission_minutes":0}
Type: 'object'
Expected type: 'Lazy<Object<{durationMinutes,serviceVariationId,teamMemberId,serviceVariationVersion,intermissionMinutes,anyTeamMember,resourceIds}>>'
Path: bookings › 1 › appointment_segments › 0
app.js:128

Extra Info

As you can see the service_variation_id and service_variation_version aren't present. In this case I don't actually care since all I want to know about is times, dates, customer, staff, email, and phone info about the booking. The data in the system was put there via the appointments web interface, so I don't know why it is missing attributes.

My workaround, is to correct the data, but that only works for 'bad' bookings that haven't been canceled. If they have been canceled I can't edit them through the UI.

My other idea is to fetch the bookings one by one rather than in batch mode so I can skip over the ones that are causing a problem. That won't work since the fetch fails in a way that doesn't allow me to continue with a subsequent fetch with a new cursor value.

Conclusions

It shouldn't bomb out the way it does, especially since I am not responsible for the integrity of that data. I'm just a consumer of it.

Thank you for reporting this @chris-miner. We're looking into it and will get back to you.

commented

To remedy the situation for myself, I commented out the relevant lines in node_modules/square/dist/square.cjs.development.js:

var appointmentSegmentSchema = /*#__PURE__*/schema.object({
  durationMinutes: ['duration_minutes', /*#__PURE__*/schema.number()],
  // serviceVariationId: ['service_variation_id', /*#__PURE__*/schema.string()],
  teamMemberId: ['team_member_id', /*#__PURE__*/schema.string()],
  // serviceVariationVersion: ['service_variation_version', /*#__PURE__*/schema.bigint()],
  intermissionMinutes: ['intermission_minutes', /*#__PURE__*/schema.optional( /*#__PURE__*/schema.number())],
  anyTeamMember: ['any_team_member', /*#__PURE__*/schema.optional( /*#__PURE__*/schema.boolean())],
  resourceIds: ['resource_ids', /*#__PURE__*/schema.optional( /*#__PURE__*/schema.array( /*#__PURE__*/schema.string()))]
});

This was caused by a discrepancy between what the back end was actually returning and what the back end specified it would return. The fix was made on the back end and no SDK changes are necessary.