One of our startups at MS Ventures was looking to use the command line to manage their Azure account on Mac. If you prefer using Mac OS X Terminal or iTerm and have an Azure account then you should check out the Azure CLI tools for Mac.
You can either download the Azure Command Line tools installer for Mac or install the Azure command line tools using nodejs. I have previously written a post covering installing nodejs using NVM.
npm install -g azure-cli@0.8.17
Test Azure command works with help:
azure -h
Sign in to your Azure account and download your *.publishsettings subscription file.
Import path to downloaded Azure Publish Settings file:
azure account import <file.publishsettings>
Tip: You can drag & drop the file into Terminal instead of typing the link.
Show Azure account subscriptions:
azure account list
azure mobile create TerminalTest --push "nh"
You will be prompted to enter SQL admin user name and password. The Mobile Service should only take a couple of minutes to provision.
azure mobile show TerminalTest
You will want to make a note of your applicationUrl and applicationKey for CRUD examples below.
azure mobile table create TerminalTest Items
azure mobile table list TerminalTest
azure mobile data read TerminalTest Items
You can quickly execute Create, Read, Update and Delete operations with Mobile Services using curl
commands. Here’s a quick overview of Mobile Service CRUD operations and methods:
Operation | Method | REST URL format |
---|---|---|
Create / Insert | POST | https://<service_name>.azure-mobile.net/tables/<table_name> |
Read / Query | GET | https://<service_name>.azure-mobile.net/tables/<table_name> |
Update | PATCH | https://<service_name>.azure-mobile.net/tables/<table_name>/<item_id> |
Delete | DELETE | https://<service_name>.azure-mobile.net/tables/<table_name>/<item_id> |
You will need to replace the X-ZUMO-APPLICATION
header value below with your own Mobile Service applicationKey.
curl --request POST \
--header 'X-ZUMO-APPLICATION: RLKPKSRTzFUFgXqVLRPkUTOKorqRQV65' \
--header 'Content-Type: application/json; charset=UTF-8' \
--data '{"text":"hello mac","complete":false}' \
--location 'https://terminaltest.azure-mobile.net/tables/Items'
Change the data text
to submit a couple of items… Note you will get a JSON response with the id
of the inserted item. This item id value is to be used in the Update and Delete examples below.
curl --request GET \
--header 'X-ZUMO-APPLICATION: RLKPKSRTzFUFgXqVLRPkUTOKorqRQV65' \
--header 'Content-Type: application/json; charset=UTF-8' \
--location 'https://terminaltest.azure-mobile.net/tables/Items'
curl --request PATCH \
--header 'X-ZUMO-APPLICATION: RLKPKSRTzFUFgXqVLRPkUTOKorqRQV65' \
--header 'Content-Type: application/json; charset=UTF-8' \
--data '{"complete":true}' \
--location 'https://terminaltest.azure-mobile.net/tables/Items/C9CCC7F7-4F16-4F63-8ACD-BD2DCC32F4CC'
curl --request DELETE \
--header 'X-ZUMO-APPLICATION: RLKPKSRTzFUFgXqVLRPkUTOKorqRQV65' \
--header 'Content-Type: application/json; charset=UTF-8' \
--location 'https://terminaltest.azure-mobile.net/tables/Items/C9CCC7F7-4F16-4F63-8ACD-BD2DCC32F4CC'
More documentation on Azure xplat-cli
Get items marked as complete
curl --request GET \
--header 'X-ZUMO-APPLICATION: RLKPKSRTzFUFgXqVLRPkUTOKorqRQV65' \
--header 'Content-Type: application/json; charset=UTF-8' \
--location "https://terminaltest.azure-mobile.net/tables/Items?\$filter=(complete%20eq%20true)"
Get items starting with text ‘hello’ with total count of results:
curl --request GET \
--header 'X-ZUMO-APPLICATION: RLKPKSRTzFUFgXqVLRPkUTOKorqRQV65' \
--header 'Content-Type: application/json; charset=UTF-8' \
--location "https://terminaltest.azure-mobile.net/tables/Items?\$filter=(startswith(text,'hello'))&\$inlinecount=allpages"
Get a collection of items in order (eg. pagination):
curl --request GET \
--header 'X-ZUMO-APPLICATION: RLKPKSRTzFUFgXqVLRPkUTOKorqRQV65' \
--header 'Content-Type: application/json; charset=UTF-8' \
--location "https://terminaltest.azure-mobile.net/tables/Items?\$orderby=text%20desc&\$skip=1&\$top=1"
NB: Just be aware if you use double quotes for --location
then you must escape the dollar signs that prefix the params with a backslash (eg. \$
). Single quotes don’t require dollar escaping but you may have trouble encapsulating filters with quoted strings hence I have opted for double quotes in these query examples.