Skip to content

Instantly share code, notes, and snippets.

@yvoronoy
Created May 11, 2017 16:13
Show Gist options
  • Save yvoronoy/a11cc36aba77455e7ea34bd123f1f93c to your computer and use it in GitHub Desktop.
Save yvoronoy/a11cc36aba77455e7ea34bd123f1f93c to your computer and use it in GitHub Desktop.
Magento2 API Examples
#!/bin/bash
# CREATE CATEGORY REST API
TOKEN=
BASE_URL=$1
echo $BASE_URL
TOKEN=$(curl -X POST "${BASE_URL}index.php/rest/V1/integration/admin/token" \
-H "Content-Type:application/json" \
-d '{"username":"admin", "password":"123123q"}')
TOKEN=$(echo $TOKEN | sed "s/\"//g");
echo TOKEN: ${TOKEN}
curl -X POST "${BASE_URL}index.php/rest/V1/categories" \
-H "authorization: Bearer ${TOKEN}" \
-H 'content-type: application/json' \
-d '{
"category":
{
"name": "New Arrival",
"parent_id":2,
"isActive": true,
"include_in_menu": true,
"custom_attributes": [
{"attribute_code": "url_key","value": "new-arrival"}
]
},
"saveOptions": true
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment