0

I am trying to Implement an API in Angular with post request, API is working fine in Postman, but when I Implemented this API in angular data is not posting neither giving me any error, I checked my Network too!

I am getting response in browser

{"code":204,"success":"Client Id is not selected!"}

status code: 200 ok

Payload in Postman:

{"clientid": "D0242"}

Payload showing in my browser:

enter image description here

app.setting

  public static DigestEmailIdPrint = "articles/DigestEmailIdPrint";

service.ts

  DigestEmailIdPrint(clientid) {
return this.http.post<any>(
  this.SERVERURL + this.AppSettings.DigestEmailIdPrint,
  { clientid: clientid }
);
}

app.ts

    ngOnInit(){
      this.DigestEmailIdPrint()   
      }
    DigestEmailIdPrint() {
    var postData = {
      clientid: localStorage.getItem("storageselectedclient"),
    };

    this.article.DigestEmailIdPrint(postData).subscribe(
      (res) => {
        console.log(res);
        console.log("hio");
        if (res.message != "No Record Found") {
          this.DigestEmailIdPrint = res;
        }
      },
      (err) => {
        console.log(err);
      }
    );
  }
7
  • In app.ts, shouldn't you call this.DigestEmailIdPrint() inside ngOnInit? Commented Jun 8, 2022 at 13:08
  • @BrunoFarias oops typo, I have added now! Commented Jun 8, 2022 at 13:11
  • Did you remove this.DigestEmailIdPrint() from the end of app.ts? How many requests you see going out in the Network tab? Do you see anything at all in the console? Commented Jun 8, 2022 at 13:14
  • What is the HTTP Code and response received ? Commented Jun 8, 2022 at 13:14
  • @BrunoFarias yes I removed because it lead to recursive call so I removed this.DigestEmailIdPrint() from the last Commented Jun 8, 2022 at 13:19

1 Answer 1

1

Try to update your code to because API is waiting for { clientid: clientid } not {clientid : { clientid: clientid }}

DigestEmailIdPrint(payload) {
  return this.http.post<any>(
  this.SERVERURL + this.AppSettings.DigestEmailIdPrint,
  payload
);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.