Jump to content

Support manager API


Michael

Recommended Posts

Is there a way to extend the support manager to create a ticket or will it be best to use the API and if it's the API how is the best way to do it?

I saw @Blesta Addons did this and I edited it but I'm trying to start a ticket?
 

$reply_data = array(
              'ticket_id'=> NULL,
              'vars' => array(
                  'ticket_id'=>null,
                  'staff_id' => null,
                  'client_id' => $data['client_id'],
                  'contact_id' => null,
                  'type' => "reply",
                  'details' => $data['content'],
                  'status' => "open",
                  'staff_id' => null,
              ),
              'files' => null,
              'new_ticket' => true
          );
          $response = $api->post("support_manager.support_manager_tickets", "addReply", $reply_data);

Because I would like to set these up somehow:
- Subject
- Department

- priority

Thank you for your help.

the big lebowski thank you GIF

Link to comment
Share on other sites

Well I kinds depends.  If you are looking to do it through the API then you should first call SupportManagerTickets::add() like this

$ticket_data = [
    'vars' => [
        'department_id' => 1,
        'staff_id' => 1,  // This field is optional
        'service_id' => 1,  // This field is optional
        'client_id' => 1,  // This field is optional
        'email' => 'firsttes@mailinator.com',  // This field is optional
        'summary' => 'Something is terribly wrong',
        'priority' => 'critical',
        'status' => 'open'
    ]
]

$ticket = $api->post("support_manager.support_manager_tickets", "add", $ticket_data);

On the other hand, if you are within Blesta you should be able to use the loader to access the model even though it's from a plugin.  In a controller that would look like this

$ticket_data = [
    'department_id' => 1,
    'staff_id' => 1,  // This field is optional
    'service_id' => 1,  // This field is optional
    'client_id' => 1,  // This field is optional
    'email' => 'firsttes@mailinator.com',  // This field is optional
    'summary' => 'Something is terribly wrong',
    'priority' => 'critical',
    'status' => 'open'
];

$this->uses(['SupportManager.SupportManagerTickets']);
$ticket = $this->SupportManagerTickets->add($ticket_data);

brad pitt hello GIF

Link to comment
Share on other sites

6 minutes ago, Tyson said:

There are two separate calls you need to make:

  1. Create a ticket (as @Jono mentioned above)
  2. Create a reply for the ticket (as you did in your OP).
    1. FYI the first question from a customer that opens the ticket represents the first reply

Thanks mate. Is there a way to redirect to another function in Blesta for example:

<?php

public function index(){
  if($success == true){
      return self::success();
  }
}

public function success(){
	//run this function?
}

?>

 

Link to comment
Share on other sites

56 minutes ago, Blesta.Store said:

Thanks mate. Is there a way to redirect to another function in Blesta for example:


<?php

public function index(){
  if($success == true){
      return self::success();
  }
}

public function success(){
	//run this function?
}

?>

 

Your example mixes procedural and class syntax, so I'm not sure if you're running individual functions or if those are methods in a class.

If you are writing procedural functions, simply:

return success();

otherwise for one class method to call another non-statically:

return $this->success();

 

Link to comment
Share on other sites

Thanks @Tyson mate that return

$this->valid($client_info);

worked as I found I had to pass the variable through to the function to show the information on the views.

However submitting another form it tries to run the first form post in the index function and not the post in the success function do I need to set something up on the forms to call each one?

<?php
class Validate extends SupportController
{
  public function index(){
      if (!empty($this->post)) {
		$data2 = (isset($this->post) ? $this->post : '');
		if($data2){
			return $this->valid($data2);
		}
      }
  }
  public function valid($data2){
	if (!empty($this->post)) {
		$data = (isset($this->post) ? $this->post : '');
		if($data){
			return true;
		}
	}
  }
}

both of the forms have this in the views:
 

<?php
	$this->Form->create(null, ['id' => 'validate', 'enctype' => 'multipart/form-data']);
?>
<?php
	$this->Form->create(null, ['id' => 'support_ticket', 'enctype' => 'multipart/form-data']);
?>

 

Link to comment
Share on other sites

It sounds like you want to POST each form to a separate location.

<?php
// POST to the valid method
$this->Form->create('/validate/valid/', [...]);
...
$this->Form->end();

// POST to the index method
$this->Form->create(null, [...]);
...
$this->Form->end();

Your Validate::valid() method really shouldn't require an argument if you want to POST to it

Link to comment
Share on other sites

  • 1 year later...
26 minutes ago, Richzendy said:

Hi all,

How this:


$this->uses(['SupportManager.SupportManagerTickets']);

Can be used from a module? i can make a button on a client tab just to create a ticket with a format to require something with a pre-defined data.

Try using

Loader::loadModels($this, ['SupportManager.SupportManagerTickets']);

This is due to $this->uses() is not accessible from a module.

Link to comment
Share on other sites

3 hours ago, Abdy said:

Try using


Loader::loadModels($this, ['SupportManager.SupportManagerTickets']);

This is due to $this->uses() is not accessible from a module.

Hi! thank you, is working now, but to create a new ticket a details is needed, this can be all code to create a new ticket:

$ticket_data = [
    'department_id' => 1,
    'staff_id' => 1,  // This field is optional
    'service_id' => 38,  // This field is optional
    'client_id' => 1,  // This field is optional
    'summary' => 'This a new Requirement',
    'priority' => 'high',
    'status' => 'open',
];

$ticket_repply = [
    'details'   => 'Hi, I need a new Requirement'
];

Loader::loadModels($this, ['SupportManager.SupportManagerTickets']);

$ticket = $this->SupportManagerTickets->add($ticket_data);

if (!is_null($ticket)) {
	$this->SupportManagerTickets->addReply($ticket,$ticket_repply);
}
Link to comment
Share on other sites

  • 2 years later...

Hello,
 

A idea below... it works.

<?php
require_once "blesta_api.php";

$user = "apiuser";
$key = "apipw";
$url = "https://domain.tld/api/";

$clientmail = "test@demo.tld";
$ticketsummary = "This is a test.";
$ticketmsg = "Hello, I am unable to login. Please help!!";

$ticket_data = [
    'vars' => [
        'department_id' => 1,
        'staff_id' => 1,  // optional, set staffID
        'service_id' => null,  // optional
        'client_id' => null,  // optional
        'email' => $clientmail,  // optional
        'summary' => $ticketsummary,
        'priority' => 'critical',
        'status' => 'open'
    ]
];

$api = new BlestaApi($url, $user, $key);

$ticket = $api->post("support_manager.support_manager_tickets", "add", $ticket_data);

$zzid = $ticket->response();

$reply_data = array(
    'ticket_id'=> $zzid,
    'vars' => array(
        'ticket_id'=> $zzid,
        'staff_id' => null,
        'client_id' => null,
        'contact_id' => null,
        'type' => "reply",
        'details' => $ticketmsg,
        'status' => "open",
        'staff_id' => null,
    ),
    'files' => null,
    'new_ticket' => false
);


$response = $api->post("support_manager.support_manager_tickets", "addReply", $reply_data);

?>

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...