Patient Creation 400 error using Google Apps Script

75 views
Skip to first unread message

Dhruv Magar

unread,
Jul 6, 2023, 10:16:08 AM7/6/23
to DrChrono API Developers
Hello,

I am running into a 400 error while trying to POST to api/patients from Google Apps Script. The message says that I am missing the required 'gender' and 'doctor' parameters, but they are clearly defined in the payload of the request. I am able to authenticate properly, so I know I am not having an issue there. Here is a minimal payload sample which was yielding me the error:

function test_create_patient(){
var options = {};
options.headers = {Authorization: 'Bearer ' + getOAuthService().getAccessToken()};
options.method = 'POST';
options.payload = JSON.stringify({'gender': "Male",'doctor': 355753, 'first_name': 'Test', 'last_name': 'API'});
const response = UrlFetchApp.fetch(url, options);
Logger.log(JSON.parse(response))
}


Can anyone help me figure out why this is happening? Thanks in advance!

The content of this email is intended for the person or entity to which it is addressed only. This email may contain confidential information. If you are not the person to whom this message is addressed, be aware that any use, reproduction, or distribution of this message is strictly prohibited. If you received this in error, please contact the sender and immediately delete this email and any attachments.

aaron....@drchrono.com

unread,
Jul 6, 2023, 10:35:49 AM7/6/23
to DrChrono API Developers
Hello Dhruv. 
I'm thinking it may be necessary to add "{'content-type': 'application/json'}" to your headers to appropriately translate the values you've submitted. Let me know if that works.

Bryan Golkhajeh

unread,
Jul 17, 2023, 3:26:19 PM7/17/23
to DrChrono API Developers
Hi Druv, 

Adding on to Aaron's reply, have you also tried not using "JSON.stringify" in the payload? 

You can also use this tool called workload to use the API that handles everything like auth, payloads, etc. without writing code. 

Interested to know if that helps!

Dhruv Magar

unread,
Aug 9, 2023, 9:27:26 AM8/9/23
to DrChrono API Developers
Hi all,

Sorry for the late response - I needed to add '{'content-type''application/json'}' like Aaron had commented. 

Thanks for your help!
Reply all
Reply to author
Forward
0 new messages