Oct 19, 2015
0
Level 7
laravel to drupal node
I am sending a post json request to a $url = "http://......";
public function validate_node()
{
$node = $this->importer();
$url = "http://....................................................";
$content =$node;
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER,
array("Content-type: application/json"));
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 201 ) {
die("Error: call to URL $url failed with status $status, response $json_response");
}
curl_close($curl);
$response = json_decode($json_response, true);
dd($response);
}
which is in turn hitting this method on an import tool:
function importer_story() {
$story = json_decode($_POST["node"]);
//this won't be here
$story->nid = NULL;
$story->vid = NULL;
$story->author = array(13);
$story->taxonomy = $taxonomy_tids;
custom_domain_set_node_access($story, 2);
node_save($story);
var_dump($story);
return drupal_json(array('Need to put in some content to return' => true));
}
returning this as it var_dumps out
Error: call to URL http://................................................ failed with status 200, response object(stdClass)#46 (28) { ["author"]=> array(1) { [0]=> int(13) } ["taxonomy"]=> NULL ["book"]=> array(1) { ["mlid"]=> NULL } ["domains"]=> array(1) { [2]=> string(1) "2" } ["pathauto_perform_alias"]=> int(1) ["is_new"]=> bool(true) ["log"]=> string(0) "" ["teaser"]=> string(0) "" ["body"]=> string(0) "" ["created"]=> int(1445283209) ["changed"]=> int(1445283209) ["timestamp"]=> int(1445283209) ["format"]=> int(0) ["uid"]=> int(0) ["title"]=> string(0) "" ["vid"]=> string(7) "1291987" ["type"]=> string(0) "" ["language"]=> string(0) "" ["status"]=> int(1) ["comment"]=> int(0) ["promote"]=> int(0) ["moderate"]=> int(0) ["sticky"]=> int(0) ["tnid"]=> int(0) ["translate"]=> int(0) ["nid"]=> string(7) "1291938" ["path"]=> string(19) "2015-10-19/.html-12" ["domain_site"]=> string(1) "2" }
{"Need to put in some content to return":true}
I need to decode some of the data and print it out to test, and run some validation on it, but json_decode is not returning the data sent to the $url?
Please or to participate in this conversation.