Accessing the API from the command line
The following section contains a couple of examples/snippets on how to access the API from the command line.
Info
All examples/snippets are meant to be run sequentially as variables from previous requests are used.
Info
All the examples in this document assume you are using an instance of Arrigo Local installed on your local computer. Remember to change hostname and protocol (both http
and ws
) if you are testing against another computer:
http://localhost/arrigo/api
→ https://myserver.com/arrigo/api
ws://localhost/arrigo/api
→ wss://myserver.com/arrigo/api
Using Power Shell
Logging in
$url = "http://localhost/arrigo/api/login"
$headers = @{
"Content-Type" = "application/json"
}
$body = @'
{
"username": "user",
"password": "password"
}
'@
# Convert the response to Json and store it in a variable
$loginResponse = Invoke-WebRequest -Uri $url -Method POST -Body $body -Headers $headers | ConvertFrom-Json
Output
None, but the response is stored in a variable.
Getting the root folder
$url = "http://localhost/arrigo/api//graphql"
# Use the authToken from the loginResponse
$headers = @{
"Content-Type" = "application/json"
"Authorization" = "Bearer $($loginResponse.authToken)"
}
$body = @'
{
"query": "{folder {name}}"
}
'@
$response = Invoke-WebRequest -Uri $url -Method POST -Body $body -Headers $headers | ConvertFrom-Json
# Write the root folder name
Write-Host $response.data.folder.name
Output
account
Iterating sub-folders
$url = "http://localhost/arrigo/api/graphql"
# Use the authToken from the loginResponse
$headers = @{
"Content-Type" = "application/json"
"Authorization" = "Bearer $($loginResponse.authToken)"
}
$body = @'
{
"query": "{folder{name folders{edges{node{name}}}}}"
}
'@
$response = Invoke-WebRequest -Uri $url -Method POST -Body $body -Headers $headers | ConvertFrom-Json
# Iterate over the sub-folders and write their names
$response.data.folder.folders.edges | ForEach-Object {Write-Host $_.node.name}
Output
Using curl
These examples/snippets requires jq to be installed.
Logging in
# Store the output of the entire operation using command substitution.
# The curl output is piped to jq to get the authToken from the Json content.
# The jq output is piped to sed to remove the double quotes around the authToken.
authToken=$(curl http://localhost/arrigo/api/login \
-H "Cache-Control: no-cache" \
-H "Content-Type: application/json" \
-d '{
"username":"user",
"password":"password"
}' | jq '.authToken' | sed -e 's/^"//' -e 's/"$//')
Output
None, but the authToken
is stored in a variable.
Getting the root folder
# Use the authToken from the login request.
# The curl output is piped to jq to get the root folder name.
curl http://localhost/arrigo/api/graphql \
-H "Cache-Control: no-cache" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $authToken" \
-d '{
"query":"{folder {name}}"
}' | jq '.data.folder.name'
Output
"account"
Iterating sub-folders
# Use the authToken from the login request.
# The curl output is piped to jq to iterate over the sub-folders and getting their names.
curl http://localhost/arrigo/api/graphql \
-H "Cache-Control: no-cache" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $authToken" \
-d '{
"query":"{folder{name folders{edges{node{name}}}}}"
}' | jq '.data.folder.folders.edges[].node.name'