You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: authentication-personalization/sending-data.mdx
+64-9Lines changed: 64 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,12 @@
1
1
---
2
2
title: "Sending Data"
3
-
description: "The shape of user data you can use to personalize your docs"
3
+
description: "User data format for personalizing your documentation"
4
4
icon: "send"
5
5
---
6
6
7
-
Depending on your Handshake method, your API will respond with either a raw JSON object or a signed JWT. The shape of the data is the same for both:
7
+
When implementing authentication or personalization, your system returns user data in a specific format that enables content customization. This data can be sent as either a raw JSON object or within a signed JWT, depending on your handshake method. The shape of the data is the same for both.
8
+
9
+
## User data format
8
10
9
11
```tsx
10
12
typeUser= {
@@ -24,28 +26,81 @@ type User = {
24
26
path="expiresAt"
25
27
type="number"
26
28
>
27
-
The time at which this information should expire, in **seconds since epoch**. If the user loads the page and the current time is after this value, the stored data will be deleted.
28
-
<Warning><b>For JWT Handshakes:</b> This is *not* the same as the `exp` claim of the JWT. The `exp` claimdetermines when a JWT should no longer be considered valid, and should be set as low as possible. In this case, it can probably be set to 10 seconds or lower. The`expiresAt`field determines when retrieved data should be considered stale, and can be anywhere from one day to several weeks.</Warning>
29
+
Session expiration time in **seconds since epoch**. If the user loads a page after this time, their stored data is automatically deleted and they must reauthenticate.
30
+
<Warning><b>For JWT handshakes:</b> This differs from the JWT's `exp` claim, which determines when a JWT is considered invalid. Set the JWT `exp` claim to a short duration (10 seconds or less) for security. Use`expiresAt`for the actual session length (hours to weeks).</Warning>
29
31
</ParamField>
30
32
<ParamField
31
33
path="groups"
32
34
type="string[]"
33
35
>
34
-
A list of groups that the user belongs to. This will determine which pages should be shown to this user. If any of these groups is listed in the `groups` field of a page’s metadata, that page will be shown.
36
+
A list of groups that the user belongs to. Pages with a matching `groups` field in their metadata will be visible to this user.
37
+
38
+
**Example**: User with `groups: ["admin", "engineering"]` can access pages tagged with either the `admin` or `engineering` groups.
35
39
</ParamField>
36
40
<ParamField
37
41
path="content"
38
42
type="object"
39
43
>
40
-
A bag of values that can be accessed from within MDX content using the `user` variable. For example, if you have supplied `{ firstName: 'Ronan' }` as your content field, you can use the following in your MDX: `Good morning, {user.firstName}!`
44
+
Custom data accessible in your `MDX` content via the `user` variable. Use this for dynamic personalization throughout your documentation.
Welcome back, {user.firstName}! Your {user.plan} plan includes...
54
+
```
55
+
With the example `user` data, this would render as: Welcome back, Ronan! Your Enterprise plan includes...
41
56
</ParamField>
42
57
<ParamField
43
58
path="apiPlaygroundInputs"
44
59
type="object"
45
60
>
46
-
User-specific values that will be prefilled in the API playground if supplied. For example, if each of my customers makes requests at a specific subdomain, I can send `{ server: { subdomain: 'foo' } }` as my `apiPlaygroundInputs` field, and this value will be prefilled on any API page with this `subdomain` value.
61
+
User-specific values that will be prefilled in the API playground if supplied. Save users time when testing your APIs with their own data.
62
+
63
+
**Example**:
64
+
```json
65
+
{
66
+
"header": { "X-API-Key": "user_api_key_123" },
67
+
"server": { "subdomain": "foo" },
68
+
"query": { "org_id": "12345" }
69
+
}
70
+
```
71
+
If a user makes requests at a specific subdomain, you can send `{ server: { subdomain: 'foo' } }` as an `apiPlaygroundInputs` field. This value will be prefilled on any API page with the `subdomain` value.
47
72
48
-
<Note>The`header`, `query`, and `cookie` fields will only be prefilled if they are part of your [security scheme](https://swagger.io/docs/specification/authentication/). Creating a standard header parameter named `Authorization`is not sufficient to enable this feature. To know if a field will be prefilled, navigate to your existing docs and check if the field is in either the `Authorization`or `Server` section.</Note>
73
+
<Note>The`header`, `query`, and `cookie` fields will only prefill if they are part of your [OpenAPI security scheme](https://swagger.io/docs/specification/authentication/). If a field is in either the `Authorization`or `Server` sections, it will prefill. Creating a standard header parameter named `Authorization`will not enable this feature.</Note>
49
74
</ParamField>
50
75
51
-
76
+
## Example user data
77
+
78
+
```json
79
+
{
80
+
"expiresAt": 1735689600,
81
+
"groups": ["admin", "beta-users"],
82
+
"content": {
83
+
"firstName": "Jane",
84
+
"lastName": "Smith",
85
+
"company": "TechCorp",
86
+
"plan": "Enterprise",
87
+
"region": "us-west"
88
+
},
89
+
"apiPlaygroundInputs": {
90
+
"header": {
91
+
"Authorization": "Bearer abc123",
92
+
"X-Org-ID": "techcorp"
93
+
},
94
+
"server": {
95
+
"environment": "production",
96
+
"region": "us-west"
97
+
}
98
+
}
99
+
}
100
+
```
101
+
102
+
This enables:
103
+
104
+
***Access control**: User sees `admin` and `beta-user` pages.
105
+
***Personalization**: Content personalization based on `user` data like `firstName`, `company`, and `plan`.
106
+
***API testing**: Pre-filled authentication and org-specific values.
0 commit comments