

# Connecting to Snapchat Ads in AWS Glue Studio
<a name="connecting-to-data-snapchat-ads"></a>

 Snapchat is a multimedia instant messaging app and service developed by Snap Inc., originally Snapchat Inc. One of the principal features of Snapchat is that pictures and messages are usually only available for a brief time before they become inaccessible to their recipients. Snapchat Marketing are posts for which businesses can pay to serve to Snapchat users. 

**Topics**
+ [AWS Glue support for Snapchat Ads](snapchat-ads-support.md)
+ [Policies containing the API operations for creating and using connections](snapchat-ads-configuring-iam-permissions.md)
+ [Configuring Snapchat Ads](snapchat-ads-configuring.md)
+ [Configuring Snapchat Ads connections](snapchat-ads-configuring-connections.md)
+ [Reading from Snapchat Ads entities](snapchat-ads-reading-from-entities.md)
+ [Snapchat Ads connection options](snapchat-ads-connection-options.md)
+ [Creating a Snapchat Ad account and configuring the client app](connecting-to-data-snapchat-ads-new-account.md)
+ [Creating an app in your Snapchat Ads account](connecting-to-data-snapchat-ads-managed-client-application.md)

# AWS Glue support for Snapchat Ads
<a name="snapchat-ads-support"></a>

AWS Glue supports Snapchat Ads as follows:

**Supported as a source?**  
Yes. You can use AWS Glue ETL jobs to query data from Snapchat Ads.

**Supported as a target?**  
No.

**Supported Snapchat Ads API versions**  
 v1. 

