API v1.4

Tutorial 6 of 6

Move from the old integration

What changes when an integration that signs in with a username and password moves to OAuth.

Integrations built before October 2026 sign in with a username and password at portal.neurotrax.com/api/v1/…. They keep working exactly as they are. This tutorial is for moving one to OAuth, which is more secure and is where new features arrive.

You set up a key for the new integration and get a new client ID, so the old and the new can run side by side while you switch over, one call at a time.

1Change the address

New calls go to https://api.neurotrax.com/v1/… instead of https://portal.neurotrax.com/api/v1/…: the same paths, without /api. Request and response bodies for patients and orders are the same.

# Before
curl 'https://portal.neurotrax.com/api/v1/orders?status=completed' -H "Authorization: Bearer $OLD_TOKEN" -H 'X-Nx-Account: 200001'
# After
curl 'https://api.neurotrax.com/v1/orders?status=completed' -H "Authorization: Bearer $NEUROTRAX_TOKEN" -H 'X-Nx-Account: 200001'

2Replace the sign-in

Instead of posting a username and password to /api/v1/jwt, your integration signs a one-time pass with its private key and exchanges it at POST /oauth/token for a token that lasts an hour. No password is stored or sent anywhere. Create the key and send us its public half first (see Set up your key); the signed helper is in Your first call.

# Sign the assertion in your language (see the other tabs), then:
curl -X POST 'https://api.neurotrax.com/oauth/token' \
  -d grant_type=client_credentials \
  -d client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer \
  -d "client_assertion=$CLIENT_ASSERTION"
response = requests.post(TOKEN_URL, data={
    "grant_type": "client_credentials",
    "client_assertion_type": "urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
    "client_assertion": signed({"iss": CLIENT_ID, "sub": CLIENT_ID, "aud": TOKEN_URL}),
})
response.raise_for_status()
token = response.json()
print(token["expires_in"], token["scope"])
const response = await fetch(TOKEN_URL, {
  method: "POST",
  body: new URLSearchParams({
    grant_type: "client_credentials",
    client_assertion_type: "urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
    client_assertion: await signed({ iss: CLIENT_ID, sub: CLIENT_ID, aud: TOKEN_URL }),
  }),
});
if (!response.ok) throw new Error(`${response.status} ${await response.text()}`);
const token = await response.json();
console.log(token.expires_in, token.scope);
using var http = new HttpClient();
var response = await http.PostAsync(TokenUrl, new FormUrlEncodedContent(new Dictionary<string, string>
{
    ["grant_type"] = "client_credentials",
    ["client_assertion_type"] = "urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
    ["client_assertion"] = Signed(clientId, TokenUrl),
}));
response.EnsureSuccessStatusCode();
var token = await response.Content.ReadFromJsonAsync<JsonElement>();
Console.WriteLine($"{token.GetProperty("expires_in")} {token.GetProperty("scope")}");
import java.net.URI;
import java.net.URLEncoder;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;

var client = HttpClient.newHttpClient();
var form = "grant_type=client_credentials"
    + "&client_assertion_type=" + URLEncoder.encode("urn:ietf:params:oauth:client-assertion-type:jwt-bearer", StandardCharsets.UTF_8)
    + "&client_assertion=" + signed(clientId, tokenUrl, java.util.Map.of());
var request = HttpRequest.newBuilder(URI.create(tokenUrl))
    .header("Content-Type", "application/x-www-form-urlencoded")
    .POST(HttpRequest.BodyPublishers.ofString(form))
    .build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body()); // {"access_token":"...","token_type":"Bearer","expires_in":3600,...}
// In main:
res, err := http.PostForm(tokenURL, url.Values{
	"grant_type":            {"client_credentials"},
	"client_assertion_type": {"urn:ietf:params:oauth:client-assertion-type:jwt-bearer"},
	"client_assertion":      {signed(jwt.MapClaims{"iss": clientID, "sub": clientID, "aud": tokenURL})},
})
if err != nil {
	panic(err)
}
defer res.Body.Close()
var token struct {
	AccessToken string `json:"access_token"`
	ExpiresIn   int    `json:"expires_in"`
	Scope       string `json:"scope"`
}
json.NewDecoder(res.Body).Decode(&token)
fmt.Println(res.Status, token.ExpiresIn, token.Scope)
response = Net::HTTP.post_form(URI(TOKEN_URL),
  "grant_type" => "client_credentials",
  "client_assertion_type" => "urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
  "client_assertion" => signed(iss: CLIENT_ID, sub: CLIENT_ID, aud: TOKEN_URL))
response.value # raises unless the call succeeded
token = JSON.parse(response.body)
puts token["expires_in"], token["scope"]
fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client_id = CLIENT_ID;
    let client = reqwest::blocking::Client::new();
    let assertion = signed(json!({ "iss": client_id, "sub": client_id, "aud": TOKEN_URL }))?;
    let token: Value = client
        .post(TOKEN_URL)
        .form(&[
            ("grant_type", "client_credentials"),
            ("client_assertion_type", "urn:ietf:params:oauth:client-assertion-type:jwt-bearer"),
            ("client_assertion", assertion.as_str()),
        ])
        .send()?
        .error_for_status()?
        .json()?;
    println!("{} {}", token["expires_in"], token["scope"]);
    Ok(())
}

3Replace the account list

GET /api/v1/memberships becomes GET /v1/accounts. It lists the accounts your integration is granted, with each master account's sub-accounts nested under it.

curl 'https://api.neurotrax.com/v1/accounts' -H "Authorization: Bearer $NEUROTRAX_TOKEN"

4Replace portal sessions and data_report.php

  • Opening the portal: instead of POST /api/v1/sessions and a session ID in the URL, use a signed launch (see Act for a clinician). It needs no API call, and no session ID ever travels in a URL.
  • Reading results: instead of /reg/data_report.php, call GET /v1/data_reports/<report ID>?patient_number=<number> with your token (see Get results). The JSON has the same structure, without the patient's name.
curl 'https://api.neurotrax.com/v1/data_reports/1?patient_number=200001000417' \
  -H "Authorization: Bearer $NEUROTRAX_TOKEN" \
  -H 'X-Nx-Account: 200001'