SalesforceCore 1.0.3

dotnet add package SalesforceCore --version 1.0.3                
NuGet\Install-Package SalesforceCore -Version 1.0.3                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SalesforceCore" Version="1.0.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SalesforceCore --version 1.0.3                
#r "nuget: SalesforceCore, 1.0.3"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install SalesforceCore as a Cake Addin
#addin nuget:?package=SalesforceCore&version=1.0.3

// Install SalesforceCore as a Cake Tool
#tool nuget:?package=SalesforceCore&version=1.0.3                

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.

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.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 is compatible.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on SalesforceCore:

Package Downloads
SalesforceCore.Push

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

SalesforceCore.Authentication

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

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.3 5,070 1/25/2018
1.0.2 1,802 1/23/2018

Initial bug fixes.