Campaign Monitor Authenticate an Element Instance

You can authenticate with Campaign Monitor to create your own instance of the Campaign Monitor element through the UI or through APIs. Once authenticated, you can use the element instance to access the different functionality offered by the Campaign Monitor platform. 

Campaign monitor supports both Basic and OAuth 2.0 authentication.

Basic Authentication

Authenticate Through the UI Using Basic Authentication

Use the UI to authenticate with Campaign Monitor and create an element instance as described in Authenticate an Element Instance (UI). In addition to the base authentication parameters, you will need the credentials that you identified in API Provider Setup.

After successfully authenticating, we give you several options for next steps. Make requests using the API docs associated with the instance, map the instance to a virtual data resource, or use it in a formula template.

Authenticate Through API Using Basic Authentication

Send a request to our /instances endpoint to authenticate an element instance. When finished note the token and id.

To authenticate an element instance:

  1. Construct a JSON body as shown below (see Basic Parameters):

    {
      "element": {
        "key": "campaignmonitor"
      },
      "configuration": {
        "username": "<campaignmonitor API key>",
        "company.name": "<campaignmonitor Domain>"
      },
      "tags": [
        "<Add_Your_Tag>"
      ],
      "name": "<INSTANCE_NAME>"
    }
  2. Call the following, including the JSON body you constructed in the previous step:

    POST /instances
    Note: Make sure that you include the User and Organization keys in the header. For more information, see Authorization Headers, Organization Secret, and User Secret.
  3. Locate the token and id in the response and save them for all future requests using the element instance.

Example cURL

curl -X POST \
  https://api.cloud-elements.com/elements/api-v2/instances \
  -H 'authorization: User <USER_SECRET>, Organization <ORGANIZATION_SECRET>' \
  -H 'content-type: application/json' \
  -d '{
  "element": {
    "key": "campaignmonitor"
  },
  "configuration": {
    "username": "xxxxxxxxxxxxxxxxxx",
    "company.name": "Acme"
  },
  "tags": [
    "Docs"
  ],
  "name": "API Instance"
}'

Basic Parameters

API parameters not shown in Cloud Elements 2.0 are in code formatting.

Note: Event related parameters are described in Events.
ParameterDescriptionData Type
keyThe element key.string
Name
name
The name of the element instance created during authentication.string
API Key
username
The API key assigned to the user that you noted in API Provider Setup.string
Company Name
company.name
The Domain Name. The Domain Name appears in the url of your account. For example, in https://company_name.campaignmonitor.com/ the Domain Name is company_name.string
tagsOptional. User-defined tags to further identify the instance.string

Example Response for an Authenticated Element Instance

In this example, the instance ID is 12345 and the instance token starts with "ABC/D...". The actual values returned to you will be unique: make sure you save them for future requests to this new instance.

{
  "id":12345,
  "name":"API Instance",
  "createdDate":"2018-05-25T15:56:22Z",
  "token":"ABC/Dxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=",
  "element":{
    "id":6315,
    "name":"Campaign Monitor",
    "hookName":"CampaignMonitor",
    "key":"campaignmonitor",
    "description":"The API can be used to manipulate employee data and to generate reports in several formats.",
    "image":"elements/custom-element-default-logo.png",
    "active":false,
    "deleted":false,
    "typeOauth":false,
    "trialAccount":false,
    "resources":[  ],
    "transformationsEnabled":true,
    "bulkDownloadEnabled":true,
    "bulkUploadEnabled":true,
    "cloneable":true,
    "extendable":true,
    "beta":false,
    "authentication":{
      "type":"basic"
    },
    "extended":false,
    "useModelsForMetadata":true,
    "hub":"humancapital",
    "protocolType":"http",
    "parameters":[  ],
    "private":false
  },
  "elementId":6315,
  "tags":[
    "Docs"
  ],
  "provisionInteractions":[

  ],
  "valid":true,
  "disabled":false,
  "maxCacheSize":0,
  "cacheTimeToLive":0,
  "configuration":{  },
  "eventsEnabled":false,
  "traceLoggingEnabled":false,
  "cachingEnabled":false,
  "externalAuthentication":"none",
  "user":{
    "id":123456,
    "emailAddress":"claude.elements@cloud-elements.com",
    "firstName":"Claude",
    "lastName":"Elements"
  }
}

OAuth 2.0 Authentication

Authenticate Through the UI Using OAuth 2.0

Use the UI to authenticate with Campaign Monitor and create an element instance. Because you authenticate with Campaign Monitor via OAuth 2.0, all you need to do is add a name for the instance. After you create the instance, you'll log in to Campaign Monitor to authorize Cloud Elements access to your account. For more information about authenticating an element instance, see Authenticate an Element Instance (UI)

After successfully authenticating, we give you several options for next steps. Make requests using the API docs associated with the instance, map the instance to a VDR, or use it in a formula template.

Authenticate Through API Using OAuth 2.0

Authenticating with OAuth 2.0 through API is a multi-step process that involves:

Getting a Redirect URL

Use the following API call to request a redirect URL where the user can authenticate with the API provider. Replace {keyOrId} with the element key, campaignmonitor.

curl -X GET /elements/api-v2/{keyOrId}/oauth/url?apiKey=<api_key>&apiSecret=<api_secret>&callbackUrl=<url>&siteAddress=<url>

Query Parameters

Query ParameterDescription
apiKeyThe key obtained from registering your app with the provider. This is the Client ID that you recorded in API Provider Setup.
apiSecretThe secret obtained from registering your app with the provider. This is the Client Secret that you recorded in API Provider Setup.
callbackUrlThe URL that will receive the code from the vendor to be used to create an element instance.

Example cURL

