Skip to content

Commit

Permalink
Add and update cURL examples
Browse files Browse the repository at this point in the history
  • Loading branch information
szuperaz committed May 13, 2024
1 parent 3622409 commit 4407580
Show file tree
Hide file tree
Showing 22 changed files with 1,444 additions and 236 deletions.
5 changes: 2 additions & 3 deletions docusaurus/video/docusaurus/docs/api/_common_/broadcast.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ call.start_hls_broadcasting()
<TabItem value="curl" label="cURL">

```bash
curl -X POST "https://video.stream-io-api.com/video/call/${CALL_TYPE}/${CALL_ID}/start_broadcasting?api_key=${API_KEY}" \
-H "Authorization: ${JWT_TOKEN}" \
-H "Content-Type: application/json" \
curl -X POST "https://video.stream-io-api.com/api/v2/video/call/${CALL_TYPE}/${CALL_ID}/start_broadcasting?api_key=${API_KEY}" \
-H "Authorization: ${TOKEN}" \
-H "stream-auth-type: jwt"
```

Expand Down
27 changes: 14 additions & 13 deletions docusaurus/video/docusaurus/docs/api/_common_/create-call.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,20 @@ call.create(
<TabItem value="curl" label="cURL">

```bash
curl -X POST "https://video.stream-io-api.com/video/call/${CALL_TYPE}/${CALL_ID}?api_key=${API_KEY}" \
-H "Authorization: ${JWT_TOKEN}" \
-H "Content-Type: application/json" \
-H "stream-auth-type: jwt" \
-d '{
"data": {
"created_by_id": "[email protected]",
"members": [
{ "role": "speaker", "user_id": "[email protected]" }
],
"custom": { "color": "blue" }
}
}'
# Gets or creates a call
curl -X POST "https://video.stream-io-api.com/api/v2/video/call/${CALL_TYPE}/${CALL_ID}?api_key=${API_KEY}" \
-H "Authorization: ${TOKEN}" \
-H "Content-Type: application/json" \
-H "stream-auth-type: jwt" \
-d '{
"data": {
"created_by_id": "[email protected]",
"members": [
{ "role": "admin", "user_id": "[email protected]" }
],
"custom": { "color": "blue" }
}
}'
```

</TabItem>
Expand Down
17 changes: 17 additions & 0 deletions docusaurus/video/docusaurus/docs/api/_common_/go_live.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,22 @@ call.goLive({ start_hls: true, start_recording: true });
call.go_live(start_hls=True, start_recording=True)
```

</TabItem>

<TabItem value="curl" label="cURL">

```bash
curl -X POST "https://video.stream-io-api.com/api/v2/video/call/livestream/${CALL_ID}/go_live?api_key=${API_KEY}" \
-H "Authorization: ${TOKEN}" \
-H "stream-auth-type: jwt"

# optionally start HLS broadcast and/or recording
curl -X POST "https://video.stream-io-api.com/api/v2/video/call/livestream/${CALL_ID}/go_live?api_key=${API_KEY}" \
-H "Authorization: ${TOKEN}" \
-H "stream-auth-type: jwt" \
-H "Content-Type: application/json" \
-d '{ "start_hls": true, "start_recording": true }'
```

</TabItem>
</Tabs>
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,17 @@ call.update_call_members(
<TabItem value="curl" label="cURL">

```bash
curl -X PUT "https://video.stream-io-api.com/video/call/default/${CALL_ID}/members?api_key=${API_KEY}" \
-H "Authorization: ${JWT_TOKEN}" \
-H "Content-Type: application/json" \
-H "stream-auth-type: jwt" \
-d '{
"update_members": [
{ "user_id": "sara" },
{ "user_id": "emily", "role": "admin" }
]
}'
# You can only add existing members to a call
curl -X POST "https://video.stream-io-api.com/api/v2/video/call/${CALL_TYPE}/${CALL_ID}/members?api_key=${API_KEY}" \
-H "Authorization: ${TOKEN}" \
-H "Content-Type: application/json" \
-H "stream-auth-type: jwt" \
-d '{
"update_members": [
{ "user_id": "sara" },
{ "user_id": "john", "role": "admin" }
]
}'
```

</TabItem>
Expand All @@ -68,5 +69,18 @@ call.updateCallMembers({
call.update_call_members(remove_members=["jack", "sara"])
```

</TabItem>
<TabItem value="curl" label="cURL">

```bash
curl -X POST "https://video.stream-io-api.com/api/v2/video/call/${CALL_TYPE}/${CALL_ID}/members?api_key=${API_KEY}" \
-H "Authorization: ${TOKEN}" \
-H "Content-Type: application/json" \
-H "stream-auth-type: jwt" \
-d '{
"remove_members": ["sara"]
}'
```

</TabItem>
</Tabs>
12 changes: 12 additions & 0 deletions docusaurus/video/docusaurus/docs/api/_common_/rtmp.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,17 @@ rtmp_url = response.data.call.ingress.rtmp.address
print(rtmp_url, stream_key)
```

</TabItem>
<TabItem value="curl" label="cURL">

```bash
# RTMP URL is: response.call.rtmp.address
curl -X GET "https://video.stream-io-api.com/api/v2/video/call/livestream/${CALL_ID}?api_key=${API_KEY}" \
-H "Authorization: ${TOKEN}" \
-H "stream-auth-type: jwt"

# Stream key: create a user token
```

</TabItem>
</Tabs>
21 changes: 11 additions & 10 deletions docusaurus/video/docusaurus/docs/api/_common_/update-call.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,18 @@ call.update(
<TabItem value="curl" label="cURL">

```bash
curl -X PUT "https://video.stream-io-api.com/video/call/default/${CALL_ID}?api_key=${API_KEY}" \
-H "Authorization: ${JWT_TOKEN}" \
-H "Content-Type: application/json" \
-H "stream-auth-type: jwt" \
-d '{
"settings_override": {
"audio": {
"mic_default_on": true
}
curl -X PATCH "https://video.stream-io-api.com/api/v2/video/call/default/${CALL_ID}?api_key=${API_KEY}" \
-H "Authorization: ${TOKEN}" \
-H "stream-auth-type: jwt" \
-H "Content-Type: application/json" \
-d '{
"settings_override": {
"audio": {
"mic_default_on": true,
"default_device": "speaker"
}
}'
}
}'
```

</TabItem>
Expand Down
140 changes: 139 additions & 1 deletion docusaurus/video/docusaurus/docs/api/basics/authentication.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,29 @@ client.upsert_users(
)
```

</TabItem>
<TabItem value="curl" label="cURL">

```bash
curl -X POST https://video.stream-io-api.com/api/v2/users?api_key=${API_KEY} \
-H "Authorization: ${TOKEN}" \
-H "stream-auth-type: jwt" \
-H "Content-Type: application/json" \
-d '{
"users": {
"john": {
"id": "john",
"role": "user",
"custom": {
"color": "red"
},
"name": "John",
"image": "link/to/profile/image"
}
}
}'
```

</TabItem>
</Tabs>

Expand Down Expand Up @@ -124,6 +147,47 @@ client.update_users_partial(
)
```

</TabItem>
<TabItem value="curl" label="cURL">

```bash
# Upserting a user, all existing user data will be overridden
curl -X POST https://video.stream-io-api.com/api/v2/users?api_key=${API_KEY} \
-H "Authorization: ${TOKEN}" \
-H "stream-auth-type: jwt" \
-H "Content-Type: application/json" \
-d '{
"users": {
"john": {
"id": "john",
"role": "user",
"custom": {
"color": "red"
},
"name": "John",
"image": "link/to/profile/image"
}
}
}'

# Partial update
curl -X PATCH https://video.stream-io-api.com/api/v2/users?api_key=${API_KEY} \
-H "Authorization: ${TOKEN}" \
-H "stream-auth-type: jwt" \
-H "Content-Type: application/json" \
-d '{
"users": [
{
"id": "john",
"set": {
"color": "blue"
},
"unset": ["name"]
}
]
}'
```

</TabItem>
</Tabs>

Expand Down Expand Up @@ -153,7 +217,7 @@ Deleting a user means:
Delete has the following opitions:

| Name | Type | Description | Optional |
|------------------------|----------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|
| ---------------------- | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- |
| `user` | Enum (soft, pruning, hard) | - Soft: marks user as deleted and retains all user data. <br /> - Pruning: marks user as deleted and nullifies user information. <br /> - Hard: deletes user completely - this requires hard option for messages and conversation as well. | Yes |
| `conversations` | Enum (soft, hard) | - Soft: marks all conversation channels as deleted (same effect as Delete Channels with 'hard' option disabled). <br /> - Hard: deletes channel and all its data completely including messages (same effect as Delete Channels with 'hard' option enabled). | Yes |
| `messages` | Enum (soft, pruning, hard) | - Soft: marks all user messages as deleted without removing any related message data. <br /> - Pruning: marks all user messages as deleted, nullifies message information and removes some message data such as reactions and flags. <br /> - Hard: deletes messages completely with all related information. | Yes |
Expand Down Expand Up @@ -198,6 +262,47 @@ client.delete_users(user_ids=["<id>"])
client.restore_users(user_ids=["<id>"])
```

