Capture customer name - Ticket creation

Hello,

I’m looking for advice on how to capture a customer’s name when creating a ticket through the API using JS/jQuery. I have been able to successfully create a ticket using this method, but I can only capture the customer’s email and not the name.

Expected functionality:

User fills out custom form and a ticket is creating upon submission. If the customer already exists within Zammad, it will associate the ticket with that user/account. If the customer doesn’t already exist in Zammad, a new customer account will be created for the user with their name and email that was entered in the form.

HTML

<form id="zammad-form">
<div class="form-group">
	<label class="control-label" for="first-name"><span class="field-name">First name</span></label>
	<input name="First name" class="form-control" id="first-name" type="text" size="35" maxlength="400"/>
</div>
<div class="form-group">
	<label class="control-label" for="last-name"><span class="field-name">Last name</span></label>
	<input name="Last name" class="form-control" id="last-name" type="text" size="35" maxlength="400"/>
</div>
<div class="form-group">
	<label class="control-label" for="email"><span class="field-name">Email</span></label>
	<input name="Email" class="form-control" id="email" type="text" size="35" maxlength="400"/>
</div>
<div class="form-group">
	<label class="control-label" for="subject"><span class="field-name">Subject</span></label>
	<input name="Subject" class="form-control" id="subject" type="text" size="35" maxlength="400"/>
</div>
<div class="form-group">
	<label class="control-label" for="group"><span class="field-name">Group</span></label>
	<select name="Mode" class="form-control" id="mode">
		<option disabled="disabled" selected="true" value="--" label="--"> --</option>
		<option value="Marine" label="Marine">Marine</option>
		<option value="Surface" label="Surface">Surface</option>
		<option value="Aviation" label="Aviation">Aviation</option>
	</select>
</div>
<div class="form-group">
	<label class="control-label" for="message"><span class="field-name">Message</span></label>
	<textarea name="Message" class="form-control" id="message" rows="5" cols="90"></textarea>
</div>
<div class="form-group">
	<input type="button" id="myButton" class="btn btn-default" value="Create ticket">
</div>
</form>

JavaScript

$('#myButton').click(function(){
	var mode = $('#mode').val();
	var email = $('#email').val();
	var subject = $('#subject').val();
	var message = $('#message').val();

	$.ajax({
		beforeSend: function(xhr) {
			xhr.setRequestHeader("Authorization","Token token=my-token");
		},
		type: 'POST',
		url: 'http://52.237.21.158:8083/api/v1/tickets',
		data: {
			"title": subject,
			"group": mode,
			"customer_id": "guess:" + email,
			"from": "Terminator",
			"article": {
				"from": "Terminator",
				"subject": "some subject",
				"body": message,
				"type": "note",
				"internal": false
			}
		},
		crossDomain: true,
		success: function (data) {
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {
		console.log(XMLHttpRequest);
		console.log(textStatus);
		console.log(errorThrown);
		}
	})
});

My question specifically is what do I have to add to the data information within the AJAX call to capture the first and last name entered within the form?

Thanks in advance for any help that can be provided.

1 Like

Hi @jwilliams8 and welcome to the community!

Unfortunately this is not possible. This is the code that creates the customer if not found:

The only way around this I can think of right now is to add the full parameter and check the results Assets Hash if the user has a first/lastname and update the account if not. See:

and

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.