Skip to content

Examples of how to fetch a guideline with our API in various languages

Below you get two examples of how to fetch a guideline using our API

We use the example username: apitest@magicapp.org , and password: apitest

 PHP

<?php

// you'll need to use your own credentials 
$username = "apitest@magicapp.org";
$password = "apitest";
$base_url = "https://api.magicapp.org/";
$base_api_url = $base_url."api/v1/";
$auth_url = $base_url."/auth/login";

// get auth token

$auth_post = "email=".urlencode($username)."&password=".urlencode($password);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $auth_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 2);
curl_setopt($ch, CURLOPT_POSTFIELDS, $auth_post);

$result = curl_exec($ch);
if (curl_errno($ch)) print curl_error($ch);

$json = json_decode($result, true);
$auth_token = $json['token'];

print("auth token: ". $auth_token ."\n"); 


// get data !

$auth_header = array_merge($auth_header, array("Bearer: ". $auth_token));

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $base_api_url."/guidelines/2");
curl_setopt($ch, CURLOPT_HTTPHEADER, $auth_header);
curl_setopt($ch, CURLOPT_REFERER, $auth_url);
    
$result = curl_exec($ch);
var_dump(json_decode($result, true));
    
curl_close($ch);
?>


Python

import requests
import json

# you'll need to use your own credential  
auth = { 'email': 'apitest@magicapp.org', 'password': 'apitest' }
url = 'https://api-test.magicapp.org/auth/login'

r = requests.post(url, data=auth)

authToken = r.json()['token']
headers = { 'Authorization': f'Bearer {authToken}' }

r = requests.get('https://api.magicapp.org/api/v1/guidelines/2', headers=headers)

Feedback and Knowledge Base