</TabItem>
<TabItem value="curl" label="cURL">

```bash
# Deactivate users
curl -X POST https://video.stream-io-api.com/api/v2/users/deactivate?api_key=${API_KEY} \
-H "Authorization: ${TOKEN}" \
-H "stream-auth-type: jwt" \
-H "Content-Type: application/json" \
-d '{
"user_ids": ["sara"]
}'

# Reactivate users
curl -X POST https://video.stream-io-api.com/api/v2/users/deactivate?api_key=${API_KEY} \
-H "Authorization: ${TOKEN}" \
-H "stream-auth-type: jwt" \
-H "Content-Type: application/json" \
-d '{
"user_ids": ["sara"]
}'

# Delete users
curl -X POST https://video.stream-io-api.com/api/v2/users/delete?api_key=${API_KEY} \
-H "Authorization: ${TOKEN}" \
-H "stream-auth-type: jwt" \
-H "Content-Type: application/json" \
-d '{
"user_ids": ["sara"]
}'

# Restore users
curl -X POST https://video.stream-io-api.com/api/v2/users/restore?api_key=${API_KEY} \
-H "Authorization: ${TOKEN}" \
-H "stream-auth-type: jwt" \
-H "Content-Type: application/json" \
-d '{
"user_ids": ["sara"]
}'
```

</TabItem>
</Tabs>

Expand Down Expand Up @@ -244,6 +349,22 @@ def create_user_token(request):

```

</TabItem>

<TabItem value="bash" label="Bash">

```bash
HEADER=$(echo -n '{"alg": "HS256", "typ": "JWT"}' | base64);
USER_ID='<user id>';
CURRENT_TIMESTAMP=$(date +%s);
HOUR_FROM_NOW=$((CURRENT_TIMESTAMP + 3600))
PAYLOAD=$(echo -n '{"user_id": "'${USER_ID}'", "iat": '${CURRENT_TIMESTAMP}', "exp": '${HOUR_FROM_NOW}'}' | base64);
SECRET='<API secret>';
SIGNATURE=$(echo -n ${HEADER}.${PAYLOAD} | openssl dgst -sha256 -hmac ${SECRET} -binary | base64 | tr -d '=');

echo "${HEADER}.${PAYLOAD}.${SIGNATURE}"
```

</TabItem>
</Tabs>

Expand Down Expand Up @@ -280,5 +401,22 @@ call_cids = ["default:call1", "livestream:call2"]
client.create_call_token(user_id=user_id, expiration=exp, call_cids=call_cids)
```

</TabItem>

<TabItem value="bash" label="Bash">

```bash
HEADER=$(echo -n '{"alg": "HS256", "typ": "JWT"}' | base64);
USER_ID='<user id>';
CURRENT_TIMESTAMP=$(date +%s);
HOUR_FROM_NOW=$((CURRENT_TIMESTAMP + 3600))
CALL_CID='123';
PAYLOAD=$(echo -n '{"user_id": "'${USER_ID}'", "call_cids": ["'${CALL_CID}'"], "iat": '${CURRENT_TIMESTAMP}', "exp": '${HOUR_FROM_NOW}'}' | base64);
SECRET='<API secret>';
SIGNATURE=$(echo -n ${HEADER}.${PAYLOAD} | openssl dgst -sha256 -hmac ${SECRET} -binary | base64 | tr -d '=');

echo "${HEADER}.${PAYLOAD}.${SIGNATURE}"
```

</TabItem>
</Tabs>
Loading

0 comments on commit 4407580

Please sign in to comment.