Import to a Segment by POST Request
Create a Static Segment using the API
Do Not Import Data into a Dynamic Segment
Dynamic Segment data is updated each day according to it's dynamic query rule definitions. Segment data added with an import will be lost.
Import actions on subscriptions will occur on the imported data, but the segment data will be lost on the Dynamic Segment.
Create a Personal API Key with a user that has segment permissions.
Add the API Key as a Bearer Authorization
token to the API request.
Create a Static Segment
Suppression Segments
is_suppression
must betrue
if specifying asuppression_type
Suppression Hash Options:
"none"
,"md5"
,"sha256"
,"sha512"
curl -v -X POST "https://{APP_DOMAIN}/api/3.2/messages/segments" \
-H "Authorization: Bearer $OPTIPUB_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"auto_responder_id": 22,
"description": "A Static Segment",
"is_suppression": false,
"name": "Test Static Segment",
"redirect_url": "https://docs.optipub.com",
"publication_id": 7,
"suppression_type": null,
"type": "static"
}'
curl -v -X POST "https://{APP_DOMAIN}/api/3.2/messages/segments" \
-H "Authorization: Bearer $OPTIPUB_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"description": "A Suppression Segment",
"is_suppression": true,
"name": "Test Suppression Segment",
"publication_id": 7,
"suppression_type": "md5",
"type": "static"
}'
Optional parameters:
auto_responder_id
,redirect_url
API Response
A success response will return a
201
status and valid JSON data.A failure response will not contain valid JSON, and will return a
302
redirect.
Retrieve the Segment ID
from the response data to use in the segment import API request.
{
"error": false,
"data": {
"id": 100789,
"name": "Test Static Segment",
"description": "A Static Segment"
},
"message": "Created segment."
}
Add Subscription Data to a CSV
Double Quotes and Spaces
Remove all spaces and characters outside of double quotes in fields that have double quotes.
README
- Headers are required if importing variable columns with email.
- Use Variable
Names
prefixed byvarr_
for variable columns (e.g.,varr_firstname
)
email,varr_firstname,varr_lastname
john.doe@example.com, John, Doe
jane.doe@example.com, Jane, Doe
jake.doe@example.com, Jake, Doe
email,tag-add,tag-remove
john.doe@example.com,New Tag,Old Tag
jane.doe@example.com,New Tag,Old Tag
jake.doe@example.com,New Tag,Old Tag
email,subscriber-tag-add,subscriber-tag-remove
john.doe@example.com,"New Tag 1,New Tag 2,New Tag 3","Old Tag 1,Old Tag 2"
jane.doe@example.com,"New Tag 1,New Tag 2,New Tag 3","Old Tag,Old Tag 2"
jake.doe@example.com,"New Tag 1,New Tag 2,New Tag 3","Old Tag,Old Tag 2"
email,tag-replace
john.doe@example.com,Only This Tag
jane.doe@example.com,Only This Tag
jake.doe@example.com,Only This Tag
Working with Subscription Tags and Subscriber Tags
Subscription Tags Headers
-tag-add
,tag-remove
,tag-replace
Subscriber Tag Headers
-subscriber-tag-add
,subscriber-tag-remove
,subscriber-tag-replace
Each header can only be used for one column in the CSV file.
Using these headers in your CSV will effect the subscription and subscriber tags of the email address instead of variables.
All actions will create any Tags that don't exist, even the remove action.
Multiple Tags
It is possible to add, remove or replace multiple tags for each email address.
- Put all tags for the action in the same field.
- Surround the combined tags with double quotes.
- Separate the tags with commas.
- Be sure to remove any spaces outside of the double quotes in the field.
(e.g., john.doe@example.com,"New Tag 1, New Tag 2", John
)
Replacing Tags
Using tag-replace
or subscriber-tag-replace
will remove all current tags attached to the subscription or subscriber and only the imported tags will remain.
Import Subscription Data to a Segment
README
- POSTing as content-type
multipart/form-data
is required to upload the file correctly.clear
- use integer values (1
) true or (0
) falseactiveStatus
- use integer values (1
) 'Active', (0
) 'Inactive' or (null
) 'Lead'
curl -v -X POST "https://{APP_DOMAIN}/api/3.2/messages/segments/{segment_id}/import" \
-H "Authorization: Bearer $OPTIPUB_API_KEY" \
-H "Content-Type: multipart/form-data" \
-F "file=@import.csv;type=text/csv" \
-F "clear=0" \
-F "activeStatus=1" \
-F "sourceCampaign=90" \
-F "sourcePartner=9"
curl -v -X POST "https://{APP_DOMAIN}/api/3.2/messages/segments/{segment_id}/import" \
-H "Authorization: Bearer $OPTIPUB_API_KEY" \
-H "Content-Type: multipart/form-data" \
-F "file=@import.csv;type=text/csv" \
-F "clear=0" \
-F "activeStatus=0"
curl -v -X POST "https://{APP_DOMAIN}/api/3.2/messages/segments/{segment_id}/import" \
-H "Authorization: Bearer $OPTIPUB_API_KEY" \
-H "Content-Type: multipart/form-data" \
-F "file=@import.csv;type=text/csv" \
-F "clear=0" \
-F "activeStatus=null"
curl -v -X POST "https://{APP_DOMAIN}/api/3.2/messages/segments/{segment_id}/import" \
-H "Authorization: Bearer $OPTIPUB_API_KEY" \
-H "Content-Type: multipart/form-data" \
-F "file=@import.csv;type=text/csv" \
-F "clear=0"
Import Options
Static segment imports effect subscriptions for the publication configured for the segment.
Clear
segment will remove all data from the segment before importing the new data. But it does not effect subscription or subscriber data removed from the segment.
Import and Subscribe
Subscribe
"activeStatus=1"
Import and Unsubscribe
Unsubscribe
"activeStatus=0"
sourceCampaign
andsourcePartner
are not needed to unsubscribe.
Import as Lead
Lead
- (optional)
"activeStatus=null"
or omit sourceCampaign
andsourcePartner
are not needed to create leads.
Import as Suppression
List
Suppression
List- Do not include
activeStatus
,sourceCampaign
orsourcePartner
fields when importing to a suppression segment. - Import data using the
Hash Type
of the segment for the email address
API Response
A success response will return a
201
status and valid JSON data.A failure response will not contain valid JSON, and will return a
302
redirect.
{
"error": false,
"data": [],
"message": "Import created."
}
Updated 12 days ago