Merge anonymous lead with known lead with Marketo REST API - rest

I have anonymous leads in Marketo and I need to merge them with known leads through the REST API.
I am trying the code below
public function postData() {
$url = $this->host . "/rest/v1/leads/" . $this->id ."/merge.json?access_token=" . $this->getToken() . "&leadIds=" . $this::csvString($this->leadIds);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 120,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"content-type: application/json",
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
}
It is responding with {"requestId":"1af7#fgfdhgfdgfgdfg","success":false,"errors":[{"code":"1004","message":"Lead '231325' not found"}]} but I can see the lead with the id 231325 in Marketo.
How can I merge the anonymous lead with the known lead with REST?

Unfortunately, you cannot do that, or not in a straightforward way.
The description of the Merge functionality in the Docs does not states it as clearly as the Merge Endpoint reference, but it "merges two or more known lead records into a single lead record". So even if you see the MarketoIds of these visitors in the system, the API won't find them in the Leads table.
However, depending on your exact goal and setup, you might solve your issue by using the Associate Web Activity functionality, as it "associates a known Marketo lead record to a munchkin cookie and its associated web activity history". The Associate Endpoint expects the value of the _mkto_trk cookie of a visitor (sample format: id:287-GTJ-838%26token:_mch-marketo.com-1396310362214-46169).
Having said that, your curl would look something like this:
$url = $host . '/rest/v1/leads/' . $leadId . '/associate.json?cookie=' . $cookie . '&access_token=' . $token;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
]);
$response = curl_exec($curl);
curl_close($curl);
You can obtain the value of the cookie with $_COOKIE['_mkto_trk'].

Related

PayPal Sandbox MassPay: You do not have permissions to make this API call

I am trying send mass payment, for this I have used CURL, but I am getting the error response: You do not have permissions to make this API call,
My credentials are correct. Here is my full code:
$unsername = '****';
$password = '****';
$signature = '****';
$personal_email = '****#gmail.com';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api-3t.sandbox.paypal.com/nvp');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $unsername
. "&".$password
. "&".$signature
. "&METHOD=MassPay"
. "&VERSION=90"
. "&RECEIVERTYPE=EmailAddress"
. "&CURRENCYCODE=USD"
. "&L_EMAIL0=".$personal_email
. "&L_AMT0=35.95");
$headers = array();
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
$result = urldecode($result);
$data = parse_str($result,$responseArray);
$jsonResponse = $responseArray;
echo "<pre>";
print_r($jsonResponse);
die;
Response :
Array
(
[TIMESTAMP] => 2020-01-20T14:41:52Z
[CORRELATIONID] => f1f011edab2bd
[ACK] => Failure
[VERSION] => 90
[BUILD] => 54022052
[L_ERRORCODE0] => 10002
[L_SHORTMESSAGE0] => Authentication/Authorization Failed
[L_LONGMESSAGE0] => You do not have permissions to make this API call
[L_SEVERITYCODE0] => Error
)
You should not be using the old MassPay API for anything.
Instead, integrate Payouts: https://developer.paypal.com/docs/payouts/
For later use in live, there are prerequistics, which are the same for Payouts as for MassPay: https://developer.paypal.com/docs/payouts/integrate/prerequisites/
(if a live account has been enabled for MassPay it has been enabled for Payouts, and vice-versa, the business toggle is one and the same -- but must be requested and approved)
Go to developer.paypal.com .
You should have an application, "Default Application" or some other created name.
Select it and you can change the settings:
(I'm not 100% sure that the highlighted one is the right permission, I never used that functionality)
If you don't have access to the API settings, you should ask to who provided the API keys to you.

vCenter REST API - Deploy a template with network parameters

I am woking on a php tool to deploy ovf templates from the vCenter (vmWare) via CURL and JSON. The tool is already working and deploys an ovf template succesfully. My problem is that the network-parameters are getting ignored completly.
The massive informations in the vmWare documentary doesnt help me out. I think the solution is to find the right "key"-integer.
Here are some Dokus i used:
https://vcenter.iseage.org/apiexplorer/ -> ovfLibraryItem->deploy
vdc-repo
Also my google-searche was not realy helpful.
My currently json-code:
{
"deployment_spec": {
"accept_all_EULA": true,
"default_datastore_id": "datastore-30598",
"network_mappings": [
{
"key": "4000",
"value": "network-154"
}
],
"name": "AATest08"
},
"target": {
"folder_id": "group-v5920",
"host_id": "host-1934",
"resource_pool_id": "resgroup-43"
}}
I hope someone can help me out.
I didn't find any solution for this case. The workaround that i use now, is to change the network after deloying the VM. If someone is interest in the code to change the network of an existing VM in the vCenter with the REST API, i post the code below.
function updateNetwork($IdFromTheVM, $NewNetworkID)
{
$requestUrl = 'https://' . $yourVCenterHost . '/rest/vcenter/vm/' . $IdFromTheVM . '/hardware/ethernet/4000';
$data = array(
'spec' => array(
'backing' => array(
'type' => 'STANDARD_PORTGROUP',
'network' => $NewNetworkID,
)
));
$dataJson = json_encode($data);
$ch = curl_init();
$header = array(
'vmware-api-session-id: ' . $yourVCenterSessionID,
'content-Type: application/json',
'Accept: application/json'
);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataJson);
curl_setopt($ch, CURLOPT_URL, $requestUrl);
curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpcode != 200){
return false;
}
return true;
}

