SalesforceCore.Push 1.0.4

A .NET Core class library for accessing the Salesforce/ExactTarget Mobile Push service via REST API.

Install-Package SalesforceCore.Push -Version 1.0.4
dotnet add package SalesforceCore.Push --version 1.0.4
<PackageReference Include="SalesforceCore.Push" Version="1.0.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SalesforceCore.Push --version 1.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

SalesforceCore

A .NET Core class library for accessing the Salesforce/ExactTarget REST API.

So far I have only added functionality for the Authentication and Push endpoints but I will add the rest when I can.

Installation

To use SalesforceCore in your C# project, you can either download the SalesforceCore C# .NET libraries directly from the Github repository or, if you have the NuGet package manager installed, you can grab them automatically.

  • Nuget package: https://www.nuget.org/packages/SalesforceCore/ NuGet Badge
PM> Install-Package SalesforceCore

Once you have the SalesforceCore libraries properly referenced in your project, you can include calls to them in your code.

Add the following namespaces to use the library:

using SalesforceCore.Authentication;
using SalesforceCore.Authentication.Models;
using SalesforceCore.Models.Response.Base;
using SalesforceCore.Push;
using SalesforceCore.Push.Models;
using System;
using System.Collections.Generic;
using System.Linq;

Dependencies

To use this package you need to have the relevant Salesforce services (e.g. Mobile Push) as well as API credentials with rights to the service.

Usage

This is intended for usage in .NET Core 2.0 projects.

Authentication

	string clientId = "<YOUR_CLIENT_ID>";
	string clientSecret = "<YOUR_CLIENT_SECRET>";

	// Get authentication token
	Authentication authentication = new Authentication(clientId, clientSecret);
	SalesforceCoreAuthenticationClient authenticationClient = new SalesforceCoreAuthenticationClient();
	
	BaseResponse<Token> tokenResponse = authenticationClient.CreateToken(authentication);

Push

	// Create push client
	SalesforceCorePushClient pushClient = new SalesforceCorePushClient(tokenResponse.Result.AccessToken);

	// Create push message
	// https://developer.salesforce.com/docs/atlas.en-us.noversion.mc-apis.meta/mc-apis/createPushMessage.htm?search_text=application
	Message message = new Message()
	{
		MessageType = SalesforceCore.Push.Models.Type.MessageType.Outbound,
		ContentType = SalesforceCore.Push.Models.Type.ContentType.Alert,
		Name = "My Message Name",
		Application = new Application()
		{
			Id = "237690ac-41ff-4d3f-82f2-9c7efd89185f",
			Name = "MyApplication"
		},
		Alert = "Alert message to show on device",
		Sound = "Sound to play, or 'default'",
		Badge = "+1",
		ContentAvailable = 1,
		OpenDirect = "OD001",
		Keys = new List<MessageKey>()
		{
			new MessageKey() { Key = "key01", Value = "value01" },
			new MessageKey() { Key = "key02", Value = "value02" },
			new MessageKey() { Key = "key03", Value = "value03" }
		},
		Custom = new Dictionary<string, object>()
		{
			{ "customA", 1 },
			{ "customB", "custom text b" },
			{ "customC", new Tuple<string, string>("cC", "custom text c") },
		},
		SendInitiator = SalesforceCore.Push.Models.Type.SendInitiatorType.UI,
		StartDate = DateTime.Parse("2014-04-30T14:50:00Z"),
		EndDate = DateTime.Parse("2014-04-30T14:55:00Z"),
		MessagesPerPeriod = 1000,
		MinutesPerPeriod = 60,
		NumberOfPeriods = 24,
		PeriodType = SalesforceCore.Push.Models.Type.PeriodType.Hour,
		IsRollingPeriod = false,
		MessageLimit = 1,
		TzBased = true,
		TzPastSendAction = SalesforceCore.Push.Models.Type.TzPastSendActionType.SendImmediately,
		ScheduledTzOffset = -4,
		ScheduledTzSupportsDst = true,
		InclusionLists = new List<ResponseId>()
		{
			new ResponseId() { Id = "listID01" },
			new ResponseId() { Id = "listID02" },
			new ResponseId() { Id = "listID03" }
		},
		ExclusionLists = new List<ResponseId>()
		{
			new ResponseId() { Id = "listID04" },
			new ResponseId() { Id = "listID05" },
			new ResponseId() { Id = "listID06" }
		},
		Status = SalesforceCore.Push.Models.Type.StatusType.Active,
		PageId = 456,
		Url = "http://www.example.com",
		Subject = "My inbox subject line",
		Media = new Media()
		{
			IosUrl = "https://example.com",
			AndroidUrl = "https://example.com",
			Alt = "Example ALT Text"
		},
		Geofences = new List<ResponseId>()
		{
			new ResponseId() { Id = "MTIzOjEyODow" },
			new ResponseId() { Id = "MzIxOjEyODow" }
		}
	};

	// Send push message create request
	BaseResponse<MessageToken> createMessageResponse = pushClient.CreateMessage(message);

	// Find ID of created message
	BaseResponse<List<Message>> messagesResponse = pushClient.GetMessage();

	string messageId = messagesResponse.Result.Where(x => x.Name == "My Message Name").FirstOrDefault().Id;

	// Send message to contacts
	// https://developer.salesforce.com/docs/atlas.en-us.noversion.mc-apis.meta/mc-apis/postMessageContactSendPush.htm?search_text=application

	// Create send message
	MessageContact messageContact = new MessageContact()
	{
		DeviceTokens = new List<string>()
		{
			"DeviceToken1",
			"DeviceToken2",
			"DeviceToken3"
		},
		InclusionTags = new List<string>()
		{
			"Midwest"
		},
		ExclusionTags = new List<string>()
		{
			"Indiana",
			"Ohio"
		},
		Override = true,
		MessageText = "New information available!",
		Title = "Boost your winnings!",
		Subtitle = "Check your app to see what else is in store.",
		MutableContent = true,
		SendTime = DateTime.Parse("2012-10-31 09:00"),
		MessageCategory = new MessageCategory()
		{
			Name = "ETubeDemo"
		},
		Sound = "MyFile.caf",
		Badge = "+1",
		OpenDirect = "OD01",
		CustomKeys = new Dictionary<string, object>()
		{
			{ "keyA", "keyA_value" },
			{ "keyB", "keyB_value" }
		},
		CustomPayload = "\"customA\": \"customA_value\""
	};

	// Send message
	BaseResponse<MessageToken> sendMessageToDevicesResponse = pushClient.SendMessageToDevices(messageId, messageContact);

This is still a work in progress and the Salesforce REST documentation is pretty terrible so if you spot anything wrong feel free to let me know or submit some changes.

SalesforceCore

A .NET Core class library for accessing the Salesforce/ExactTarget REST API.

So far I have only added functionality for the Authentication and Push endpoints but I will add the rest when I can.

Installation

To use SalesforceCore in your C# project, you can either download the SalesforceCore C# .NET libraries directly from the Github repository or, if you have the NuGet package manager installed, you can grab them automatically.

  • Nuget package: https://www.nuget.org/packages/SalesforceCore/ NuGet Badge
PM> Install-Package SalesforceCore

Once you have the SalesforceCore libraries properly referenced in your project, you can include calls to them in your code.

Add the following namespaces to use the library:

using SalesforceCore.Authentication;
using SalesforceCore.Authentication.Models;
using SalesforceCore.Models.Response.Base;
using SalesforceCore.Push;
using SalesforceCore.Push.Models;
using System;
using System.Collections.Generic;
using System.Linq;

Dependencies

To use this package you need to have the relevant Salesforce services (e.g. Mobile Push) as well as API credentials with rights to the service.

Usage

This is intended for usage in .NET Core 2.0 projects.

Authentication

	string clientId = "<YOUR_CLIENT_ID>";
	string clientSecret = "<YOUR_CLIENT_SECRET>";

	// Get authentication token
	Authentication authentication = new Authentication(clientId, clientSecret);
	SalesforceCoreAuthenticationClient authenticationClient = new SalesforceCoreAuthenticationClient();
	
	BaseResponse<Token> tokenResponse = authenticationClient.CreateToken(authentication);

