0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
using System;
using System.Collections.Generic;
using System.Text;
using TestAMSWebService.net.kinross_apis;
using System.Xml;
namespace TestAMSWebService
{
class Program
{
static void Main(string[] args)
{
AMSMessageService service = new AMSMessageService();
service.Url = "http://kinross-apis.net/ws/AMSMessageService";
Console.Out.WriteLine("Getting new messages...\n");
getMessagesRequest request = new getMessagesRequest();
request.apiKey = "<your AMS API Key>";
message[] messages = service.getMessages(request);
XmlTextWriter writer = new XmlTextWriter(Console.Out);
writer.Formatting = Formatting.Indented;
foreach(message msg in messages) {
Console.Out.Write("from: ");
address[] addresses = msg.address;
foreach (address a in addresses) {
Console.Out.Write(" " + a.Value + "(" + a.type + ")");
}
Console.Out.Write("\ntemplate: ");
Console.Out.WriteLine(msg.templateid);
Console.Out.WriteLine("Content: ");
msg.content.WriteContentTo(writer);
Console.Out.WriteLine("\n\n");
}
sendMessagesRequest sendRequest = new sendMessagesRequest();
sendRequest.apiKey = "<your AMS API Key>";
message newServiceJobMsg = new message();
// the template id for service order
// not that this id is different to the template of the same name in 0800tulips AMS account
// therefor this needs to be configurble - as does the api key for the account
newServiceJobMsg.templateid = "<the template id for the message type>";
address mobileAccountAddress = new address();
mobileAccountAddress.type = addressType.user;
mobileAccountAddress.Value = "<mobile account username>";
newMsg.address = new address[] { mobileAccountAddress };
XmlDocument doc = new XmlDocument();
XmlElement rootElement = doc.CreateElement("<template external name>");
newMsg.content = rootElement;
// Now create some message content
// for meta data fields their keys are their XML element names
XmlElement metaDataElement = doc.CreateElement("<meta data key>");
element.AppendChild(doc.CreateTextNode("<meta data value>"));
rootElement.AppendChild(metaDataElement);
XmlElement dateElement = doc.CreateElement("<date field external name>");
// the string format for the dates is defined in the account settings
// the default format is yyyy-MM-dd'T'HH:mm:ssZ
// you should use a date formatter to convert dates into this format where Z is the timezone offset in hours
// not sure what the .Net process is for this so have just put a static string value in for the moment
dateElement.AppendChild(doc.CreateTextNode("2009-05-28T9:00:00-1300"));
rootElement.AppendChild(dateElement);
XmlElement fieldElement = doc.CreateElement("<external name of AMS field>");
fieldElement.AppendChild(doc.CreateTextNode("<field value>"));
rootElement.AppendChild(jobDateElement);
// continue adding xml for rest of message (only ones that are required and / or we have data for)
sendRequest.message = new message[] { newMsg };
sendMessagesResponse sendResponse = service.sendMessages(sendRequest);
Console.Out.WriteLine("status: " + sendResponse.status);
foreach (string id in sendResponse.messageId) {
Console.Out.WriteLine("message id: " + id);
}
}
}
}
|