![]() |
VOOZH | about |
The CData Cmdlets for Snapchat Ads are standard PowerShell cmdlets that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time and bidirectional access to Snapchat Ads.
The Cmdlets are not only a PowerShell interface to Snapchat Ads, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete Snapchat Ads data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for Snapchat Ads. To access Snapchat Ads data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for Snapchat Ads.
Once you have acquired the necessary connection properties, accessing Snapchat Ads data in PowerShell can be enabled in three steps.
Create an OAuth application to connect to Snapchat Ads. See the online Help documentation for an authentication guide.
Additionally, you can optionally set AccountId to provide a default Account ID (meaning it won't need to be manually provided in the WHERE clause). If the AccountId is not specified, the first account in the Accounts view is used.
Install the module:
Install-Module SnapchatAdsCmdlets
Connect:
$snapchatads = Connect-SnapchatAds -InitiateOAuth "$InitiateOAuth"
Search for and retrieve data:
$id = "123" $campaigns = Select-SnapchatAds -Connection $snapchatads -Table "Campaigns" -Where "Id = `'$Id`'" $campaigns
You can also use the Invoke-SnapchatAds cmdlet to execute SQL commands:
$campaigns = Invoke-SnapchatAds -Connection $snapchatads -Query 'SELECT * FROM Campaigns WHERE Id = @Id' -Params @{'@Id'='123'}
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Snapchat Ads\lib\System.Data.CData.SnapchatAds.dll")
Connect to Snapchat Ads:
$conn= New-Object System.Data.CData.SnapchatAds.SnapchatAdsConnection("InitiateOAuth=GETANDREFRESH;")
$conn.Open()
Instantiate the SnapchatAdsDataAdapter, execute an SQL query, and output the results:
$sql="SELECT AccountId, Name from Campaigns"
$da= New-Object System.Data.CData.SnapchatAds.SnapchatAdsDataAdapter($sql, $conn)
$dt= New-Object System.Data.DataTable
$da.Fill($dt)
$dt.Rows | foreach {
Write-Host $_.accountid $_.name
}
Update-SnapchatAds -Connection $SnapchatAds -Columns @('AccountId','Name') -Values @('MyAccountId', 'MyName') -Table Campaigns -Id "MyId"
$cmd = New-Object System.Data.CData.SnapchatAds.SnapchatAdsCommand("UPDATE Campaigns SET Id='123' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.SnapchatAds.SnapchatAdsParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Add-SnapchatAds -Connection $SnapchatAds -Table Campaigns -Columns @("AccountId", "Name") -Values @("MyAccountId", "MyName")
$cmd = New-Object System.Data.CData.SnapchatAds.SnapchatAdsCommand("INSERT INTO Campaigns (Id) VALUES (@myId)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.SnapchatAds.SnapchatAdsParameter("@myId","123")))
$cmd.ExecuteNonQuery()
Remove-SnapchatAds -Connection $SnapchatAds -Table "Campaigns" -Id "MyId"
$cmd = New-Object System.Data.CData.SnapchatAds.SnapchatAdsCommand("DELETE FROM Campaigns WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.SnapchatAds.SnapchatAdsParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject
Download a free trial of the Snapchat Ads Data Provider to get started:
Download NowLearn more:
👁 Snapchat Ads IconRapidly create and deploy powerful .NET applications that integrate with Snapchat Ads.