'https://api.cloud-elements.com/elements/api-v2/elements/campaignmonitor/oauth/url?apiKey=fake_api_key&apiSecret=fake_api_secret&callbackUrl=https://www.mycoolapp.com/auth&state=campaignmonitor' \

Example Response

Use the oauthUrl in the response to allow users to authenticate with the vendor.

{
    "oauthUrl": "https://api.createsend.com/oauth?scope=ViewReports%2CManageLists%2CCreateCampaigns%2CImportSubscribers%2CSendCampaigns%2CViewSubscribersInReports%2CManageTemplates%2CAdministerPersons%2CAdministerAccount%2CViewTransactional%2CSendTransactional&response_type=code&redirect_uri=https%3A%2F%2Fhttpbin.org%2Fget&state=campaignmonitor&client_id=123456",
    "element": "campaignmonitor"
}

Authenticating Users and Receiving the Authorization Grant Code

Provide the response from the previous step to the users. After they authenticate, Campaign Monitor provides the following information in the response:

  • code
  • state
Response ParameterDescription
codeThe Authorization Grant Code required by Cloud Elements to retrieve the OAuth access and refresh tokens from the endpoint.
stateA customizable identifier, typically the element key (campaignmonitor) .
Note: If the user denies authentication and/or authorization, there will be a query string parameter called error instead of the code parameter. In this case, your application can handle the error gracefully.

Authenticating the Element Instance

Use the /instances endpoint to authenticate with Campaign Monitor and create an element instance. If you are configuring events, see the Events section.

Note: The endpoint returns an element instance token and id upon successful completion. Retain the token and id for all subsequent requests involving this element instance.

To create an element instance:

  1. Construct a JSON body as shown below (see OAuth 2.0 Parameters):

    {
      "element": {
        "key": "campaignmonitor"
      },
      "providerData": {
        "code": "<AUTHORIZATION_GRANT_CODE>"
      },
      "configuration": {
        "authentication.type": "oauth2",
        "oauth.callback.url": "<CALLBACK_URL>",
        "oauth.api.key": "<CONSUMER_KEY>",
        "oauth.api.secret": "<CONSUMER_SECRET>",
        "filter.response.nulls": true
      },
      "tags": [
        "<Add_Your_Tag>"
      ],
      "name": "<INSTANCE_NAME>"
    }
    
  2. Call the following, including the JSON body you constructed in the previous step:

    POST /instances
    
    Note: Make sure that you include the User and Organization keys in the header. For more information, see Authorization Headers, Organization Secret, and User Secret.
  3. Locate the token and id in the response and save them for all future requests using the element instance.

Example cURL

curl -X POST \
  https://api.cloud-elements.com/elements/api-v2/instances \
  -H 'authorization: User <USER_SECRET>, Organization <ORGANIZATION_SECRET>' \
  -H 'content-type: application/json' \
  -d '{
  "element": {
    "key": "campaignmonitor"
  },
  "providerData": {
    "code": "xoz8AFqScK2ngM04kSSM"
  },
  "configuration": {
    "authentication.type": "oauth2",
    "oauth.callback.url": "<CALLBACK_URL>",
    "oauth.api.key": "<CONSUMER_KEY>",
    "oauth.api.secret": "<CONSUMER_SECRET>"
  },
  "tags": [
    "For Docs"
  ],
  "name": "API Instance"
}'

OAuth 2.0 Parameters

API parameters not shown in the Cloud Elements are in code formatting.

Note: Event related parameters are described in Events.
ParameterDescriptionData Type
'key'The element key.
campaignmonitor
string
Name
name
The name for the element instance created during authentication.Body
Authentication Type
authentication.type
How you want to authenticate with the API provider, either OAuth2 or Basic.string
API Key
username
Basic Authentication only. The Campaign Monitor API Key.
oauth.callback.urlOAuth 2.0 Authentication only. The URL where you want to redirect users after they grant access. This is the Callback URL that you noted in in API Provider Setup.
OAuth API Key
oauth.api.key
OAuth 2.0 Authentication only. The Client ID from Campaign Monitor. This is the Client ID that you noted in API Provider Setup.string
OAuth API Secret
oauth.api.secret
OAuth 2.0 Authentication only. The Client Secret from Campaign Monitor. This is the Client Secret that you noted in API Provider Setup.string
tagsOptional. User-defined tags to further identify the instance.string

Example Response for an Authenticated Element Instance

{
  "id": 123,
  "name": "test",
  "token": "3sU/S/kZD36BaABPS7EAuSGHF+1wsthT+mvoukiE",
  "element": {
      "id": 39,
      "name": "Campaign Monitor",
      "key": "campaignmonitor",
      "description": "Campaign Monitor makes it easy for you to create, send, and optimize your email marketing campaigns.",
      "image": "https://www.campaignmonitor.com/assets/brand/campaignmonitor.jpg",
      "active": true,
      "deleted": false,
      "typeOauth": false,
      "trialAccount": false,
      "resources": [ ],
      "transformationsEnabled": true,
      "bulkDownloadEnabled": true,
      "bulkUploadEnabled": true,
      "cloneable": true,
      "extendable": false,
      "beta": true,
      "authentication": {
          "type": "oauth2"
      },
      "elementId": 3928,
      "provisionInteractions": [],
      "valid": true,
      "disabled": false,
      "maxCacheSize": 0,
      "cacheTimeToLive": 0,
      "configuration": {    },
      "eventsEnabled": false,
      "eventsNotificationCallbackUrl": "false",
      "traceLoggingEnabled": false,
      "cachingEnabled": false,
      "externalAuthentication": "none",
      "user": {
          "id": 12345
        }
    }
 }