odyright
Angular5 POST request to Phoenix Frramework (api), send 422 (Unprocessable Entity)
I was running Angular 5 and Phoenix framework and I’m trying to send a POST request to Phoenix. i got 422 Unprocessable error

I have the following code:
enrollment.component.ts
saveEnrollment()
{
this.enrservice.saveEnrollment(this.enrollment)
.then(
(enrollment: Enrollment) => {
// Show the success message
this.snackBar.open('Enrollment success', 'OK', {
verticalPosition: 'top',
duration : 6000
});
});
}
enrollment.component.ts
saveEnrollment(enrollment: Enrollment)
{
return new Promise((resolve, reject) => {
this.http.post(API_URL, enrollment)
.subscribe((response: any) => {
resolve(response);
}, reject);
});
}
enrollment.model.ts
export class Enrollment {
id: number;
firstName: string;
lastName: string;
address: string;
city: string;
state: string;
postalCode: string;
constructor(enrollment?)
{
enrollment = enrollment || {};
/* this.id = enrollment.id || FuseUtils.generateGUID(); */
this.id = enrollment.id || '';
this.firstName = enrollment.firstName || '';
this.lastName = enrollment.lastName || '';
this.address = enrollment.address || '';
this.city = enrollment.city || '';
this.state = enrollment.state || '';
this.postalCode = enrollment.postalCode || '';
}}
and when i try to submit the form..i got that result:
[info] POST /api/enrollments
[debug] Processing with UmappWeb.EnrollmentController.create/2
Parameters: %{"address" => "", "city" => "", "firstName" => "", "id" => "",
"lastName" => "", "postalCode" => "", "state" => ""}
Pipelines: [:api]
[info] Sent 422 in 0┬Ás
Not sure what I’m doing wrong. please i need advise or help! thank you
Marked As Solved
odyright
everything works now… it was due to a mismatched TYPO… on server side Repo migration in the database. that’s why i got 422 (unprocessable entity)
Thank you @all of you.
Also Liked
odyright
Harrrrr, it seems the problem is the angular’s part..when i investigated the request payload part shown blank data for each input sent to the server(phoenix framework) but i don’t know where i’m wrong ///// ![]()
![]()
odyright
idi527
You would need to provide more information, probably. Or try to trace this enrollment object up to its creation, and see why it is empty.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









