Custom angular form submission

Hello, I tried to use the embed code section into an angular 9 project but I did not work, so I created a custom form sending it to hubspot url https://api.hsforms.com/submissions/v3/integration/submit/{{portalId}}/{{formId}}
but it doesn’t create a ticket number automatically even if I have th option of creating it automatically on, I have all the required fields added to the form, an example of it the way I am using it in postman is this one:

{

“fields”: [

{

“name”: “firstname”,

“value”: “”

},

{

“name”: “lastname”,

“value”: “”

},

{

“name”: “email”,

“value”: “”

},

{

“name”: “TICKET.content”,

“value”: “”

},

{

“name”: “TICKET.feature_request_category”,

“value”: “Feature Request”

},

{

“name”: “TICKET.user_role”,

“value”: “Role”

},

{

“name”: “attach_file”,

“value”: “”

},

{

“name”: “TICKET.subject”,

“value”: “Feature Request Ticket (in-product)”

},

{

“name”: “TICKET.ticket_type”,

“value”: “Feature Request”

}

]

}

Does anyone know what I am missing here?

Hello @01950

Forms API is designed to create contacts and not tickets.

To create a ticket in HubSpot, you can use the HubSpot Tickets API instead. Here’s an example of how you can submit a ticket to HubSpot using the Tickets API in Angular:

First, you’ll need to import the HttpClient module in your component:

import { HttpClient, HttpHeaders } from '@angular/common/http';

Then, you can create a function to submit the ticket:

submitTicket() {
 const headers = new HttpHeaders({
 'Content-Type': 'application/json'
 });

 const body = {
 subject: 'Feature Request Ticket (in-product)',
 content: 'Ticket content',
 hs_pipeline: '0',
 hs_pipeline_stage: '1',
 'requester.0.email': 'user@example.com',
 'requester.0.user_role': 'Role',
 'requester.0.ticket_type': 'Feature Request',
 'requester.0.feature_request_category': 'Feature Request'
 };

 this.http.post(`https://api.hubapi.com/crm-objects/v1/objects/tickets?hapikey=${yourApiKey}`, body, { headers }).subscribe(
 data => console.log(data),
 error => console.log(error)
 );
}

In this example, we’re using the HttpClient module to submit a POST request to the HubSpot Tickets API endpoint with the necessary parameters to create a new ticket.

Note that you’ll need to replace yourApiKey with your actual HubSpot API key.

Also, make sure to include the required fields in the body object. In this example, we’re including the ticket subject, content, pipeline stage, requester email, user role, ticket type, and feature request category.

Hi,

May you help me with the example for Forms API to create contacts with Angular 15.

thanks!

Hi @01950

It looks like you are trying to create a ticket in HubSpot using the HubSpot Forms API, but the ticket number is not being generated automatically.

HubSpot generates ticket numbers automatically only for tickets created through the Tickets API, not through the Forms API. Therefore, if you want the ticket number to be generated automatically, you should create the ticket using the Tickets API.

Here’s an example of how you could use the Tickets API to create a ticket in HubSpot:

1. First, you will need to obtain an OAuth access token from HubSpot.

2. Next, you can use the access token to make a POST request to the Tickets API endpoint, which is located at https://api.hubapi.com/crm-objects/v1/objects/tickets. The request body should include the following properties:

- `properties`: An object containing the properties of the ticket, including the `subject`, `content`, `ticket_type`, `feature_request_category`, and `user_role`.

- `associations`: An object containing the associations between the ticket and other HubSpot objects, such as contacts, companies, or deals. For example, you could associate the ticket with a contact by including the `contactIds` property and setting it to an array of contact IDs.

Here’s an example of what the request body might look like:

```
{
“properties”: {
“subject”: “Feature Request Ticket (in-product)”,
“content”: “This is the content of the ticket.”,
“ticket_type”: “Feature Request”,
“feature_request_category”: “Feature Request”,
“user_role”: “Role”
},
“associations”: {
“contactIds”: [123],
“companyIds”: [456],
“dealIds”: [789]
}
}
```

3. Finally, you can parse the response to retrieve the ticket number, which is located in the `objectId` property of the response.

Note that you will need to have the appropriate permissions and access to use the Tickets API. Also, make sure that you are properly authenticating your requests using the access token.

Please mark it as SOLUTION ACCEPTED if you like the solution.

Thank you!