Skip to content

Instantly share code, notes, and snippets.

@velp
Created February 6, 2020 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save velp/2b4933e5c6532314f46cb6282bc2c7ec to your computer and use it in GitHub Desktop.
Save velp/2b4933e5c6532314f46cb6282bc2c7ec to your computer and use it in GitHub Desktop.
Curl examples for Jexia platform

Authenticate API

curl -X POST -d '{"method":"apk","key":"ff5b2d94-35f0-4696-92ca-cd2cf2f78bb3","secret":"..."}' "https://41724d4f-2d2f-4106-ab6c-075481c2f903.app.jexia.com/auth" | jq .access_token

Athenticate UMS

curl -X POST -d '{"method":"ums","email":"test@example.com","password":"qwerty"}' "https://41724d4f-2d2f-4106-ab6c-075481c2f903.app.jexia.com/auth" | jq .access_token

# save UMS token to env
export UMS_TOKEN=`curl -X POST -d '{"method":"ums","email":"test@example.com","password":"qwerty"}' "https://41724d4f-2d2f-4106-ab6c-075481c2f903.app.jexia.com/auth" | jq -r .access_token`

Select data

# Select all data
curl -H "Authorization: Bearer $UMS_TOKEN" -X GET "https://41724d4f-2d2f-4106-ab6c-075481c2f903.app.jexia.com/ds/posts" | jq .
[
  {
    "id": "15a9c335-fc2f-4524-90c3-f36f04cd5774",
    "created_at": "2020-02-06T09:00:12.003325Z",
    "updated_at": "2020-02-06T09:00:12.003325Z",
    "text": "First post",
    "author": "Jessica Davis",
    "views": 10
  },
  {
    "id": "2a51593d-e99f-4025-b20b-159e226fc47d",
    "created_at": "2020-02-06T09:00:51.619346Z",
    "updated_at": "2020-02-06T09:01:37.305811Z",
    "text": "Second post",
    "author": "Sophie Johnson",
    "views": 2
  },
  {
    "id": "9ab4b2da-7164-4bf0-8c5f-132adf99a45d",
    "created_at": "2020-02-06T08:37:41.036527Z",
    "updated_at": "2020-02-06T09:06:03.515227Z",
    "text": "Third post",
    "author": "John Doe",
    "views": 0
  }
]

# Select by id
curl -H "Authorization: Bearer $UMS_TOKEN" -X GET "https://41724d4f-2d2f-4106-ab6c-075481c2f903.app.jexia.com/ds/posts?cond=\[\{\"field\":\"id\"\},\"=\",\"2a51593d-e99f-4025-b20b-159e226fc47d\"\]" | jq .
[
  {
    "id": "2a51593d-e99f-4025-b20b-159e226fc47d",
    "created_at": "2020-02-06T09:00:51.619346Z",
    "updated_at": "2020-02-06T09:01:37.305811Z",
    "text": "Second post",
    "author": "Sophie Johnson",
    "views": 2
  }
]

Insert data

curl -H "Authorization: Bearer $UMS_TOKEN" -X POST -d '{"text":"New post","author":"Chloe Williams","views":0}' "https://41724d4f-2d2f-4106-ab6c-075481c2f903.app.jexia.com/ds/posts" | jq .
[
  {
    "id": "3005a8f8-b849-4525-b535-a0c765e1ef8e",
    "created_at": "2020-02-06T09:13:29.363196Z",
    "updated_at": "2020-02-06T09:13:29.363196Z",
    "text": "New post",
    "author": "Chloe Williams",
    "views": 0
  }
]

Update data

curl -H "Authorization: Bearer $UMS_TOKEN" -d '{"text":"New post","author":"Roy Ban","views":2}' -X PUT "https://41724d4f-2d2f-4106-ab6c-075481c2f903.app.jexia.com/ds/posts?cond=\[\{\"field\":\"id\"\},\"=\",\"3005a8f8-b849-4525-b535-a0c765e1ef8e\"\]" | jq .
[
  {
    "id": "3005a8f8-b849-4525-b535-a0c765e1ef8e",
    "created_at": "2020-02-06T09:13:29.363196Z",
    "updated_at": "2020-02-06T09:14:28.592648Z",
    "text": "New post",
    "author": "Roy Ban",
    "views": 2
  }
]

Delete data

curl -H "Authorization: Bearer $UMS_TOKEN" -X DELETE "https://41724d4f-2d2f-4106-ab6c-075481c2f903.app.jexia.com/ds/posts?cond=\[\{\"field\":\"id\"\},\"=\",\"3005a8f8-b849-4525-b535-a0c765e1ef8e\"\]" | jq .
[
  {
    "id": "3005a8f8-b849-4525-b535-a0c765e1ef8e",
    "created_at": "2020-02-06T09:13:29.363196Z",
    "updated_at": "2020-02-06T09:14:28.592648Z",
    "text": "New post",
    "author": "Roy Ban",
    "views": 2
  }
]

Complex filtering

# Select special fields
curl -H "Authorization: Bearer $UMS_TOKEN" -X GET "https://41724d4f-2d2f-4106-ab6c-075481c2f903.app.jexia.com/ds/posts?outputs=\[\"text\",\"author\"\]" | jq .
[
  {
    "text": "First post",
    "author": "Jessica Davis",
    "id": "15a9c335-fc2f-4524-90c3-f36f04cd5774"
  },
  {
    "text": "Second post",
    "author": "Sophie Johnson",
    "id": "2a51593d-e99f-4025-b20b-159e226fc47d"
  },
  {
    "text": "Third post",
    "author": "John Doe",
    "id": "9ab4b2da-7164-4bf0-8c5f-132adf99a45d"
  }
]

# Select special fields + where
curl -H "Authorization: Bearer $UMS_TOKEN" -X GET "https://41724d4f-2d2f-4106-ab6c-075481c2f903.app.jexia.com/ds/posts?outputs=\[\"text\",\"author\"\]&cond=\[\{\"field\":\"views\"\},\">\",3\]" | jq .
[
  {
    "text": "First post",
    "author": "Jessica Davis",
    "id": "15a9c335-fc2f-4524-90c3-f36f04cd5774"
  }
]

Sorting and limits

curl -H "Authorization: Bearer $UMS_TOKEN" -X GET "https://41724d4f-2d2f-4106-ab6c-075481c2f903.app.jexia.com/ds/posts?order=\{\"direction\":\"desc\",\"fields\":\[\"views\"\]\}&range=\{\"limit\":2,\"offset\":2\}" | jq .
[
  {
    "id": "9ab4b2da-7164-4bf0-8c5f-132adf99a45d",
    "created_at": "2020-02-06T08:37:41.036527Z",
    "updated_at": "2020-02-06T09:06:03.515227Z",
    "text": "Third post",
    "author": "John Doe",
    "views": 0
  }
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment