Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

672
Views
Not able to pass parameter in POST url angular

Hi I am trying to pass parameter in POST method url in angular service to construct a URL to fetch some data from an API but when I am calling it on component file I am getting error response.

Where am I doing wrong ?

Example I need this type of url to pass:- https://something/api/v1/map/GetdetailsById?ID=EF-345-RHDJI34-EHI3

In service I am doing :-

// Http Options
  httpOptions = {
    headers: new HttpHeaders({
      'Content-Type': 'application/json'
    })
  };

//POST API to show lists
  getOTList(): Observable<any> {
    const params = new HttpParams()
    .set('ID', 'EF-345-RHDJI34-EHI3');
    return this.http
      .post<any>(`${environment.Url}` + `${APIs.getList}`,{params}, this.httpOptions)
      .pipe(
        retry(1),
        catchError(this.handleError)
      )
  }

Ang in component I am doing :

ngOnInit(){
    this.getLists();
  }

getLists(){
    this.addService.getOTList().subscribe((response:any) => {
      if (response.IsSuccess == true) {
        console.log(response);
      }
      else {
        console.log("something is wrong.") //<========== getting this message in console
      }
    });
  }
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

We are doing a POST request, therefore we need to add a body. Your params should also be set into the same object as your httpOptions, setting the content type to json is really not needed with the HttpClient, it happens automagically, so I would just do:

return this.http.post<any>(`${environment.Url}` + `${APIs.getList}`, {}, { params })

Notice the empty body {}. As you are not even passing a body, this wouldn't need to be a POST request, just thought I'd mention. Also, please don't use any. Typing your data will help you in the future! :)

over 4 years ago · Santiago Trujillo Report

0

You need to set your params const to the params object in the your http.post call, like this: {params: params}.

So your updated service function should look like this:

getOTList(): Observable<any> {
   const params = new HttpParams()
   .set('ID', 'EF-345-RHDJI34-EHI3');
   return this.http.post<any>(`${environment.Url}` + `${APIs.getList}`, {params:params}, this.httpOptions)
      .pipe(
         retry(1),
         catchError(this.handleError)
      )
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!