Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

osTicket v1.10 (stable) and Maintenance Release v1.9.15 are now available! Go get it now

Formatting API tickets

Hi,

I have looked at the various documentation for the API, but still seem to be having trouble getting the resulting ticket description to be formatted correctly. I apologize if I have missed something.

I am trying to use the API to create a ticket which needs to include various information from a database. Here is the relevant snippets of code based on the example api.php file:
-----
$message .= $title . '<br>';
$message .= '<p>' . $referrer . '</p><p>Hours:Min (' . $hrs . ':' . $min . ')</p>';

$data = array(
    'name'      =>      'Test Proctor',  // from name aka User/Client Name
    'email'     =>      $user,  // from email aka User/Client Email
    'dept'         =>        'NPI',  // phone number aka User/Client Phone Number
    'subject'   =>      'API Test: ' . $title,  // test subject, aka Issue Summary
    'message'   =>      "data:text/html;charset=utf-8,$message",  // test ticket body, aka Issue Details.
    'ip'        =>      $_SERVER['SERVER_ADDR'], // Should be IP address of the machine thats trying to open the ticket.
    'topicId'   =>      '1', // the help Topic that you want to use for the ticket
 
    'attachments' => array()
);
----

Where $title, $referrer, $hrs, and $min are variables pulled from the database.

Unfortunately, when I look at the ticket created, all the html tags are ignored. I'm thinking there is just something I'm missing or is set wrong.

Help?


Comments

  • Does this work?

    'message'   =>      'This is a test of the osTicket API',


  • Yes, that would work. This is an example of what I get using the string variable:

    This is a test of the API process. Instance ID: 25963 XXXXXXX Hours:Min (1:0)

    That should be broken into 3 lines, but it's ignoring any <p> or <br> in the string.
  • I'm not real sure then.  I haven't done much in the way of API stuff other then playing with it and writing a basic how to a while back.  I didn't even know that they had added HTML support into the API. :)  That didn't exist when I first played with it.  
  • Thought I would provide an answer to my own question, having figured it out. This is how you do it:

    ---
    $message = '<html><body style="font-family: Helvetica, Arial, san-serif; font-size:12pt;"><p>';
    $message .= 'Instance ID: <a href="' . $referrer . '" target="_blank">' . $instance_id . '</a><br>';
    $message .= 'Request: '. $title . '</p>';
    .
    .
    .
    'message'   =>      "data:text/html;charset=utf-8,$message",
    ---
    What I was missing before was the <html> declaration at the start of $message. If you have that, you can build your html section as desired (like a stand-alone web page). I was able to create an entire table of all the ticket variables (the agents needed the variables set up in a specific way different than how it's presented in the ticket), including URL links to the originating page.

    Hope this helps someone!

  • I think you'll also want to encapsulate your HTML using xml CDATA tags like this:

    <message type="text/html"><![CDATA[This is a <b>test</b><br>This is a new line<br><ul><li>Item1<li>Item2</ul>]]></message>

    Otherwise, HTML tags aren't valid XML. If OSticket ever switches to a more stringent XML parser in the future, your raw HTML message elements may break.
Sign In or Register to comment.