Push

	// Create push client
	SalesforceCorePushClient pushClient = new SalesforceCorePushClient(tokenResponse.Result.AccessToken);

	// Create push message
	// https://developer.salesforce.com/docs/atlas.en-us.noversion.mc-apis.meta/mc-apis/createPushMessage.htm?search_text=application
	Message message = new Message()
	{
		MessageType = SalesforceCore.Push.Models.Type.MessageType.Outbound,
		ContentType = SalesforceCore.Push.Models.Type.ContentType.Alert,
		Name = "My Message Name",
		Application = new Application()
		{
			Id = "237690ac-41ff-4d3f-82f2-9c7efd89185f",
			Name = "MyApplication"
		},
		Alert = "Alert message to show on device",
		Sound = "Sound to play, or 'default'",
		Badge = "+1",
		ContentAvailable = 1,
		OpenDirect = "OD001",
		Keys = new List<MessageKey>()
		{
			new MessageKey() { Key = "key01", Value = "value01" },
			new MessageKey() { Key = "key02", Value = "value02" },
			new MessageKey() { Key = "key03", Value = "value03" }
		},
		Custom = new Dictionary<string, object>()
		{
			{ "customA", 1 },
			{ "customB", "custom text b" },
			{ "customC", new Tuple<string, string>("cC", "custom text c") },
		},
		SendInitiator = SalesforceCore.Push.Models.Type.SendInitiatorType.UI,
		StartDate = DateTime.Parse("2014-04-30T14:50:00Z"),
		EndDate = DateTime.Parse("2014-04-30T14:55:00Z"),
		MessagesPerPeriod = 1000,
		MinutesPerPeriod = 60,
		NumberOfPeriods = 24,
		PeriodType = SalesforceCore.Push.Models.Type.PeriodType.Hour,
		IsRollingPeriod = false,
		MessageLimit = 1,
		TzBased = true,
		TzPastSendAction = SalesforceCore.Push.Models.Type.TzPastSendActionType.SendImmediately,
		ScheduledTzOffset = -4,
		ScheduledTzSupportsDst = true,
		InclusionLists = new List<ResponseId>()
		{
			new ResponseId() { Id = "listID01" },
			new ResponseId() { Id = "listID02" },
			new ResponseId() { Id = "listID03" }
		},
		ExclusionLists = new List<ResponseId>()
		{
			new ResponseId() { Id = "listID04" },
			new ResponseId() { Id = "listID05" },
			new ResponseId() { Id = "listID06" }
		},
		Status = SalesforceCore.Push.Models.Type.StatusType.Active,
		PageId = 456,
		Url = "http://www.example.com",
		Subject = "My inbox subject line",
		Media = new Media()
		{
			IosUrl = "https://example.com",
			AndroidUrl = "https://example.com",
			Alt = "Example ALT Text"
		},
		Geofences = new List<ResponseId>()
		{
			new ResponseId() { Id = "MTIzOjEyODow" },
			new ResponseId() { Id = "MzIxOjEyODow" }
		}
	};

	// Send push message create request
	BaseResponse<MessageToken> createMessageResponse = pushClient.CreateMessage(message);

	// Find ID of created message
	BaseResponse<List<Message>> messagesResponse = pushClient.GetMessage();

	string messageId = messagesResponse.Result.Where(x => x.Name == "My Message Name").FirstOrDefault().Id;

	// Send message to contacts
	// https://developer.salesforce.com/docs/atlas.en-us.noversion.mc-apis.meta/mc-apis/postMessageContactSendPush.htm?search_text=application

	// Create send message
	MessageContact messageContact = new MessageContact()
	{
		DeviceTokens = new List<string>()
		{
			"DeviceToken1",
			"DeviceToken2",
			"DeviceToken3"
		},
		InclusionTags = new List<string>()
		{
			"Midwest"
		},
		ExclusionTags = new List<string>()
		{
			"Indiana",
			"Ohio"
		},
		Override = true,
		MessageText = "New information available!",
		Title = "Boost your winnings!",
		Subtitle = "Check your app to see what else is in store.",
		MutableContent = true,
		SendTime = DateTime.Parse("2012-10-31 09:00"),
		MessageCategory = new MessageCategory()
		{
			Name = "ETubeDemo"
		},
		Sound = "MyFile.caf",
		Badge = "+1",
		OpenDirect = "OD01",
		CustomKeys = new Dictionary<string, object>()
		{
			{ "keyA", "keyA_value" },
			{ "keyB", "keyB_value" }
		},
		CustomPayload = "\"customA\": \"customA_value\""
	};

	// Send message
	BaseResponse<MessageToken> sendMessageToDevicesResponse = pushClient.SendMessageToDevices(messageId, messageContact);

This is still a work in progress and the Salesforce REST documentation is pretty terrible so if you spot anything wrong feel free to let me know or submit some changes.

Release Notes

Initial bug fixes.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.4 304 1/25/2018
1.0.3 288 1/24/2018