# Angular integration with POST request

**URL:** <https://community.hubspot.com/t/angular-integration-with-post-request/64677>\
**Category:** APIs & Integrations\
**Created:** [September 8, 2022, 9:09am UTC](https://community.hubspot.com/t/angular-integration-with-post-request/64677 "2022-09-08T09:09:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nischala](https://avatars.discourse-cdn.com/v4/letter/n/5fc32e/32.png) [@nischala](https://community.hubspot.com/u/nischala)\
**Post date:** [September 8, 2022, 9:09am UTC](https://community.hubspot.com/t/angular-integration-with-post-request/64677/1 "2022-09-08T09:09:54Z")

</div>

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/](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');

```

}

}

---

<div class="post-metadata">

**Author:** ![LeeBartelme](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/leebartelme/32/95647_2.png) [@LeeBartelme](https://community.hubspot.com/u/LeeBartelme)\
**Post date:** [September 8, 2022, 12:43pm UTC](https://community.hubspot.com/t/angular-integration-with-post-request/64677/2 "2022-09-08T12:43:49Z")

</div>

The access token should be provided as an [authorization header](https://developers.hubspot.com/docs/api/intro-to-auth#:~:text=10%26archived%3Dfalse-,Private%20app%20access%20tokens,in%20the%20authorization%20header%3A,-%2F~curl%20--header%20%22Authorization) and not in the URL of the request.

---

<div class="post-metadata">

**Author:** ![nischala](https://avatars.discourse-cdn.com/v4/letter/n/5fc32e/32.png) [@nischala](https://community.hubspot.com/u/nischala)\
**Post date:** [September 12, 2022, 6:45am UTC](https://community.hubspot.com/t/angular-integration-with-post-request/64677/3 "2022-09-12T06:45:19Z")

</div>

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’);

---

<div class="post-metadata">

**Author:** ![LeeBartelme](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/leebartelme/32/95647_2.png) [@LeeBartelme](https://community.hubspot.com/u/LeeBartelme)\
**Post date:** [September 12, 2022, 11:47am UTC](https://community.hubspot.com/t/angular-integration-with-post-request/64677/4 "2022-09-12T11:47:46Z")

</div>

Please see [this post](https://community.hubspot.com/t5/APIs-Integrations/CORS-issue/m-p/304553) 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.
