Skip to content

Instantly share code, notes, and snippets.

@simonmorley
Last active January 18, 2017 20:25
Show Gist options
  • Save simonmorley/6c7a02597019c1e6455b0106d4ec7e83 to your computer and use it in GitHub Desktop.
Save simonmorley/6c7a02597019c1e6455b0106d4ec7e83 to your computer and use it in GitHub Desktop.
Common API calls for the Cucumber WiFi API

Each request must be authorized with a bearer. Get this bearer by using the oauth flow explain elsewhere. Or, use the login API below. Set your token in your ENV:

T=my-secure-token

##Log a user in

curl -F grant_type=password \
-F username=simon@mail.com \
-F password=xxx -F brand_url=my-brand-id \
-X POST https://api.ctapp.io/oauth/token

#Projects

##List projects

curl "https://api.ctapp.io/api/v1/projects" \
-H "Authorization: Bearer $T" \
-H 'Content-Type: application/json; charset=UTF-8' \
-H 'Accept: application/json'

Response

{
	"projects": [{
		"id": 1,
		"brand_id": "5821eb75f4f67bf610137420",
		"user_id": 2654,
		"slug": "fbbfa34e-d6ce-49b4-a7ca-369f42849867",
		"project_name": "bottle-whether-6430",
		"type": "rw"
	}, {
		"id": 2,
		"brand_id": "570e610a4f0055fc7906722a",
		"user_id": 2654,
		"slug": "832ac065-ac4d-4531-949d-e0099f753853",
		"project_name": "conversations-pigeon-4568",
		"type": "rw"
	}],
	"_links": {
		"current_page": 1,
		"total_pages": 1,
		"next_page": 0,
		"total_entries": 2
	}
}

##Create a project

curl 'http://127.0.0.1:8080/api/v1/projects/' \
-H "Authorization: Bearer $T" \
-H 'Content-Type: application/json; charset=UTF-8' \
-H 'Accept: application/json' \
-d '{
    "project": {
        "project_name": "my fab project"
    }
}'

Response

{
	"id": 14,
	"brand_id": "5821eb75f4f67bf610137420",
	"user_id": 2654,
	"slug": "harmless-compliance-3020",
	"project_name": "harmless-compliance-3020"
}

##Create a project user

The project must belong to the user creating the project user. Obtain the slug from the API.

curl 'https://api.ctapp.io/api/v1/projects/fbbfa34e-d6ce-49b4-a7ca-369f42849867/project_users' \
-H "Authorization: Bearer $T" \
-H 'Content-Type: application/json; charset=UTF-8' \
-H 'Accept: application/json' \
-d '{
	"project_user": {
		"email": "someone-nice@email.com",
		"role_id": 110,
		"brand_id": "570e610a4f0055fc7906722a"
	}
}'

##List Project Users

curl 'http://127.0.0.1:8080/api/v1/projects/harmless-compliance-3020/project_users' \
-H "Authorization: Bearer $T" \
-H 'Content-Type: application/json; charset=UTF-8' \
-H 'Accept: application/json'

#Locations ##List locations

curl "https://api.ctapp.io/api/v1/locations"
-H "Authorization: Bearer $T"
-H 'Content-Type: application/json; charset=UTF-8'
-H 'Accept: application/json'

##Invite user to location

curl 'https://api.ctapp.io/api/v1/invites \
-H "Authorization: Bearer $T" \
-H 'Content-Type: application/json;charset=UTF-8' \
-H 'Accept: application/json' \
-d '{
	"location_id": "my-location-id",
	"invite": {
		"role_id": 110,
		"name": "simon",
		"email": "simon@email.com"
	}
}'

##Create location

curl 'https://api.ctapp.io/api/v1/locations' \
-H "Authorization: Bearer $T" \
-H 'Content-Type: application/json;charset=UTF-8' \
-H 'Accept: application/json' \
-d '{
	"location": {
		"location_name": "My Location",
		"location_address": "What a nice place",
		"town": "Nice Ville",
		"postcode": "NV123",
		"country": "UK",
		"brand_id": "570e610a4f0055fc7906722a"
	}
}'

##Create a location for a user

You can only create locations for users on the enterprise plans

curl 'https://api.ctapp.io/api/v1/locations' \
-H "Authorization: Bearer $T" \
-H 'Content-Type: application/json;charset=UTF-8' \
-H 'Accept: application/json' \
-d '{
	"location": {
		"location_name": "My Location",
		"location_address": "What an nice place",
		"town": "Nice Ville",
		"postcode": "NV123",
		"country": "UK",
		"brand_id": "570e610a4f0055fc7906722a",
		"user_id": "111"
	}
}'

#Users

##List users

curl "https://api.ctapp.io/api/v1/locations" \
-H "Authorization: Bearer $T" \
-H 'Content-Type: application/json; charset=UTF-8' \
-H 'Accept: application/json'

##Create a user

Only enterprise plans have permission to create.

curl -XPOST https://api.ctapp.io/api/v1/users \
-H "Content-Type: application/json" \
-H "Authorization: bearer $T" \
-d '{
	"user": {
		"username": "Jenny The Cat",
		"email": "newuser@me.com",
		"password": "my-pass-word123",
		"brand_id": "570e610a4f0055fc7906722a"
	}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment