Open staverton opened 2 years ago
Hi there!
I think the problem is you have the body being sent with the x-www-form-urlencoded option, but it needs to be JSON. On our side, it looks like your content is coming through as one big string instead of a JSON object.
Hope that helps! John
On Wed, Apr 6, 2022 at 12:06 PM staverton @.***> wrote:
Hi there,
I'm struggling to get the treatment_notes endpoint to accept treatment notes content. I can create the notes ok, but am struggling to actually update the notes - example of the data I'm feeding into 'content' below: {"sections": [{"name": "Section 1", "questions": [{"name": "Patient progress report", "type": "paragraph", "answer": "hello world"} ] } ] }
...and getting a 500 error:
[image: image] https://user-images.githubusercontent.com/100085262/162017948-1e51667f-c54c-47b5-823d-022a1a162e98.png
Any help gratefully received.
— Reply to this email directly, view it on GitHub https://github.com/redguava/cliniko-api/issues/362, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACL3M7JVP55VXR5W2V7Q7DVDWY7JANCNFSM5SWRA2EQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>
Thanks for getting back so quickly John!
I'm now up against a validation failure... (please be patient!). Message body as follows:
{ "body": { "patient_id": xxx, "treatment_note_template_id": xxx, "draft": true, "content": { "sections": [ { "name": "Section 1", "questions": [ { "name": "Patient progress report", "type": "paragraph", "answer": "Hello world" } ] } ] } } }
And a response of:
{ "errors": { "patient": "can’t be blank", "title": "can’t be blank" }, "message": "Validation Failed" }
...which is kinda odd because I couldn't see 'title' or 'patient' in the api docs?!
Thanks again for your help on this.
Almost there! body is just the content of the request. Not a property in the JSON object.
You're posting to treatment notes, to create the treatment note:
POST /v1/treatment_notes
Your JSON will be:
{
"patient_id": "xxx",
"treatment_note_template_id": "xxx",
"draft": true,
"content": {
"sections": [
{
"name": "Section 1",
"questions": [
{
"name": "Patient progress report",
"type": "paragraph",
"answer": "Hello world"
}
]
}
]
}
}
To update a treatment note, you make a PUT
request instead.
You can only update treatment notes that are still in a
draft
state. Once a treatment note has been updated withdraft: false
, you cannot make any further changes to the treatment note record.
PUT /v1/treatment_notes/xxx
Your JSON will be same as above, with the changes you require. For example, your update may just be finalising the treatment note with:
{
"draft": false
}
PS - this worked using Postman, but I got the above error using Power Automate.
Ah - yup, sorry I had excluded 'body' from the body 😂 - just copied the code wrong, so I'm afraid I am still having issues.
I will definitely follow up a post with the put as you say to mark as final - nice touch. I wonder if you're able to 'fix' the date the note was taken as well?
I don't use Power Automate, sorry! The request body looks fine to me. Maybe it needs to be stringified before sending? If you can see the response text from that 422 response, that might help identify what's wrong? We send 422s when the content of your request is invalid in some way (missing params, wrongly typed params, invalid content, etc.)
I don't blame you! 😂
I'm getting the validation failure below - is this something you can see on your end?
{ "errors": { "draft": "is not included in the list", "patient": "can’t be blank", "title": "can’t be blank" }, "message": "Validation Failed" }
The above was what I got with a stringified version - the below is what I get with a JSON body:
{ "errors": { "patient": "can’t be blank" }, "message": "Validation Failed" }
It looks like you're missing the Content-Type header, so I think your body is not getting processed correctly. It should be set to application/json.
I wonder if you're able to 'fix' the date the note was taken as well?
Cliniko does not allow dates of treatment notes to be changed.
On Thu, Apr 7, 2022 at 9:31 AM staverton @.***> wrote:
The above was what I got with a stringified version - the below is what I get with a JSON body:
{ "errors": { "patient": "can’t be blank" }, "message": "Validation Failed" }
— Reply to this email directly, view it on GitHub https://github.com/redguava/cliniko-api/issues/362#issuecomment-1091742411, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACL3M4ER2XUX6LEDUOHSRTVD3PTJANCNFSM5SWRA2EQ . You are receiving this because you commented.Message ID: @.***>
I’m afraid I tried that – I also tried “application/json; charset=utf-8”
Annoying!
From: John Colvin @.> Sent: 07 April 2022 15:53 To: redguava/cliniko-api @.> Cc: Ben Deacon @.>; Author @.> Subject: [EXTERNAL] Re: [redguava/cliniko-api] Content creation in Treatment Notes failing (Issue #362)
It looks like you're missing the Content-Type header, so I think your body is not getting processed correctly. It should be set to application/json.
I wonder if you're able to 'fix' the date the note was taken as well?
Cliniko does not allow dates of treatment notes to be changed.
On Thu, Apr 7, 2022 at 9:31 AM staverton @.***> wrote:
The above was what I got with a stringified version - the below is what I get with a JSON body:
{ "errors": { "patient": "can’t be blank" }, "message": "Validation Failed" }
— Reply to this email directly, view it on GitHub https://github.com/redguava/cliniko-api/issues/362#issuecomment-1091742411, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACL3M4ER2XUX6LEDUOHSRTVD3PTJANCNFSM5SWRA2EQ . You are receiving this because you commented.Message ID: @.***>
— Reply to this email directly, view it on GitHubhttps://github.com/redguava/cliniko-api/issues/362#issuecomment-1091840397, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AX3S4DUC7DFZIAG2BYKJV6LVD3ZFZANCNFSM5SWRA2EQ. You are receiving this because you authored the thread.Message ID: @.***>
This message is confidential and may be covered by legal professional privilege. If you are not the intended recipient, you must not disclose or use the information contained in it. If you have received this email in error, please notify us immediately by return email or by calling us on +44 (0)7980 621088 and delete the email. Further information is available from www.stavertonpartners.co.uk.
EDIT: Didn't realize this was a github issue, I was emailing thinking it was the google group 🤦 I remade my comment below to use github formatting.
I think for us to be able to help, we'll need to be using the same tool. Which unfortunately means CURL. Below is the simplest POST that will work for a treatment note. Once that's working with your params, add your content to make sure it's working. If CURL works then we'll know there's a problem somewhere in the other tool you're using.
curl https://api.au1.cliniko.com/v1/treatment_notes \
-u YOURAPIKEY-au1: \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'User-Agent: CURL ***@***.***)' \
-d '{ "draft": true, "patient_id": 835505263451571861, "title": "Test" }' \
-X POST
Hi there,
I'm struggling to get the treatment_notes endpoint to accept treatment notes content. I can create the notes ok, but am struggling to actually update the notes - example of the data I'm feeding into 'content' below:
{"sections": [{"name": "Section 1", "questions": [{"name": "Patient progress report", "type": "paragraph", "answer": "hello world"} ] } ] }
...and getting a 500 error:
Any help gratefully received.