mailtrain icon indicating copy to clipboard operation
mailtrain copied to clipboard

Add subscription with custom fields using API

Open reinhardfuehricht opened this issue 5 years ago • 3 comments

Hi!

I am trying to add subscriptions using PHP and CURL. I managed to fill email, first name and last name, but custom fields are not set.

Here are the things I tried. None of them works except email, FIRST_NAME, LAST_NAME.

$subscription = [
        'email' => $email,
        'FIRST_NAME' => $this->gp['first_name'],
        'LAST_NAME' => $this->gp['last_name'],
        //'REQUIRE_CONFIRMATION' => 1
];
$subscription['customHerrXtfmedw6'] = 1;
$subscription['custom_herr_xtfmedw6'] = 1;
$subscription['CUSTOM_HERR_XTFMEDW6'] = 1;
$subscription['custom_Herr_Xtfmedw6'] = 1;

$subscription['HerrXtfmedw6'] = 1;
$subscription['herr_xtfmedw6'] = 1;
$subscription['HERR_XTFMEDW6'] = 1;
$subscription['Herr_Xtfmedw6'] = 1;

$subscription['xtfmedw6'] = 1;
$subscription['XTFMEDW6'] = 1;
$subscription['Xtfmedw6'] = 1;

$subscription['merge_customHerrXtfmedw6'] = 1;
$subscription['merge_custom_herr_xtfmedw6'] = 1;
$subscription['MERGE_CUSTOM_HERR_XTFMEDW6'] = 1;
$subscription['merge_custom_Herr_Xtfmedw6'] = 1;

$subscription['merge_HerrXtfmedw6'] = 1;
$subscription['merge_herr_xtfmedw6'] = 1;
$subscription['MERGE_HERR_XTFMEDW6'] = 1;
$subscription['merge_Herr_Xtfmedw6'] = 1;

$subscription['merge_xtfmedw6'] = 1;
$subscription['MERGE_XTFMEDW6'] = 1;
$subscription['merge_Xtfmedw6'] = 1;

The customer creates the custom fields and I have no access to the administration interface. I only received an access token for using the API.

Can you please tell me how to do it?

Kind regards

reinhardfuehricht avatar Feb 07 '20 10:02 reinhardfuehricht

I have come across the same problem. It seems the API doesn't process first and lastname. I will check the code, if I can find out why. Without high hopes I still have to ask, Have you found a solution? ;)

l4b4r4b4b4 avatar Apr 17 '22 17:04 l4b4r4b4b4

I managed to get it done. Here is example code of the project:

$subscription = [
    'email' => '[email protected]',
    'FIRST_NAME' => 'John',
    'LAST_NAME' => 'Doe',
    'REQUIRE_CONFIRMATION' => 1
];

//For simple custom fields, use field name and value like this:
$subscription['myfield'] = 'myvalue';

//For dropdown fields, use field name and value as key and "1" as value like this:
$subscription['myfield_myvalue1'] = '1';

//Then send it:
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $subscribeUrl);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($subscription, JSON_HEX_QUOT | JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS));

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);

curl_close($ch);

Hope this helps you.

reinhardfuehricht avatar Apr 19 '22 11:04 reinhardfuehricht

thx, managed to get it done. Aparently the parameters were different than stated in the documentation.

l4b4r4b4b4 avatar Apr 19 '22 23:04 l4b4r4b4b4

We are going to start with the development and testing of mailtrain v3 in the next weeks.

You are welcome to help us with the testing as soon as the first release candidate is available.

forgeOneHQ avatar Mar 16 '24 09:03 forgeOneHQ