What is the process for updating a specific element in an object using Axios PATCH?

Using Axios.patch to modify data in an API. Here's a glimpse of the API structure:

"email": "string",
"phoneNumber": "string",
"mobileNumber": "string",
"temporaryAddress": {
  "address1": "string",
  "address2": "string",
  "address3": "string",
  "address4": "string",
}

It's straightforward when updating values except for when trying to update values within an object, like addresses. The syntax seems to be causing trouble. How can I edit a value inside an object? Specifically, I want to change address1, address2, etc.

I've experimented with different approaches but none seem to work. For example: "address: this.myAddress", "address: this.myAddress.address1", and "address1: this.myAddress" have all failed to update the values.

updateCustomer() {

  this.$axios.$patch('http://localhost:8381/customer/v3/PRIVATE/' + this.customerData.id + '/?auditUser=Updatus', {
      lastName: this.lName,
      phoneNumber: this.phoneNr,
      email: this.eMail,
      mobileNumber: this.mobileNr,
      firstName: this.fName,
      address.adress1: this.myAddress
    }, {
      headers: {
        'Authorization': 'Basic YXBpdXNlcjpwYXNzd29yZA==',
        'Content-Type': 'application/json',
      },
    })
    .then(response => {
      alert("Information successfully changed!")
      this.updateCheck = false;
    })

  error => {
    alert("Type in the information correctly!");
    console.log("update error test");
    return false;
  }
}

The goal is to update the value of address1 based on user input, but so far I'm encountering errors or the value remains unchanged.

Tried another approach: "address: {address1: "blabla 2", address2: "blablabla 3", address3: "tester 4", address4: "mehmeh 5"}". Although it compiled, it resulted in a 400 "Bad Request" error. Need guidance on the correct method.

Answer №1

Success! The functionality is operational.

Here is the method to access the content stored in the "location" entity.

location: {street: this.myStreet, city: this.myCity, state: this.myState, country: this.myCountry} 

Now I can modify the information using the PATCH request.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Buffering ceases on the video

I am experiencing an issue with 4 videos and a preloader, which should hide once all the videos are fully buffered. <div id="preload"> <h1> Download... </h1> </div> <video preload="auto" class= ...

Systemjs running with Angular2 is causing 503 errors

I have developed a basic Angular2 app that does not make any external calls to resources. It consists of approximately 10 components, each with its own HTML and CSS files. I utilize gulp to generate a distribution package and deploy it to a testing environ ...

Having trouble getting webpack to transpile typescript to ES5?

Despite following official guides and various tutorials, I am still facing an issue with compiling my code to ES5 using TypeScript and webpack. The problem is that the final bundle.js file always contains arrow functions. Here is a snippet from my webpack ...

Using Laravel to find records within a specific date range

Currently, I am able to search for an article and a specific date. How can I expand this search functionality to include searching for articles between two specific dates? Assuming criterion 1 is the name field and criterion is created_at, how can criteri ...

Troubleshooting problems with a JavaScript game that involves guessing numbers

I have been given a challenging Javascript assignment that involves using loops to create a counting betting game. The concept is simple: the User inputs a number, and the computer randomly selects a number between 1 and 10. The User can then bet up to 10 ...

Guide on how to display normal vectors on the surface of an object using three.js

After discovering an intriguing example on threejs.org that showcases drawing arrow normals, I realized that it is exactly what I need. However, the arrows are complex objects created by ArrowHelper. Upon examining the source code, I came across the setDir ...

Guide on executing dynamic queries with MySQL in Meteor

Attempting to execute dynamic queries against MySQL in Meteor using the numtel:mysql package has proven unsuccessful thus far. It seems that either I need guidance on passing dynamic arguments to the subscribe function, or I need to learn how to retrieve ...

I am facing an issue with invoking the post and put methods in AngularJS

My GET calls to the service are successful using CORS, but I'm encountering issues with preflight for POST, PUT, and DELETE requests. I am working with AngularJS and have tried various server-side headers configurations. $app = \Slim\Slim:: ...

Utilizing jQuery to Adjust Tab Transparency

I'm trying to add some opacity to my jQuery tabs, but so far I've only been successful with accordions. Any tips or tricks for achieving this effect with tabs? Styling with CSS .ui-tabs{ background-image: none; background: rgba(204, 204 ...

Showcase a Pair of Files Next to Eachother using HTML

I am a beginner with HTML and I am trying to accomplish a seemingly simple task. I have searched for similar questions and attempted the solutions provided, but none have worked for me. My goal is to have two documents displayed side by side on a web page ...

"Submit form data without reloading the page using the $_

I have an associative array that I am using to display images. I want to randomly select two or more pictures from these images with my code, but I have a couple of questions: How can I enhance the efficiency of my code? And is there a way to use JSON or ...

Tips for refreshing a webpage after returning from a redirected page

After utilizing certain logic, I am able to redirect to a new page. return RedirectToAction("Index"); If I navigate back to the previous page using the browser's back button, I would like for the "old" page to automatically update with default valu ...

Transferring Data from Mod_rewrite to PHP using HTML and JavaScript for the User Interface

My web application has two components: the front end built with HTML, JavaScript/jQuery, and the back end using PHP. In its previous state, it utilized unsightly URLs such as host/app/Page.php?userid=1... definitely not aesthetically pleasing! But with a ...

Is there a way to add user-input text to a .txt file in an ASP.NET MVC project?

Currently engrossed in a project involving user input from the 'categoryDescription' text box to be appended to an existing text file named 'category.txt' located in the 'app_data' folder. As a newcomer to ASP.NET MVC, I find ...

Is there a way to retrieve the JavaScript Console response code using Python and Selenium's execute_script method?

I am running a JavaScript fetch request in the Chrome developer console using Selenium's execute_script() function. The request performs as expected, but I want to set up a function that can verify if the response is a 403 status code. Is there any Se ...

Guide on converting a date input to a timestamp

I am trying to convert the date retrieved from an HTML5 date input into a timestamp and store it as a variable. HTML: <form> <section class="input"> <input type="date" id="date" name="maintenanace_date"/> </section> <sectio ...

Express JS encountering Firebase Google Sign-In glitch

Whenever a user clicks a button on the HTML page, this function is triggered. The function resides in auth.js and it is called from the server.js page. auth.js const firebase = require("firebase"); static googleSignIn(req,res){ firebase.aut ...

The property 'innerHTML' cannot be assigned to null, as stated in Vue

I am dealing with two components that allow for editing JSON objects. Additionally, I have a button that toggles between these two components. Below is the HTML code snippet: <v-btn @click="switchConfigClicked">Switch config</v-btn> <h4 cla ...

Creating a "select all" feature in an HTML multiple select box with jQuery - a step-by-step guide

I'm currently working on an HTML form that includes a multiple select box. I am looking to create a "select all" option within the multiple select box so that when a user clicks on that option, all other options in the select box are automatically sel ...

Storing the background color in a JavaScript variable

I've been experimenting with creating a fade in and out effect for a background image on a website. I've also been attempting to capture the background color of a div and store it in a variable. Here's what I have tried: elem = document.ge ...