view_content
This endpoint creates a view content conversion event and posts it to Snap
/api/conversionapi/viewcontent
Usage Samples
curl -X POST -H "Authorization: [[apiKey]]" "https://snapchat.dmscg.com/api/conversionapi/viewcontent"
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("text/plain");
RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM)
.addFormDataPart("email_address","[email protected]")
.addFormDataPart("event_type","VIEW_CONTENT")
.addFormDataPart("event_conversion_type","web")
.addFormDataPart("event_tag","in-stock")
.addFormDataPart("item_category","bikes")
.addFormDataPart("price","43")
.addFormDataPart("number_items","1")
.addFormDataPart("currency","usd")
.addFormDataPart("item_ids","sam001")
.build();
Request request = new Request.Builder()
.url("https:://snapchat.dmscg.com/api/conversionapi/view_content")
.method("POST", body)
.addHeader("Authorization", "Bearer [[apikey]]")
.build();
Response response = client.newCall(request).execute();
public classDefaultApiExample {
public static void main(String[] args) {
DefaultApi apiInstance = new DefaultApi();
ViewContent viewContent = ; // ViewContent | Event data to add
try {
apiInstance.apiConversionapiViewcontentPost(viewContent);
} catch (ApiException e) {
System.err.println("Exception when calling DefaultApi#apiConversionapiViewcontentPost");
e.printStackTrace();
}
}
}
#import <Foundation/Foundation.h>
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://snapchat.dmscg.com/api/conversionapi/view_content"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:10.0];
NSDictionary *headers = @{
@"Authorization": @"Bearer [[apiKey]]"
};
[request setAllHTTPHeaderFields:headers];
NSArray *parameters = @[
@{ @"name": @"email_address", @"value": @"[email protected]" },
@{ @"name": @"timestamp", @"value": @"Thu, 24 Mar 2022 09:00:02" },
@{ @"name": @"event_type", @"value": @"VIEW_CONTENT" },
@{ @"name": @"event_conversion_type", @"value": @"web" },
@{ @"name": @"event_tag", @"value": @"in-stock" },
@{ @"name": @"item_category", @"value": @"bikes" },
@{ @"name": @"price", @"value": @"43" },
@{ @"name": @"number_items", @"value": @"1" },
@{ @"name": @"currency", @"value": @"usd" },
@{ @"name": @"item_ids", @"value": @"sam001" }
];
NSString *boundary = @"----WebKitFormBoundary7MA4YWxkTrZu0gW";
NSError *error;
NSMutableString *body = [NSMutableString string];
for (NSDictionary *param in parameters) {
[body appendFormat:@"--%@\r\n", boundary];
[body appendFormat:@"Content-Disposition:form-data; name=\"%@\"\r\n\r\n", param[@"name"]];
[body appendFormat:@"%@", param[@"value"]];
}
[body appendFormat:@"\r\n--%@--\r\n", boundary];
NSData *postData = [body dataUsingEncoding:NSUTF8StringEncoding];
[request setHTTPBody:postData];
[request setHTTPMethod:@"POST"];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error) {
NSLog(@"%@", error);
dispatch_semaphore_signal(sema);
} else {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
NSError *parseError = nil;
NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:&parseError];
NSLog(@"%@",responseDictionary);
dispatch_semaphore_signal(sema);
}
}];
[dataTask resume];
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
var form = new FormData();
form.append("email_address", "[email protected]");
form.append("timestamp", "Thu, 24 Mar 2022 09:00:02");
form.append("event_type", "VIEW_CONTENT");
form.append("event_conversion_type", "web");
form.append("event_tag", "in-stock");
form.append("price", "43");
form.append("currency", "usd");
form.append("item_category", "bikes");
form.append("item_ids", "sam001");
var settings = {
"url": "https://snapchat.dmscg.com/conversionapi/view_content",
"method": "POST",
"timeout": 0,
"headers": {
"Authorization": "Bearer [[apikey]]"
},
"processData": false,
"mimeType": "multipart/form-data",
"contentType": false,
"data": form
};
$.ajax(settings).done(function (response) {
console.log(response);
});
var client = new RestClient("https://snapchat.dmscg.com/api/conversionapi/view_content");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer [[apikey]]");
request.AlwaysMultipartFormData = true;
request.AddParameter("email_address", "[email protected]");
request.AddParameter("price", "43");
request.AddParameter("timestamp", "Thu, 24 Mar 2022 09:00:02");
request.AddParameter("event_type", "VIEW_CONTENT");
request.AddParameter("event_conversion_type", "web");
request.AddParameter("currency", "usd");
request.AddParameter("item_category", "bikes");
request.AddParameter("item_ids", "sam001");
request.AddParameter("event_tag", "in-stock");
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://snapchat.dmscg.com/api/conversionapi/view_content',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => array(
'email_address' => '[email protected]',
'price' => '43',
'timestamp' => 'Thu, 24 Mar 2022 09:00:02',
'event_type' => 'VIEW_CONTENT',
'event_conversion_type' => 'web',
'event_tag' => 'in-stock',
'currency' => 'usd',
'item_category' => 'bikes',
'item_ids' => 'sam001',
),
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer [[apiKey]]'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
?>
#!/usr/bin/perl
use strict;
use warnings;
use REST::Client;
my $client = REST::Client->new();
my $request_url = 'https://snapchat.dmscg.com/api/conversionapi/view_content';
@data=(
'email_address' => '[email protected]',
'price' => '43',
'timestamp' => 'Thu, 24 Mar 2022 09:00:02',
'event_type' => 'VIEW_CONTENT',
'event_conversion_type' => 'web',
'event_tag' => 'in-stock',
'currency' => 'usd',
'item_category' => 'bikes',
'item_ids' => 'sam001',
);
$client->POST($request_url, encode_json(@data),{"Authorization"=>"Bearer [[apiKey]]"});
print $client->responseContent();
import http.client
import mimetypes
from codecs import encode
conn = http.client.HTTPSConnection("snapchat.dmscg.com")
dataList = []
boundary = 'wL36Yn8afVp8Ag7AmP8qZ0SA4n1v9T'
dataList.append(encode('--' + boundary))
dataList.append(encode('Content-Disposition: form-data; name=email_address;'))
dataList.append(encode('Content-Type: {}'.format('text/plain')))
dataList.append(encode(''))
dataList.append(encode("[email protected]))
dataList.append(encode('--' + boundary))
dataList.append(encode('Content-Disposition: form-data; name=price;'))
dataList.append(encode('Content-Type: {}'.format('text/plain')))
dataList.append(encode(''))
dataList.append(encode("43"))
dataList.append(encode('--' + boundary))
dataList.append(encode('Content-Disposition: form-data; name=timestamp;'))
dataList.append(encode('Content-Type: {}'.format('text/plain')))
dataList.append(encode(''))
dataList.append(encode("Monday, March 28, 2022"))
dataList.append(encode('--' + boundary))
dataList.append(encode('Content-Disposition: form-data; name=event_type;'))
dataList.append(encode('Content-Type: {}'.format('text/plain')))
dataList.append(encode(''))
dataList.append(encode("VIEW_CONTENT"))
dataList.append(encode('--' + boundary))
dataList.append(encode('Content-Disposition: form-data; name=event_conversion_type;'))
dataList.append(encode('Content-Type: {}'.format('text/plain')))
dataList.append(encode(''))
dataList.append(encode("web"))
dataList.append(encode('--' + boundary))
dataList.append(encode('Content-Disposition: form-data; name=phone_number;'))
dataList.append(encode('Content-Type: {}'.format('text/plain')))
dataList.append(encode(''))
dataList.append(encode("+444 (999) 56 56 56"))
dataList.append(encode('--' + boundary))
dataList.append(encode('Content-Disposition: form-data; name=currency;'))
dataList.append(encode('Content-Type: {}'.format('text/plain')))
dataList.append(encode(''))
dataList.append(encode("usd"))
dataList.append(encode('--' + boundary))
dataList.append(encode('Content-Disposition: form-data; name=item_category;'))
dataList.append(encode('Content-Type: {}'.format('text/plain')))
dataList.append(encode(''))
dataList.append(encode("bikes"))
dataList.append(encode('--' + boundary))
dataList.append(encode('Content-Disposition: form-data; name=item_ids;'))
dataList.append(encode('Content-Type: {}'.format('text/plain')))
dataList.append(encode(''))
dataList.append(encode("sma001"))
dataList.append(encode('--' + boundary))
dataList.append(encode('Content-Disposition: form-data; name=event_tag;'))
dataList.append(encode('Content-Type: {}'.format('text/plain')))
dataList.append(encode(''))
dataList.append(encode("in-stock"))
dataList.append(encode('--'+boundary+'--'))
dataList.append(encode(''))
body = b'\r\n'.join(dataList)
payload = body
headers = {
'Authorization': 'Bearer [[apikey]]',
'InternalTest': 'true',
'Content-type': 'multipart/form-data; boundary={}'.format(boundary)
}
conn.request("POST", "/api/conversionapi/view_content", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
Parameters
Name | Description |
---|---|
viewContent |