Skip to content

Instantly share code, notes, and snippets.

@freyr
Created June 11, 2015 10:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save freyr/8df61744619728a7c8c9 to your computer and use it in GitHub Desktop.
Save freyr/8df61744619728a7c8c9 to your computer and use it in GitHub Desktop.
GetResponse APIv2 example
<?php
# Demonstrates how to add new contact to campaign.
# JSON::RPC module is required
# available at http://github.com/GetResponse/DevZone/blob/master/API/lib/jsonRPCClient.php
require_once 'jsonRPCClient.php';
# your API key is available at
# https://app.getresponse.com/my_api_key.html
$api_key = 'ENTER_YOUR_API_KEY_HERE';
# API 2.x URL
$api_url = 'http://api2.getresponse.com';
# initialize JSON-RPC client
$client = new jsonRPCClient($api_url);
# find campaign named 'test'
$campaigns = $client->get_campaigns(
$api_key,
array (
# find by name literally
'name' => array ( 'EQUALS' => 'test' )
)
);
# uncomment following line to preview Response
# print_r($campaigns);
# because there can be only one campaign of this name
# first key is the CAMPAIGN_ID required by next method
# (this ID is constant and should be cached for future use)
$CAMPAIGN_ID = array_pop(array_keys($campaigns));
# add contact to the campaign
$result = $client->add_contact(
$api_key,
array (
# identifier of 'test' campaign
'campaign' => $CAMPAIGN_ID,
# basic info
'name' => 'Test',
'email' => 'test@test.test',
# custom fields
'customs' => array(
array(
'name' => 'likes_to_drink',
'content' => 'tea'
),
array(
'name' => 'likes_to_eat',
'content' => 'steak'
)
)
)
);
# uncomment following line to preview Response
# print_r($result);
print("Contact added\n");
# Pawel Pabian http://implix.com
?>
@kfo2010
Copy link

kfo2010 commented Jun 15, 2016

You should change $api_url to https:// otherwise you are sending your api key across the web unencrypted.

@brunodegoyrans
Copy link

brunodegoyrans commented Nov 10, 2016

How $result can be tested?
What are the possible returned values? Can't find them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment