AnsweredAssumed Answered

Need help using API to fill target list

Question asked by Adam Adkins on May 8, 2018
Latest reply on May 9, 2018 by André Lopes

I'm trying to update a prospect list with a bunch of contacts. I'm struggling to get traction. Could anyone help and look over where I'm at? I do not appear to be getting any $record_response at the end. 

 

Any help/direction would be appreciated. André Lopes

 

<?php

$instance_url = 'test'
$username = 'test'
$password = 'test'

//Login - POST /oauth2/token
$url = $instance_url . "/oauth2/token";

$oauth2_token_arguments = array(
"grant_type" => "password",
//client id - default is sugar.
//It is recommended to create your own in Admin > OAuth Keys
"client_id" => "sugar",
"client_secret" => "",
"username" => $username,
"password" => $password,
//platform type - default is base.
//It is recommend to change the platform to a custom name such as "custom_api" to avoid authentication conflicts.
"platform" => "custom_api3"
);

$curl_request = curl_init($url);
curl_setopt($curl_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($curl_request, CURLOPT_HEADER, false);
curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_request, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($curl_request, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json"
));

//convert arguments to json
$json_arguments = json_encode($oauth2_token_arguments);
curl_setopt($curl_request, CURLOPT_POSTFIELDS, $json_arguments);

//execute request
$curl_response = curl_exec($curl_request);

//decode oauth2 response to get token
$oauth2_token_response_obj = json_decode($curl_response);
$oauth_token = $oauth2_token_response_obj->access_token;


$url = $instance_url . "/ProspectLists/c4cec6ce-520e-11e8-a3c5-000c29d75c29/link";


$record_arguments = array(
'link_name' => 'contacts',
'ids' => array("84ab6e6e-b842-7e8e-6d9b-57e2ae4fa094") //array of contact ids,
);

$record_response = call($url, $oauth_token, 'POST',$record_arguments);

echo "<pre>hello";print_r($record_response);exit;

?>

Outcomes