Skip to content

Instantly share code, notes, and snippets.

@gnh1201
Created November 26, 2018 11:29
Show Gist options
  • Save gnh1201/c3ec1a7eec66cf33fba60e9e17395af6 to your computer and use it in GitHub Desktop.
Save gnh1201/c3ec1a7eec66cf33fba60e9e17395af6 to your computer and use it in GitHub Desktop.
Directus 7 with ReasonableFramework: Get token and Data migration
<?php
// (How to) Get DIrectus 7 CMS token by ReasonableFramework
// step by step
// 1. git clone https://github.com/gnh1201/reasonableframework
// 2. edit /storage/config/database.ini (if you want data migrate to directus)
// 3. fill your email address and password into this example
// 4. copy edited example to /route directory
// 5. connect to http://[your-web-url]/?route=migrate
loadHelper("webpagetool");
// Authenticate
$url = "https://directus.local/api/_/auth/authenticate";
$response = get_web_json($url, "jsondata", array(
"email" => "[email protected]",
"password" => "password"
));
$token = $response->data->token;
echo "token: " . $token . "<br>";
// create item
$url = "https://directus.local/api/_/items/testcollection";
$response = get_web_json($url, "jsondata", array(
"headers" => array(
"Authorization" => "Bearer " . $token
),
"data" => array(
"name" => "hello",
"category" => "world"
)
));
var_dump($response);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment