cURL

Guide and References for connectivity to Gitana

curl.svg

Connecting to Gitana

From a command prompt, the curl command can be used to execute API calls to Gitana. Connecting to the Gitana API requires API Keys from your Gitana project. This is done by default for the sample project. You can find these by going to Manage Project and clicking API Keys in the left hand menu.

Several examples of using curl are available in our Gitana SDK

For example, reading a node can be done with the following script which calls curl. First set the client key, client secret, username and password from your API keys. Set repository id, branch id and node id. The script needs curl and jq.

sh read-node.sh

The read-node.sh file looks like:

#!/bin/bash

BASE_URL=https://api.cloudcms.com

# plug in your API keys here
CLIENT_KEY=
CLIENT_SECRET=
USERNAME=
PASSWORD=

# plug in your node information here
REPOSITORY_ID=
BRANCH_ID=master
NODE_ID=

# sign in
TOKEN=$(curl -fsS -u "$CLIENT_KEY:$CLIENT_SECRET" \
  --data-urlencode "grant_type=password" \
  --data-urlencode "username=$USERNAME" \
  --data-urlencode "password=$PASSWORD" \
  "$BASE_URL/oauth/token" | jq -r '.access_token // empty')

# read the node
if [ -n "$TOKEN" ]; then
  curl -fsS -H "Authorization: Bearer $TOKEN" \
    "$BASE_URL/repositories/$REPOSITORY_ID/branches/$BRANCH_ID/nodes/$NODE_ID"
else
  echo "Sign-in failed. Check your four API keys and the API address." >&2
fi