redguava / cliniko-api

The API for Cliniko
74 stars 39 forks source link

Validation issue for patient forms #349

Closed Paperpotato closed 3 years ago

Paperpotato commented 3 years ago

Hi there!

I'm having some trouble getting my patient forms validated. The Cliniko server returns: { errors: { name: 'can’t be blank', patient: 'can’t be blank', content: null }, message: 'Validation Failed' }

Here's the fetch request I'm using from my Node server, which specifies the name, patient and content in the request body: fetch('https://api.au1.cliniko.com/v1/patient_forms', { headers: setHeaders(apiKey), method: 'POST', body: JSON.stringify({ name: 'Meow meow - Intake form', patient: { links: { self: patientLink } }, restricted_to_practitioner: false, content: requestPayload.content }) }) .then(response => response.json()) .then(data => console.log(data))

I've also tried switching out patient for patient_id to no avail. Is there another step I'm missing? I'm able to make other GET and POST requests normally with other endpoints, but only seem to be having a bit of trouble specifically with the patient_forms one. Any help would be super appreciated 🙂

JohnColvin commented 3 years ago

Hi potato!

The only way I can reproduce those validation errors is to send no body at all. So, something is likely wrong with your code in that area. But the snippet you sent here looks fine to me, so I'm not sure. I'd suggest breaking your code down into simpler bits and debugging to make sure the body is being built and sent correctly.

The patient param should be patient_id.

Best, John

On Sat, Jun 5, 2021 at 11:21 AM Paperpotato @.***> wrote:

Hi there!

I'm having some trouble getting my patient forms validated. The Cliniko server returns: { errors: { name: 'can’t be blank', patient: 'can’t be blank', content: null }, message: 'Validation Failed' }

Here's the fetch request I'm using from my Node server, which specifies the name, patient and content in the request body: fetch('https://api.au1.cliniko.com/v1/patient_forms', { headers: setHeaders(apiKey), method: 'POST', body: JSON.stringify({ name: 'Meow meow

  • Intake form', patient: { links: { self: patientLink } }, restricted_to_practitioner: false, content: requestPayload.content }) }) .then(response => response.json()) .then(data => console.log(data))

I've also tried switching out patient for patient_id to no avail. Is there another step I'm missing? I'm able to make other GET and POST requests normally with other endpoints, but only seem to be having a bit of trouble specifically with the patient_forms one. Any help would be super appreciated 🙂

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/redguava/cliniko-api/issues/349, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACL3M2TWIHLPMPRQJUMIILTRI6GTANCNFSM46EVOAFQ .

Paperpotato commented 3 years ago

Silly me! I was actually missing the content-type header in the property. Thank you for the super quick reply John :)

Also, when I submitted an invalid patient_id (such as a link instead of the id), the status code returned was 500. It might be useful to have it return 404 instead 🙂