sugarcrm REST get_entry

Can someone take a look at how I've set up this REST call? I haven't been able to find an example of this, and I can't get it to work.
It may be the blank 'link_name_to_fields_array' parameter. I have read the documentation and don't really understand that parameter. I don't know if that is causing my problem or not.
Any help would be apprecitated.
//SET UP CURL
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
//parameters for get_entry call (I received a session id from a call to the login function. Using it here)
//I manually got this user 'id' form the sugarcrm database
$parameters = array(
'session'=>$result->id,
'module_name' => 'users',
'id' => '21a6a633-40de-9bf4-aa14-4f8753ea5aa2',
'select_fields' => array('user_name'),
'link_name_to_fields_array'=> array()
);
$json = json_encode($parameters);
$postArgs='method=get_entry&input_type=JSON&response_type=JSON$rest_data=' . $json;
curl_setopt($curl,CURLOPT_POSTFIELDS, $postArgs);
$result2 = curl_exec( $curl );
echo("<pre>" . print_r($result2,true) . "</pre>");
The output is "Bad data passed in; Return to Home"
You have an error in the postArgs line (replace $rest_data with &rest_data). Try with this:
$postArgs='method=get_entry&input_type=JSON&response_type=JSON&rest_data=' . $json;

How to submit form to a page on another server with some type of ajax?

I would like to submit my form to another page but making it not go to that page (like AJAX, but I know that AJAX does not work across domains)
Do you guys know how to do this? I don't like submitting it to the page on the other site because it is just really a slower and crappier way of doing things.
Thanks,
Nathan Johnson
Submit your form to a local page via AJAX. From that page you can post the data to the remote site with e.g. cURL.
Here's a very abstract example:
page_with_form.php
<form id="form1">
//input fields
</form>
<script>
$.post('post_to_remote.php', $('#form1').serialize(), function(){
//do something when finished
return false; //prevent from reloading
});
</script>
post_to_remote.php
$param1 = $_POST['param1'];
$param2 = $_POST['param2'];
$remoteUrl = 'http://www.remote_site.com/page_to_post_to.php';
$postFields = array('param1' => $param1, 'param2' => $param2);
//if you don't want to do any sanitizing, you can also simply do this:
//$postFields = $_POST;
$data_from_remote_page = $getUrl($remoteUrl, 'post', $postFileds);
function getUrl($url, $method='', $vars='') {
$ch = curl_init();
if ($method == 'post') {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt');
$buffer = curl_exec($ch);
curl_close($ch);
return $buffer;
}
If you do not need the full power of curl and it's really just a simple post, you can also use native PHP functions:
$postFields = http_build_query($_POST);
$remoteUrl = 'http://www.remote_site.com/page_to_post_to.php';
$context = stream_context_create(
array(
'http' => array(
'method' => 'POST',
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'content' => $postFields,
'timeout' => 10,
),
)
);
$result = file_get_contents($remoteURL, false, $context);
A vary basic example, but you get the idea.
You can try using JSONP:
http://davidwalsh.name/jsonp
http://api.jquery.com/jQuery.getJSON/#jsonp
It can be used cross-domain, but the data you send back from the server has to be something like (PHP):
echo $_GET['callback']."(".json_encode($data).")";
When I first used it I didn't echoed the callback function's name and it took me a couple of hours to see why it wasn't working.
Good luck!
Try jsonp in javascript:
$.ajax({
url: 'some_url' ,
data: $('#form_id').serialize(),
dataType: "jsonp",
jsonp : "callback",
jsonpCallback: "jsonpcallbask"
});
function jsonpcallbask(data) {
//handle response here
}

Facebook Graph API - Photo Upload

I have an application that uses the old Facebook API but now I'm migrating it. The application works good until I try to upload a photo.
I knew how to do it in the old way, but now... I'm in troubles.
This is the way I used to do it:
$args = array
(
'method' => 'photos.upload',
'v' => $ver,
'api_key' => $key,
'uid' => $uid,
'call_id' => $cid,
'format' => 'XML',
'caption' => $caption
);
signRequest($args, $sec);
$args[basename($file)] = '#' . realpath($file);
$ch = curl_init();
$url = 'http://api.facebook.com/restserver.php?method=photos.upload';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
$data = curl_exec($ch);
Any ideas??
Thanks
The API url starts with https:// not http://. That could be the issue.
I found the solution here:
Uploading a picture to facebook
There is shown how to use the new Facebook Graph API with the PHP Curl function and a valid session token.