<?php
function immomig_query($query) {
$url = 'https://api.myimmomig.com/graphql/v1';
$username = 'aaaa-bbbb-cccc-dddd';
$password = 'asdf1234';
$post = '{"query":"'.trim(preg_replace('!\s+!',' ',str_replace(array("\n","\r","\t",'"'),array(' ',' ',' ','\"'),$query))).'"}';
$headers = array();
$headers[] = 'Content-Type: application/json';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
/**/echo '<h2>immomig_query()</h2>';
/**/echo '<pre>'.$post.'</pre>';
/**/echo '<pre>'.$status_code.'</pre>';
/**/echo '<pre>'; print_r(json_decode($result,true)); echo '</pre>';
return json_decode($result,true);
}
$query = 'query {
objects(first: 5, offset: 0, room_min: 4, room_max: 6) {
totalCount,
list {
id,
reference,
}
}
}';
immomig_query($query);
$query = 'query {
object(id: 131232) {
id,
reference,
date_creation,
date_lastedit,
category {
ident,
text { fr, de, it, en }
},
subcategory {
ident,
text { fr, de, it, en }
},
online,
images {
id,
online,
url,
description {fr de it en}
},
files {
id,
url,
},
descriptions {
title {fr de it en},
main{fr de it en}
},
distances {
train_station {meters}
public_transports{meters}
},
surfaces {
living {
is_approximate,
is_lower_bound,
value
},
living_total {
is_approximate,
is_lower_bound,
value
},
usable {
is_approximate,
is_lower_bound,
value
},
land {
is_approximate,
is_lower_bound,
value
},
}
contact {
agency {
id,
name,
references,
address,
zip,
city,
country,
phone,
mobile,
fax,
email
},
visit {
... on VisitContactPerson {
gender { ident },
firstname,
lastname,
phone,
mobile,
fax,
email,
remark,
picture_url
}
... on VisitContactDepartment {
type { ident },
address,
zip,
city,
phone,
fax,
email
}
}
},
types {ident text{fr de it en}}
situation {
lat,
lng,
address,
address_substitution,
zip,
city,
state,
country,
}
}
}';
immomig_query($query);
/**/die('END');
Comments