Skip to content

Instantly share code, notes, and snippets.

@aerostitch
Last active June 17, 2019 19:20
Show Gist options
  • Save aerostitch/4cef457c4489a9080533ff4f0fba5351 to your computer and use it in GitHub Desktop.
Save aerostitch/4cef457c4489a9080533ff4f0fba5351 to your computer and use it in GitHub Desktop.
Examples of usage of the slab.com api using curl
# This is a list of examples on how to interact with the slab.com API using curl.
# The original documentation is https://the.slab.com/public/slab-api-vk0o0i33 but missing good examples
# so I figured I'd keep that one here for future reference
SLAB_TOKEN=<PLACE_YOUR_TOKEN_HERE>
# Get the organization domain
curl -s -X POST \
-H "Authorization: ${SLAB_TOKEN}" \
-H "Content-Type: application/json" \
-d '{"query":"query { organization { host } }"}' \
https://api.slab.com/v1/graphql | python -m json.tool
# List topics hierarchy
cat > /tmp/slab000.tmp <<- __EOF__
{
"query": "query {
organization {
topics {
id
description
hierarchy
insertedAt
updatedAt
ancestors {
id
}
children {
id
}
parent {
id
}
posts {
id
title
updatedAt
insertedAt
}
}
}
}"
}
__EOF__
curl -s -X POST \
-H "Authorization: ${SLAB_TOKEN}" \
-H "Content-Type: application/json" \
-d "@/tmp/slab000.tmp" \
https://api.slab.com/v1/graphql | python -m json.tool
# List posts
cat > /tmp/slab000.tmp <<- __EOF__
{
"query": "query {
organization {
posts {
id
title
content
updatedAt
version
insertedAt
}
}
}"
}
__EOF__
curl -s -X POST \
-H "Authorization: ${SLAB_TOKEN}" \
-H "Content-Type: application/json" \
-d "@/tmp/slab000.tmp" \
https://api.slab.com/v1/graphql | python -m json.tool
# View a given post
POST_ID=aa23bb44
cat > /tmp/slab000.tmp <<- __EOF__
{
"query": "{
post(id: \"${POST_ID}\") {
id
title
content
}
}"
}
__EOF__
curl -s -X POST \
-H "Authorization: ${SLAB_TOKEN}" \
-H "Content-Type: application/json" \
-d "@/tmp/slab000.tmp" \
https://api.slab.com/v1/graphql | python -m json.tool
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment