Angular integration with POST request

Hallo everyone, i am new to subspot. I want to POST my user contact details to Hubspot Private-App. So far i created Private-App and got ACCESS-CODE. Can anyone help me with Angular POST request code. this is my service code

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

import { Injectable } from ‘@angular/core’;

import { ApiService } from ‘ish-core/services/api/api.service’;

@Injectable({ providedIn: ‘root’ })

export class HubspotService {

private readonly accesstoken = my-access-token;

private readonly API_URL = ‘https://api.hubapi.com/’;

private readonly DEAL_URL = `${this.API_URL}deals/v1/deal?haccessTOKEN=${this.accesstoken}`;

constructor(private apiService: ApiService, private http: HttpClient) {}

private get headers() {

return new HttpHeaders({ 'Content-Type': 'application/json' });

}

saveContact(param: { firstname: string; lastname: string; email: string; tel: string }) {

console.log(param);

const url = this.DEAL\_URL;

const params = {

  properties: \[

    {

      value: \`${param.firstname}\`,

      name: 'firstname',

    },

    {

      value: \`${param.lastname}\`,

      name: 'lastname',

    },

    {

      value: \`${param.email}\`,

      name: 'email',

    },

    {

      value: \`${param.tel}\`,

      name: 'telnumber',

    },

  ],

};

return this.http.post(url, params, { headers: this.headers });

}

getHubspot() {

return this.apiService.get('hubspot');

}

}

The access token should be provided as an authorization header and not in the URL of the request.

Hallo Everyone, I have changed my code to below, now getting “localhost has been blocked by CORS policy”

hubspot = require(‘@hubspot/api-client’);

hubspotClient = new this.hubspot.Client({

accessToken: my-access-token,

developerApiKey: my-api-key,

});

const createContactResponse = await this.hubspotClient.crm.contacts.basicApi.create(params);

await this.hubspotClient.crm.companies.associationsApi.create(createContactResponse.id, ‘company_to_contact’);

Please see this post about CORS errors. Generally speaking, you can’t use the API with front-end Javascript code. There are some exceptions, but regardless, doing so would expose your API keys in your front-end code and thus to your end users.

Also, you shouldn’t need your developer API Key in your request. Just your access token.