diff --git a/include/asterisk/res_pjsip.h b/include/asterisk/res_pjsip.h
index 45d9325ee7906fda22dbe2a6689f9ad28c39c418..fdb2105cfaba033bad70c2bb7239503c41707f81 100644
--- a/include/asterisk/res_pjsip.h
+++ b/include/asterisk/res_pjsip.h
@@ -1727,6 +1727,8 @@ struct ast_sip_ami {
 	const char *action_id;
 	/*! user specified argument data */
 	void *arg;
+	/*! count of objects */
+	int count;
 };
 
 /*!
diff --git a/res/res_pjsip/config_auth.c b/res/res_pjsip/config_auth.c
index cd4b959859b0ee5531e377d903a3c5085a6f1dde..b8c9bc9d1e0a935f004f2860b26b26c8e5666ea9 100644
--- a/res/res_pjsip/config_auth.c
+++ b/res/res_pjsip/config_auth.c
@@ -175,6 +175,8 @@ static int format_ami_auth_handler(void *obj, void *arg, int flags)
 	}
 
 	astman_append(ami->s, "%s\r\n", ast_str_buffer(buf));
+	ami->count++;
+
 	return 0;
 }
 
diff --git a/res/res_pjsip/config_transport.c b/res/res_pjsip/config_transport.c
index 785fcc5ac57c7646d78e607c03b96c8e7210c871..0a56b926345107be2c9ef14b691ba85f6d34e27d 100644
--- a/res/res_pjsip/config_transport.c
+++ b/res/res_pjsip/config_transport.c
@@ -39,16 +39,20 @@ static int sip_transport_to_ami(const struct ast_sip_transport *transport,
 static int format_ami_endpoint_transport(const struct ast_sip_endpoint *endpoint,
 					 struct ast_sip_ami *ami)
 {
-	RAII_VAR(struct ast_str *, buf,
-		 ast_sip_create_ami_event("TransportDetail", ami), ast_free);
-	RAII_VAR(struct ast_sip_transport *,
-		 transport, ast_sorcery_retrieve_by_id(
-			 ast_sip_get_sorcery(), "transport",
-			 endpoint->transport), ao2_cleanup);
+	RAII_VAR(struct ast_str *, buf, NULL, ast_free);
+	RAII_VAR(struct ast_sip_transport *, transport, NULL, ao2_cleanup);
+
+	if (ast_strlen_zero(endpoint->transport)) {
+		return 0;
+	}
+
+	buf = ast_sip_create_ami_event("TransportDetail", ami);
 	if (!buf) {
 		return -1;
 	}
 
+	transport = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "transport",
+		endpoint->transport);
 	if (!transport) {
 		astman_send_error_va(ami->s, ami->m, "Unable to retrieve "
 				     "transport %s\n", endpoint->transport);
@@ -61,6 +65,8 @@ static int format_ami_endpoint_transport(const struct ast_sip_endpoint *endpoint
 		       ast_sorcery_object_get_id(endpoint));
 
 	astman_append(ami->s, "%s\r\n", ast_str_buffer(buf));
+	ami->count++;
+
 	return 0;
 }
 
diff --git a/res/res_pjsip/location.c b/res/res_pjsip/location.c
index b0a49cdf770c6ca3dac7c6553dddefa0b8a5db83..d6015c7582ae346092e48b6b95f56f557acffa00 100644
--- a/res/res_pjsip/location.c
+++ b/res/res_pjsip/location.c
@@ -506,6 +506,8 @@ static int format_ami_aor_handler(void *obj, void *arg, int flags)
 		       ast_sorcery_object_get_id(endpoint));
 
 	astman_append(ami->s, "%s\r\n", ast_str_buffer(buf));
+	ami->count++;
+
 	return 0;
 }
 
diff --git a/res/res_pjsip/pjsip_configuration.c b/res/res_pjsip/pjsip_configuration.c
index 548372879f174ec7b80d93712863aeb908ddec09..9166d3f337e6c324b7a636b4f2f0a900d7162390 100644
--- a/res/res_pjsip/pjsip_configuration.c
+++ b/res/res_pjsip/pjsip_configuration.c
@@ -1107,7 +1107,8 @@ static int format_ami_endpoint(const struct ast_sip_endpoint *endpoint,
 
 static int ami_show_endpoint(struct mansession *s, const struct message *m)
 {
-	struct ast_sip_ami ami = { .s = s, .m = m, .action_id = astman_get_header(m, "ActionID"), };
+	struct ast_sip_ami ami = { .s = s, .m = m, .action_id = astman_get_header(m, "ActionID"),
+		.count = 0, };
 	RAII_VAR(struct ast_sip_endpoint *, endpoint, NULL, ao2_cleanup);
 	const char *endpoint_name = astman_get_header(m, "Endpoint");
 	int count = 0;
@@ -1144,7 +1145,8 @@ static int ami_show_endpoint(struct mansession *s, const struct message *m)
 		astman_append(s, "ActionID: %s\r\n", ami.action_id);
 	}
 	astman_append(s, "EventList: Complete\r\n"
-		      "ListItems: %d\r\n\r\n", count + 1);
+		      "ListItems: %d\r\n\r\n", ami.count + 1);
+
 	return 0;
 }
 
diff --git a/res/res_pjsip/pjsip_options.c b/res/res_pjsip/pjsip_options.c
index c9b4f8ccbe7551b5564c9882f8da2f9f1b939205..1c26251abffe0dba0050ca3169e802839af1ebdf 100644
--- a/res/res_pjsip/pjsip_options.c
+++ b/res/res_pjsip/pjsip_options.c
@@ -995,7 +995,8 @@ static int format_contact_status(void *obj, void *arg, int flags)
 	ast_str_append(&buf, 0, "EndpointName: %s\r\n",
 			ast_sorcery_object_get_id(endpoint));
 	astman_append(ami->s, "%s\r\n", ast_str_buffer(buf));
-
+	ami->count++;
+	
 	ast_free(buf);
 	ao2_cleanup(status);
 	return 0;
diff --git a/res/res_pjsip_endpoint_identifier_ip.c b/res/res_pjsip_endpoint_identifier_ip.c
index 294c4455d2035db83688868a5666b9ca52f38e41..5d938c03ed320a4b2798152c811f3f4fc1c81f81 100644
--- a/res/res_pjsip_endpoint_identifier_ip.c
+++ b/res/res_pjsip_endpoint_identifier_ip.c
@@ -263,6 +263,8 @@ static int format_ami_endpoint_identify(const struct ast_sip_endpoint *endpoint,
 		ast_sorcery_object_get_id(endpoint));
 
 	astman_append(ami->s, "%s\r\n", ast_str_buffer(buf));
+	ami->count++;
+
 	return 0;
 }