add ticket creation to self-service API, RT#7007
[freeside.git] / fs_selfservice / java / freeside_create_ticket_example.java
1
2 import biz.freeside.SelfService;
3 import org.apache.commons.logging.impl.SimpleLog; //included in apache xmlrpc
4 import java.util.HashMap;
5 import java.util.Vector;
6
7 public class freeside_create_ticket_example {
8   private static SimpleLog logger = new SimpleLog("SelfService");
9
10   public static void main( String args[] ) throws Exception {
11     SelfService client =
12       new SelfService( "http://192.168.1.221:8081/xmlrpc.cgi" );
13
14     Vector params = new Vector();
15     params.addElement( "username" );
16     params.addElement( "4155551212" ); // svc_phone.phonenum
17     params.addElement( "password" );
18     params.addElement( "5454" );       // svc_phone.pin
19     params.addElement( "domain" );
20     params.addElement( "svc_phone" );
21     HashMap result = client.execute( "login", params );
22
23     String error = (String) result.get("error");
24
25     if (error.length() < 1) {
26
27       // successful login
28
29       String sessionId = (String) result.get("session_id");
30
31       logger.trace("[login] logged into freeside with session_id="+sessionId);
32
33       // store session id in your session store to be used for other calls
34
35       // like, say, this one to create a ticket
36
37       Vector ticket_params = new Vector();
38       ticket_params.addElement( "session_id" );
39       ticket_params.addElement( sessionId );
40       ticket_params.addElement( "requestor" );         // these
41       ticket_params.addElement( "email@example.com" ); // are
42       ticket_params.addElement( "cc" );                // optional
43       ticket_params.addElement( "joe@example.com" );   // 
44       ticket_params.addElement( "subject" );
45       ticket_params.addElement( "Houston, we have a problem." );
46       ticket_params.addElement( "message" );
47       ticket_params.addElement( "The Oscillation Overthurster has gone out of alignment!\n\nIt needs to be fixed immediately!" );
48
49       HashMap ticket_result = client.execute( "create_ticket", ticket_params);
50
51       String error = (String) ticket_result.get("error");
52
53       if (error.length() < 1) {
54
55         // successful ticket creation
56
57         String ticketId = (String) ticket_result.get("ticket_id");
58
59         logger.trace("[login] ticket created with id="+ticketId);
60
61       } else {
62
63         // unsuccesful creating ticket
64
65         logger.warn("[login] error creating ticket: "+error);
66
67       }
68
69     }else{
70
71       // unsuccessful login
72
73       logger.warn("[login] error logging into freeside: "+error);
74
75       // display/say error message to user
76
77     }
78   }
79 }