Create a new custom field


×
For API key Please contact with us at our SMTPprovider web chat

URL

To create a new custom field on a mailing list:

POST https://spsrvr/ga/api/v2/mailing_lists/:mailing_list_id/custom_fields

To create a new custom field that is global to the organization:

POST https://spsrvr/ga/api/v2/custom_fields

Request Parameters

Key Meaning Example
mailing_list_id The id of the mailing list for this custom field 17293

Request Payload

See the “Attributes” section above for an explanation of the custom field fields. The JSON object should be a child of the custom_field key.

Response

A successful response will return the custom field record as described below, in addition to the “Extra Parameters” listed above.

A failure will return a standard error response with an explanation of what went wrong.

Example

> POST /ga/api/v2/mailing_lists/1/custom_fields HTTP/1.1
> Authorization: Basic MTo1ZTk2NDY1Yzg4M2YzMzA5ZjAxMDVhMmUxMDc2NjMyYjY4N2U2MWQy
> User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5
> Host: greenarrow-studio.dev
> Accept: */*
{
   "custom_field":{
      "default_string":"",
      "field_type":"text",
      "instructions":"",
      "maximum_length":2,
      "minimum_length":1,
      "name":"text",
      "required":false
   }
}
< HTTP/1.1 200 OK
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate
< Pragma: no-cache
< Expires: Fri, 01 Jan 1990 00:00:00 GMT
< Content-Type: application/json; charset=utf-8
< X-UA-Compatible: IE=Edge
< Set-Cookie: _session_id=458055a23f26f844e74f8cd7300f6445; path=/; HttpOnly
< X-Request-Id: f6e40d578ed1d9c418cca45e1b7fe532
< X-Runtime: 0.025540
< Connection: close
{
   "success":true,
   "data":{
      "default_string":"",
      "field_type":"text",
      "id":3,
      "instructions":"",
      "mailing_list_id":1,
      "maximum_length":2,
      "minimum_length":1,
      "name":"text",
      "required":false
   }
}

PHP Example :

<?php

define('GAS_BASE_URL', 'http://localhost:3000/api');
define('GAS_API_KEY', '1:c9b20e681af084e1830b09933c6c851295ec0a75');

function greenarrow_studio_create_subscriber($params) {
  // Gather parameters needed to communicate with GA Studio.
  $listID   = $params['mailing_list_id'];
  $url      = GAS_BASE_URL.'/v2/mailing_lists/'.$listID.'/subscribers';
  $ch       = curl_init($url);
  $campaign = array('subscriber' => $params);
  $json     = json_encode($campaign);

  // Set up cURL to communicate this message.
  curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  curl_setopt($ch, CURLOPT_USERPWD, GAS_API_KEY);
  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Content-Length: ' . strlen($json),
  ));

  // Execute the command, retrieve HTTP errors.
  $response_raw = curl_exec($ch);
  $error_test   = curl_error($ch);
  $err          = curl_errno($ch);

  // Don't leave the connection hanging.
  curl_close($ch);

  // First, check if there was an HTTP error.
  if ($err != 0) {
    $rv = "ERROR: cURL - $err $error_test\n";
    return $rv;
  }

  // Decode Studio's response JSON.
  $result = json_decode($response_raw);

  // Return an appropriate response.
  if (isset($result->success)) {
    if ($result->success == false) {
      $return_value = "Error:";

      if (isset($result->error_message)) {
        $return_value .= " " . $result->error_message;
      }
    } else if ($result->success == true) {
      $return_value = "OK";
    } else {
      $return_value = "Error: unknown status";
    }
  } else {
    $return_value = "Error: unknown response from GAS Station: $response_raw";
  }

  return $return_value;
}

$params = array(
  'mailing_list_id' => 1,
  'email'           => 'subscriber-112@example.com',
  'status'          => 'active',
  'subscribe_time'  => '2013-03-27T10:14:13-05:00',
  'subscribe_ip'    => '10.0.81.8',
  'custom_fields' => array(
    'Name' => 'Bob Example'
  )
);

$result = greenarrow_studio_create_subscriber($params);
echo $result . "\n";