1

I send a parameter with this

apiUrl = SERVER_API_URL + '/api/import/estimatee/' + this.state.estimateId;
.post(apiUrl, formData, config)

but I need to send parameters like

apiUrl = SERVER_API_URL + '/api/import/estimatee/' + this.state.estimateId + this.state.purchaseOrder.purchaseOrderName + this.state.purchaseOrder.purchaseOrderCurr

How can I solve this Thanks for your feedback people?

5
  • Why have you put the other parameters in quotes? Commented Oct 6, 2018 at 20:17
  • Depends on API I suppose, but I'm guessing separate them by & Commented Oct 6, 2018 at 20:22
  • like this ? this.state.estimateId & this.state.purchaseOrder.purchaseOrderName & this.state.purchaseOrder.purchaseOrderCurr Commented Oct 6, 2018 at 20:30
  • kind of. like this.state.estimateId + '&' + this.state.purchaseOrder.purchaseOrderName + '&' + this.state.purchaseOrder.purchaseOrderCurr Commented Oct 6, 2018 at 20:36
  • i tired for two parameters and i get this error localhost:9000/api/import/estimatee/1&undefined 404 (Not Found) 1 is my first parameter it is ok but second &undefined Commented Oct 6, 2018 at 20:58

2 Answers 2

2

Use template literals with query parameters ? and & to include multiple parameters:

const { estimateId, purchaseOrderCurr, purchaseOrderName } = this.state;

const apiURL = `${SERVER_API_URL}/api/import/estimate/order?estimateId=${estimateId}&purchaseOrderName=${purchaseOrderName}&purchaseOrderCurr=${purchaseOrderCurr}`

apiUrl will now be:

http://serverapi/api/import/estimate/order?estimateId="1234"&purchaseOrderName="orderName"&purchaseOrderCurr="USD"

Then you can use axios to post to apiUrl:

axios.post(apiUrl, formData, config);

OR

just paste the parameters in axios's options -- these parameters should be appended to formData, especially if they are relevant to what's being submitted in formData:

const { estimateId, purchaseOrderCurr, purchaseOrderName } = this.state;

axios.post(`${SERVER_API_URL}/api/import/estimate`, { formData, estimateId, purchaseOrderCurr, purchaseOrderName }, config);

OR

const fd = new FormData();
fd.append('estimateId', estimateId);
fd.append('purchaseOrderCurr', purchaseOrderCurr);
fd.append('purchaseOrderName', purchaseOrderName);
...other formData options

axios.post(`${SERVER_API_URL}/api/import/estimate`, fd, config);
Sign up to request clarification or add additional context in comments.

2 Comments

i get this error error: "Not Found" message: "Not Found" path: "/api/import/estimate/order" status: 404 and in console msj is xhr.js:178 POST localhost:9000/api/import/estimate/… 404 (Not Found)
and when i use like this const { estimateId, supplierId, purchaseOrder } = this.state; const apiUrl = ${SERVER_API_URL}/api/import/estimate/order?estimateId=${estimateId}&purchaseOrderName=${purchaseOrder}&purchaseOrderCurr=${supplierId}`` i get this error detail: "Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long'; nested exception is java.lang.NumberFormatException: For input string: "order"" message: "error.http.400" path: "/api/import/estimate/order" status: 400 title: "Bad Request"
0
const { estimateId, purchaseOrderName } = this.state;
const apiUrl = `${SERVER_API_URL}/api/import/estimate/${estimateId}/${purchaseOrderName}`;

im solved this way thanks guys.

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.