# Can not UPDATE movie in Vidly

**URL:** <https://forum.codewithmosh.com/t/can-not-update-movie-in-vidly/10695>\
**Category:** React\
**Created:** [February 15, 2022, 11:12am UTC](https://forum.codewithmosh.com/t/can-not-update-movie-in-vidly/10695 "2022-02-15T11:12:05Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anastasia\_djk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/anastasia_djk/32/3270_2.png) [@Anastasia\_djk](https://forum.codewithmosh.com/u/Anastasia_djk)\
**Post date:** [February 15, 2022, 11:12am UTC](https://forum.codewithmosh.com/t/can-not-update-movie-in-vidly/10695/1 "2022-02-15T11:12:05Z")

</div>

PLEASE, HELP ME! 😪

Section **Calling Backend Services** 24.

I can post new movie but cannot update the existing one. When I click the save button nothing happens and I see this error in the console:

 ![ERROR](https://us1.discourse-cdn.com/flex020/uploads/codewithmosh/original/2X/b/bb7f77898a9aed369bddc3d751ccfc7064bb4e49.png)

Here is movieForm

> import React from ‘react’;
> 
> import Form from ‘./common/form’;
> 
> import Joi from ‘joi-browser’;
> 
> import { getGenres } from ‘…/services/genreService’;
> 
> import { getMovie, saveMovie } from ‘…/services/movieService’;
> 
> class MovieForm extends Form {
> 
> ```
> state = {
> 
> data: {
> 
> title: "",
> 
> genreId: "",
> 
> numberInStock: "",
> 
> dailyRentalRate: ""
> 
> },
> 
> genres: [],
> 
> errors: {}
> 
> };
> 
> schema = {
> 
> _id: Joi.string(),
> 
> title: Joi.string().required().label('Title'),
> 
> genreId: Joi.required().label('Genre'),
> 
> numberInStock: Joi.number().min(0).max(100).required().label('Number In Stock'),
> 
> dailyRentalRate: Joi.number().min(0).max(10).required().label('Daily Rental Rate')
> 
> };
> 
> async populateGenres() {
> 
> const { data: genres } = await getGenres();
> 
> this.setState({ genres: genres });
> 
> };
> 
> async populateMovie() {
> 
> try {
> 
> const movieId = this.props.match.params.id;
> 
> if (movieId === 'new') return;
> 
> const { data: movie } = await getMovie(movieId);
> 
> this.setState({ data: this.mapToViewModel(movie) });
> 
> } catch (ex) {
> 
> if (ex.response && ex.response.status === 404)
> 
> return this.props.history.replace('/not-found');
> 
> }
> 
> };
> 
> async componentDidMount() {
> 
> await this.populateGenres();
> 
> await this.populateMovie();
> 
> };
> 
> mapToViewModel(movie) {
> 
> return {
> 
> _id: movie._id,
> 
> title: movie.title,
> 
> genreId: movie.genre._id,
> 
> numberInStock: movie.numberInStock,
> 
> dailyRentalRate: movie.dailyRentalRate
> 
> };
> 
> };
> 
> doSubmit = async () => {
> 
> await saveMovie(this.state.data);
> 
> this.props.history.push('/movies');
> 
> };
> 
> render() {
> 
> ```

**movieService.js**

> import http from ‘./httpService’;
> 
> import config from ‘…/config.json’;
> 
> const apiEndPoint = config.apiUrl + ‘/movies’;
> 
> export function getMovies() {
> 
> ```
> return http.get(apiEndPoint);
> 
> ```
> 
> }
> 
> export function getMovie(id) {
> 
> ```
> return http.get(apiEndPoint + '/' + id);
> 
> ```
> 
> }
> 
> export function deleteMovie(movieId) {
> 
> ```
> return http.delete(apiEndPoint + '/' + movieId);
> 
> ```
> 
> }
> 
> export function saveMovie(movie) {
> 
> ```
> if (movie._id) {
> 
> const body = { ...movie };
> 
> delete body._id;
> 
> return http.put(apiEndPoint + '/' + movie.id, body);
> 
> }
> 
> return http.post(apiEndPoint, movie);
> 
> ```
> 
> }

**httpService**

> import axios from ‘axios’;
> 
> import { toast } from ‘react-toastify’;
> 
> axios.interceptors.response.use(null, error =\> {
> 
> ```
> const expectedError = error.response && error.response.status >= 400 && error.response.status < 500;
> 
> if (!expectedError) {
> 
> console.log('Logging error: ', error);
> 
> toast.error('An unexpected error occured');
> 
> }
> 
> return Promise.reject(error);
> 
> ```
> 
> });
> 
> export default {
> 
> ```
> get: axios.get,
> 
> post: axios.post,
> 
> put: axios.put,
> 
> delete: axios.delete
> 
> ```
> 
> };

---

<div class="post-metadata">

**Author:** ![ThangTruong](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/thangtruong/32/3223_2.png) [@ThangTruong](https://forum.codewithmosh.com/u/ThangTruong)\
**Post date:** [February 15, 2022, 1:23pm UTC](https://forum.codewithmosh.com/t/can-not-update-movie-in-vidly/10695/2 "2022-02-15T13:23:12Z")

</div>

Hi Anas,

I do believe your code is nothing wrong. The Error 500 is means from server. It happens to me before. I believe that libraries you installed not matching with lessons. Have look the json file in the folder in finished and compare with your json file and see.  
My solution is I deleted my json file and re-installed library according to json file in finished folder and works well.

I hope this could help you.

Regards,  
Thang

---

<div class="post-metadata">

**Author:** ![sufian.babri](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/sufian.babri/32/1028_2.png) [@sufian.babri](https://forum.codewithmosh.com/u/sufian.babri)\
**Post date:** [February 16, 2022, 5:37am UTC](https://forum.codewithmosh.com/t/can-not-update-movie-in-vidly/10695/3 "2022-02-16T05:37:10Z")

</div>

The error says that the API endpoint that was hit was `/api/movies/undefined `. This means that somewhere in the code where you are setting the URL, the movie ID is not being set correctly.

So in your movieService.js file, replace `movie.id` with `movie._id` in the following line:

```auto
return http.put(apiEndPoint + '/' + movie.id, body);

```

---

<div class="post-metadata">

**Author:** ![Anastasia\_djk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/anastasia_djk/32/3270_2.png) [@Anastasia\_djk](https://forum.codewithmosh.com/u/Anastasia_djk)\
**Post date:** [February 16, 2022, 8:27am UTC](https://forum.codewithmosh.com/t/can-not-update-movie-in-vidly/10695/4 "2022-02-16T08:27:26Z")

</div>

Hello Thang,  
Thanks for our support! I have tried it but with the json file of Mosh my app seems not working at all 😬

---

<div class="post-metadata">

**Author:** ![Anastasia\_djk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/anastasia_djk/32/3270_2.png) [@Anastasia\_djk](https://forum.codewithmosh.com/u/Anastasia_djk)\
**Post date:** [February 16, 2022, 8:29am UTC](https://forum.codewithmosh.com/t/can-not-update-movie-in-vidly/10695/5 "2022-02-16T08:29:46Z")

</div>

Hello Sufian,  
I also thought about that, however it didnt solve the problem. Can I ask you to share your json file ?

---

<div class="post-metadata">

**Author:** ![sufian.babri](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/sufian.babri/32/1028_2.png) [@sufian.babri](https://forum.codewithmosh.com/u/sufian.babri)\
**Post date:** [February 16, 2022, 11:40am UTC](https://forum.codewithmosh.com/t/can-not-update-movie-in-vidly/10695/6 "2022-02-16T11:40:28Z")

</div>

I took the course in 2020 so I’m afraid I don’t even have that file and even if I have it, it will be similar to what Mosh has.

Maybe you could share the error log when you make the changes I suggested in my previous post? And if you still face a problem, you can post the error log here and I’ll take a look.

Just make sure you again reply to my comment so I get notified.

Have a great day. 🙂

---

<div class="post-metadata">

**Author:** ![Anastasia\_djk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/anastasia_djk/32/3270_2.png) [@Anastasia\_djk](https://forum.codewithmosh.com/u/Anastasia_djk)\
**Post date:** [February 16, 2022, 3:59pm UTC](https://forum.codewithmosh.com/t/can-not-update-movie-in-vidly/10695/7 "2022-02-16T15:59:43Z")

</div>

I would like to, but after making some changes in the json file my app broke completely and my original json file is somehow got lost, thats why I was asking yours 😅 So Im just following Mosh course without my app running. As Im almost at the end its fine… Thanks for your help! 😃

---

<div class="post-metadata">

**Author:** ![ThangTruong](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/thangtruong/32/3223_2.png) [@ThangTruong](https://forum.codewithmosh.com/u/ThangTruong)\
**Post date:** [February 17, 2022, 5:25am UTC](https://forum.codewithmosh.com/t/can-not-update-movie-in-vidly/10695/8 "2022-02-17T05:25:42Z")

</div>

How comes it not working ? It’s weird. It works for me as what I did is deleted my json file and then lookup dependencies from json file in the finished folder of the section and re-installed libraries which should be matched with version of the json file in the finished folder and then connected to Mongodb and all functions (insert new movie, update movie, delete movie and sorting) are working well.

OR you can give it a try compare your code with the code in the finished folder and see any different ? Trying from one to one. Ensuring files are store in the right path and import probably.

Regards,  
Thang

---

<div class="post-metadata">

**Author:** ![Anastasia\_djk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/anastasia_djk/32/3270_2.png) [@Anastasia\_djk](https://forum.codewithmosh.com/u/Anastasia_djk)\
**Post date:** [February 18, 2022, 1:19pm UTC](https://forum.codewithmosh.com/t/can-not-update-movie-in-vidly/10695/9 "2022-02-18T13:19:11Z")

</div>

But are you doing the course now?

---

<div class="post-metadata">

**Author:** ![ThangTruong](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/thangtruong/32/3223_2.png) [@ThangTruong](https://forum.codewithmosh.com/u/ThangTruong)\
**Post date:** [February 19, 2022, 6:29am UTC](https://forum.codewithmosh.com/t/can-not-update-movie-in-vidly/10695/10 "2022-02-19T06:29:34Z")

</div>

Hi Anas,

Yupe, i enrolled and still learning the course. My journal is up to Authentication and Authorization Section.

I am still a newbie and want to learn from others as much as i could.

Regards,  
Thang

---

<div class="post-metadata">

**Author:** ![mykfrost](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/mykfrost/32/3918_2.png) [@mykfrost](https://forum.codewithmosh.com/u/mykfrost)\
**Post date:** [August 14, 2022, 8:47am UTC](https://forum.codewithmosh.com/t/can-not-update-movie-in-vidly/10695/11 "2022-08-14T08:47:02Z")

</div>

Hey everyone. I have just finished adding config files and my movies app shows i have no movies in the database. can anyone help ?  
xhr.js:173 GET [http://localhost:3900/api/](http://localhost:3900/api/) 404 (Not Found)  
createError.js:17 Uncaught (in promise) Error: Request failed with status code 404  
at createError (createError.js:17:1)  
at settle (settle.js:19:1)  
at XMLHttpRequest.handleLoad (xhr.js:78:1)
