Search…
Make your first API request

Medable API requests

To make your first Medable API request, you need to know four things:
    1.
    The API endpoint: for example, api.<env>.medable.com/<org_code>
    2.
    The API key: for example, mwidxhb8ShcqmV1B9iOYJh
    3.
    Authentication credentials: an email and password
    4.
    The API client: a terminal, web, iOS, or Android

The API endpoint

The endpoint for your API requests will look like the following:
HTTP
1
https://api.dev.medable.com/{{your_org_code}}/v2/{{api_resource}}
Copied!
Where your_org_code is the org code you specified when signing up and api_resource is the resource you are trying to access, such as an account. And remember, since we're making this request to the development org, we use the api.dev.medable.com URL.
In our case, we'll use the example org code we used when we made the new app: newhealthco.
Note: When making requests, use the plural name for api_resource. For example, if the resource is account, use accounts in your endpoint: https://api.dev.medable.com/newhealthco/v2/accounts

The API key

Copy the API key that you generated in the previous step (see Generate an API key). In our example, the API key is mwidxhb8ShcqmV1B9iOYJh.

Authentication credentials

Because we specified that our app uses sessions, a username and password is needed to authenticate and initiate a user session.
For the username, use your email address. In our case, it's [email protected]. For the password, use the password you set when signing up.
If you're interested in signature-based authentication, see Authentication.

The API client

There are a number of tools out there that make it easy to make API requests. One option is Postman and another option is the live API explorer in the API Reference page. In this guide, we'll keep it simple and make our requests from the command line using curl.

Make a request

Note: This section is written assuming the request is being made through an OSX terminal.
Now that you're ready to make a request, you simply have to issue the command in the form of curl \[options...\] URL. Let's give it a shot using the API endpoint:
Request
Response
1
$ curl https://api.dev.medable.com/newhealthco/v2/accounts
Copied!
1
{
2
"object":"fault",
3
"name":"error",
4
"code":"kNotFound",
5
"status":404,
6
"reason":"Invalid application client api key.",
7
"message":"Resource not found"
8
}
Copied!
Tip: Add | python -m json.toolto the end of the curl request to pretty-print the JSON response.
We got a result back! Unfortunately, the result is a fault.
This is because we need to pass in a few more options to get the request to work. First, we need to add the API key header. We can do this using the following option:
-H "medable-client-key: mwidxhb8ShcqmV1B9iOYJh"
So let's give that a try:
Request
Response
1
$ curl -H "medable-client-key: mwidxhb8ShcqmV1B9iOYJh" https://api.dev.medable.com/newhealthco/v2/accounts
Copied!
1
{
2
"object":"list",
3
"data":[
4
5
],
6
"hasMore":false
7
}
Copied!
The fault is gone, but now we get back an unexpected result. Rather than a list of accounts, which should at least have our own account in it, we get an empty result.
This is because the Account resource requires authentication to access. If we had tried to access a specific account using an account ID (575f58281d0c03a53ccc3ac6 in this case), we would receive a 403 error like so:
Request
Response
1
$ curl -H "medable-client-key: mwidxhb8ShcqmV1B9iOYJh" https://api.dev.medable.com/newhealthco/v2/accounts/575f58281d0c03a53ccc3ac6
Copied!
1
{
2
"object":"fault",
3
"name":"error",
4
"code":"kAccessDenied",
5
"status":403,
6
"reason":"Read access denied.",
7
"message":"Access to this resource is denied"
8
}
Copied!
So let's authenticate. To log in, we need to POST to the login route with our username and password. For more information on the Account resource and the available routes, see the API documentation on Accounts.
One more thing before we log in. For session-based apps, Medable uses cookies to track the session ID. So we need to enable cookie support in curl. To do this, we pass in the additional options:-b cookies.txt -c cookies.txt
The first option -b reads any existing cookies from cookies.txt and sends with the request. The second option -c writes any cookies coming from Medable to cookies.txt.
Request
Response
1
$ curl -b cookies.txt -c cookies.txt -H "medable-client-key: mwidxhb8ShcqmV1B9iOYJh" -d "[email protected]&password=This is not the password\!" https://api.dev.medable.com/newhealthco/v2/accounts/login
Copied!
1
{
2
"_id":"575f58281d0c03a53ccc3ac6",
3
"object":"account",
4
"created":"2016-06-14T01:04:40.888Z",
5
"updated":"2016-06-14T01:08:06.647Z",
6
"updater":{
7
"_id":"575f58281d0c03a53ccc3ac6",
8
"object":"account",
9
"path":"/accounts/575f58281d0c03a53ccc3ac6"
10
},
11
"access":6,
12
"favorite":false,
13
"email":"[email protected]",
14
"name":{
15
"first":"John",
16
"last":"Smith"
17
},
18
"mobile":"+15555555555",
19
"locale":"en_US",
20
"state":"verified",
21
"locked":false,
22
"key":{
23
"fingerprint":"73ad85a0-31cc-11e6-ba07-3f24c7443557",
24
"secret":"PXXvBvG86sJC2RVk4X6K4FV0OUH7ojzp"
25
},
26
"roles":[
27
"000000000000000000000004",
28
"000000000000000000000007",
29
"000000000000000000000006"
30
],
31
"shared":false
32
}
Copied!
And we've successfully logged in! We know this because after a successful login, we receive our account object in the response.
If, instead of a response similar to the above, you receive a fault response that resembles this:
1
{
2
"object": "fault",
3
"name": "location",
4
"code": "kNewLocation",
5
"status": 403,
6
"message": "A new location has been added to the account."
7
}
Copied!
This means that two-factor authentication (2FA) has been initiated. Note that the fault could be kNewLocation, kUnverifiedLocation, or kLocationClientMismatch.
When this happens, you will receive a verification token via SMS to your mobile number. Once you receive that token, you'll need to authenticate again as well as send along verificationToken like so:
1
curl -b cookies.txt -c cookies.txt -H "medable-client-key: mwidxhb8ShcqmV1B9iOYJh" -d '[email protected]&password=NotYourPassword&location[verificationToken]=123456' https://api.medable.com/newhealthco/v2/accounts/login
Copied!
For more information on 2FA, see Two-factor authentication.
Now that we've logged in and have an active session, let's try that account request again.
Request
Response
1
$ curl -b cookies.txt -c cookies.txt -H
2
"medable-client-key: mwidxhb8ShcqmV1B9iOYJh"
3
-d "[email protected]&password=This is not the password\!"
4
https://api.dev.medable.com/newhealthco/v2/accounts/login
Copied!
1
{
2
"_id":"575f58281d0c03a53ccc3ac6",
3
"object":"account",
4
"created":"2016-06-14T01:04:40.888Z",
5
"updated":"2016-06-14T01:08:06.647Z",
6
"updater":{
7
"_id":"575f58281d0c03a53ccc3ac6",
8
"object":"account",
9
"path":"/accounts/575f58281d0c03a53ccc3ac6"
10
},
11
"access":6,
12
"favorite":false,
13
"email":"[email protected]",
14
"name":{
15
"first":"John",
16
"last":"Smith"
17
},
18
"mobile":"+15555555555",
19
"locale":"en_US",
20
"state":"verified",
21
"locked":false,
22
"key":{
23
"fingerprint":"73ad85a0-31cc-11e6-ba07-3f24c7443557",
24
"secret":"PXXvBvG86sJC2RVk4X6K4FV0OUH7ojzp"
25
},
26
"roles":[
27
"000000000000000000000004",
28
"000000000000000000000007",
29
"000000000000000000000006"
30
],
31
"shared":false
32
}
Copied!
Success! You've made your first API request!
Last modified 1mo ago