# Policies containing the API operations for creating and using connections
<a name="snapchat-ads-configuring-iam-permissions"></a>

 The following sample policy describes the required AWS permissions for creating and using connections. If you are creating a new role, create a policy that contains the following: 

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "glue:ListConnectionTypes",
        "glue:DescribeConnectionType",
        "glue:RefreshOAuth2Tokens",
        "glue:ListEntities",
        "glue:DescribeEntity"
      ],
      "Resource": "*"
    }
  ]
}
```

------

You can also use the following managed IAM policies to allow access:
+  [ AWSGlueServiceRole ](https://console.aws.amazon.com/iam/home#policies/arn:aws:iam::aws:policy/service-role/AWSGlueServiceRole) – Grants access to resources that various AWS Glue processes require to run on your behalf. These resources include AWS Glue, Amazon S3, IAM, Amazon CloudWatch Logs, and Amazon EC2. If you follow the naming convention for resources specified in this policy, AWS Glue processes have the required permissions. This policy is typically attached to roles specified when defining crawlers, jobs, and development endpoints. 
+  [ AWSGlueConsoleFullAccess ](https://console.aws.amazon.com/iam/home#policies/arn:aws:iam::aws:policy/AWSGlueConsoleFullAccess) – Grants full access to AWS Glue resources when an identity that the policy is attached to uses the AWS Management Console. If you follow the naming convention for resources specified in this policy, users have full console capabilities. This policy is typically attached to users of the AWS Glue console. 

# Configuring Snapchat Ads
<a name="snapchat-ads-configuring"></a>

Before you can use AWS Glue to transfer from Snapchat Ads, you must meet these requirements:

## Minimum requirements
<a name="snapchat-ads-configuring-min-requirements"></a>
+  You have a Snapchat Ads account. For more information on creating an account, see see [Creating a Snapchat Ad account and configuring the client app](connecting-to-data-snapchat-ads-new-account.md). 
+  You have created an OAuth2 app in your Snapchat Ads account. This integration provides the credentials that AWS Glue uses to access your data securely when it makes authenticated calls to your account. For more information, see [Creating an app in your Snapchat Ads account](connecting-to-data-snapchat-ads-managed-client-application.md). 

 If you meet these requirements, you’re ready to connect AWS Glue to your Snapchat Ads account. In Snapchat Ads, a connected app is a framework that authorizes external applications, like AWS Glue, to access your Snapchat Ads data. 

# Configuring Snapchat Ads connections
<a name="snapchat-ads-configuring-connections"></a>

 Snapchat Ads supports only the `AUTHORIZATION_CODE` grant type. 

 This grant type is considered “three-legged” OAuth as it relies on redirecting users to the third party authorization server to authenticate the user. It is used when creating connections via the AWS Glue Console. The user creating a connection may by default rely on a AWS Glue owned connected app (AWS Glue managed client application) where they do not need to provide any OAuth related information except for their Snapchat Ads instance URL. The AWS Glue Console will redirect the user to Snapchat Ads where the user must login and allow AWS Glue the requested permissions to access their Snapchat Ads instance. 

 Users may still opt to create their own connected app in Snapchat Ads and provide their own client id and client secret when creating connections through the AWS Glue Console. In this scenario, they will still be redirected to Snapchat Ads to login and authorize AWS Glue to access their resources. 

 This grant type results in a refresh token and access token. The access token expires after 1 hour of creation. A new access token can be fetched using the refresh token. 

 For more information on creating a connected app for Authorization Code OAuth flow, see [ Ads API ](https://marketingapi.snapchat.com/docs/#authentication). 

To configure a Snapchat Ads connection:

1.  In AWS Secrets Manager, create a secret with the following details. It is required to create a secret for each connection in AWS Glue. 

   1.  For customer managed connected app – Secret should contain the connected app Consumer Secret with `USER_MANAGED_CLIENT_APPLICATION_CLIENT_SECRET` as key. 

1. In AWS Glue Glue Studio, create a connection under **Data Connections** by following the steps below: 

   1. When selecting a **Connection type**, select Snapchat Ads.

   1. Provide the Snapchat Ads environment.

   1.  Select the IAM role which AWS Glue can assume and has permissions for following actions: 

------
#### [ JSON ]

****  

      ```
      {
        "Version":"2012-10-17",		 	 	 
        "Statement": [
          {
            "Effect": "Allow",
            "Action": [
              "secretsmanager:DescribeSecret",
              "secretsmanager:GetSecretValue",
              "secretsmanager:PutSecretValue",
              "ec2:CreateNetworkInterface",
              "ec2:DescribeNetworkInterfaces",
              "ec2:DeleteNetworkInterface"
            ],
            "Resource": "*"
          }
        ]
      }
      ```

------

   1.  Select the `secretName` which you want to use for this connection in AWS Glue to put the tokens. 

   1.  Select the network options if you want to use your network. 

1.  Grant the IAM role associated with your AWS Glue job permission to read `secretName`. 

# Reading from Snapchat Ads entities
<a name="snapchat-ads-reading-from-entities"></a>

 **Prerequisites** 
+  A Snapchat Ads Object you would like to read from. Refer the supported entities table below to check the available entities. 

 **Supported entities** 


| Entity | Can be Filtered | Supports Limit | Supports Order By | Supports Select \$1 | Supports Partitioning | 
| --- | --- | --- | --- | --- | --- | 
| Organization | No | No | No | Yes | No | 
| Ad Account | No | No | No | Yes | No | 
| Creative | No | No | No | Yes | No | 
| Media | No | No | No | Yes | No | 
| Campaign | Yes | No | No | Yes | No | 
| Ad Under Ad Account | Yes | No | No | Yes | No | 
| Ad Under Campaign | No | No | No | Yes | No | 
| Ad Squad | Yes | No | No | Yes | No | 
| Segment | No | No | No | Yes | No | 

 **Example** 

```
snapchatads_read = glueContext.create_dynamic_frame.from_options(
    connection_type="snapchatAds",
    connection_options={
        "connectionName": "connectionName",
        "ENTITY_NAME": "organization",
        "API_VERSION": "v1"
    }
)
```

 **Snapchat Ads entity and field details** 

 Snapchat Ads dynamically loads available fields under selected entity. Depending on the data type of the field, it supports following filter operators. 


| Field Data Type | Supported Filter Operators | 
| --- | --- | 
| Boolean | = | 

 **Partitioning queries** 
+  Field-based partitioning: Not supported. 
+  Record-based partitioning: Not supported. 

# Snapchat Ads connection options
<a name="snapchat-ads-connection-options"></a>

The following are connection options for Snapchat Ads:
+  `ENTITY_NAME`(String) - (Required) Used for Read. The name of Snapchat Ads entity. Example: ` campaign `. 
+  `API_VERSION`(String) - (Required) Used for Read. Snapchat Ads Rest API version you want to use. The value will be v1, as Snapchat Ads currently supports only version v1. 
+  `SELECTED_FIELDS`(List<String>) - Default: empty(SELECT \$1). Used for Read. Comma separated list of columns you want to select for the selected entity. 
+  `FILTER_PREDICATE`(String) - Default: empty. Used for Read. It should be in the Spark SQL format. 
+  `QUERY`(String) - Default: empty. Used for Read. Full Spark SQL query. 

# Creating a Snapchat Ad account and configuring the client app
<a name="connecting-to-data-snapchat-ads-new-account"></a>

**Topics**
+ [Sign up for Snapchat Ads](#snapchat-ads-sign-up)
+ [Steps to create a Snapchat Ad account](#snapchat-ads-create-ad-account)

## Sign up for Snapchat Ads
<a name="snapchat-ads-sign-up"></a>

**To sign up for Snapchat Ads:**

1.  Navigate to [Snapchat Ads Manager](https://ads.snapchat.com/). Choose **Sign Up** next to **New to Snapchat?**. 

1.  On the **Create Account** screen, follow the prompts to enter your Business Name, Email, Password, etc. Choose **Next**. 

1.  On the **Create Your Profile** screen, enter values for User Name, Website (Optional), and choose **Create Account**. This will give you an option to add a profile photo and bio on the **Edit Your Profile** screen. Choose **Confirm**. 

1.  On the **Business Info** screen, fill out the required fields like Country, Currency, Phone Number, GSTIN etc, and complete the account creation process by choosing **Next**. 

## Steps to create a Snapchat Ad account
<a name="snapchat-ads-create-ad-account"></a>

**To create a Snapchat Ad account:**

1.  Log in to **Ads Manager**. Then click the navigation in the top corner and select **Ad Accounts**. 

1.  Choose **\$1 New Ad Account**. Input your advertiser details: 
   +  Select whether or not you’re an agency buying ads on behalf of an advertiser. If you select ‘Yes’, your ad may be rejected if it uses targeting parameters that could include age, gender, or postal code level targeting. Minimum age targeting may be applied to up to 21 years of age. 
   +  Select whether or not your ad account will run housing, credit, or employment ads. If you select ‘Yes’, your ad may be rejected if it uses targeting parameters that could include age, gender, or postal code level targeting. Minimum age targeting may be applied to up to 21 years of age. 
   +  Select whether you will use the ad account for political ads. If you're running a political ad, input the sponsoring political organization or advocacy group who is paying for the ad. If you do not accurately input the political organization your ads may be rejected. You will also need to fill out the mandatory linked 'Political Ad Review Form' before submitting ads. 

1.  Choose **Account Details** and fill out your ad account info:     
<a name="snapchat-ads-account-details"></a>[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/glue/latest/dg/connecting-to-data-snapchat-ads-new-account.html)

1.  Choose **Create Account**. Your ad account will be created, and you can find it in the Ad Accounts portion of Ads Manager. To begin launching ads, you’ll want to input a payment method. You can also add members to your ad account. 

1.  Select whether you’d like to use an existing payment or create a new one. Then, choose **Save Payment Method**. 

1.  Select any [ members you’ve invited](https://businesshelp.snapchat.com/s/article/manage-members?language=en_US) to your business to add to the ad account. For more information about the roles and permissions that can be assigned, see [ Roles and Permissions Overview](https://businesshelp.snapchat.com/s/article/roles-permissions?language=en_US). Members added will then be able to log in to Ads Manager and access this ad account. When you’re done, save your members. 

 For more information about ad accounts, see [https://businesshelp.snapchat.com/s/article/roles-permissions?language=en_US](https://businesshelp.snapchat.com/s/article/roles-permissions?language=en_US)https://businesshelp.snapchat.com/s/article/roles-permissions?language=en\$1US 

# Creating an app in your Snapchat Ads account
<a name="connecting-to-data-snapchat-ads-managed-client-application"></a>

 To activate access to Snapchat’s Marketing API, make sure you have a business account set up. Then follow the steps below. 

1.  Log in to Ads Manager. Then choose the menu in the top left corner and select **Business Dashboard**, then select **Business Details**. 

1.  Choose **\$1OAuth App** . 

1.  Enter your App Name and Add following URL as Snap Redirect URI `https://<aws-region>.console.aws.amazon.com/gluestudio/oauth`. For example, if using the us-west-1 region, the URL would be `https://us-west-1.console.aws.amazon.com/gluestudio/oauth) and choose Create OAuth App`. Choose **Create OAuth App**. 

1.  Your app credentials (Client ID and client Secret) will be displayed. Save them as they will be required to create a connection. 