APIs & Integrations

swoop
Member

Problems sending post requests

SOLVE

Good day! I have an Angular app. I send a post request for

https://api.hubapi.com/deals/v1/deal?hapikey=MY_API_KEY

and get an error

 

OPTIONS https://api.hubapi.com/deals/v1/deal?hapikey=my-key 401

 

Access to XMLHttpRequest at 'https://api.hubapi.com/deals/v1/deal?hapikey=!!!!!!!!!!!' from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

 

Tell me what's wrong please. That is my code

 

export class CrmService {
private readonly key = 'my api-key';
private readonly API_URL = 'https://api.hubapi.com/';
private readonly DEAL_URL = `${this.API_URL}deals/v1/deal?hapikey=${this.key}`;

constructor(private http: HttpClient) {}

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

sendOrder(param) {
const url = this.DEAL_URL;
const params = {
'properties': [
{
'value': `${param.name} ${param.surname}`,
'name': 'dealname'
},
{
'value': `${param.cost}`,
'name': 'amount'
},
{
'value': `${param.tel}`,
'name': 'telnumber'
},
{
'value': `${param.recipient}`,
'name': 'email'
},
{
'value': 'was deleted!!',
'name': 'hubspot_owner_id'
},
{
'value': `${param.model} ${param.memory} ${param.condition}`,
'name': 'old'
},
{
'value': `${param.tradeinModel} ${param.tradeinMemory} ${param.tradeinColor}`,
'name': 'new'
},
{
'value': `${param.comment}`,
'name': 'comment'
},
{
'value': `${param.address}`,
'name': 'adress'
},
{
'value': `${param.day} ${param.time}`,
'name': 'time'
}
]
};
return this.http.post(url, params, {headers: this.headers});
}

 

0 Upvotes
1 Accepted solution
swoop
Solution
Member

Problems sending post requests

SOLVE

I found a solution Smiley Wink

View solution in original post

0 Upvotes
5 Replies 5
ABENMALEK
Member

Problems sending post requests

SOLVE

How did you solved your probem please @swoop ?

0 Upvotes
swoop
Solution
Member

Problems sending post requests

SOLVE

I found a solution Smiley Wink

0 Upvotes
Vchannel
Participant

Problems sending post requests

SOLVE

Hi swoop,

 

I am also getting same issue can you tell how should i slove this.

0 Upvotes
somespec
Member

Problems sending post requests

SOLVE

so what is the solution please share it here .. thanks !

0 Upvotes
IsaacTakushi
HubSpot Employee
HubSpot Employee

Problems sending post requests

SOLVE

Welcome, @swoop.

 

Thanks for contributing; I'm glad you resolved the matter!

 

Would you mind briefly describing the solution you found?

 

If other Community members encounter a similar issue, I'd love to be able to direct them to your post Smiley Very Happy

Isaac Takushi

Associate Certification Manager
0 Upvotes