Recent searches
No recent searches
How to use the formdata in the client request method?
Posted Sep 04, 2023
I making an API calls inside the SDK application with the Axios POST method and Formdata, you can in the below code.
const axios = require('axios');
const FormData = require('form-data');
let data = new FormData();
data.append('username', 'balu');
data.append('key', jhjjjjhjjjhh');
data.append('email', 'anish.k@spritle.com');
let config = {
method: 'post',
maxBodyLength: Infinity,
url: 'https://opencart.ajithr.com/index.php?route=zendesk/customer',
headers: {
'Content-Type': 'application/json',
'Cookie': 'OCSESSID=0c4898f4cd2a443a21c3fb3324; currency=USD',
...data.getHeaders()
},
data : data
};
axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});
How can I change this Axios method into a client method?
I documentation also can't able to find it.
Thanks in advance.
1
12
12 comments
Erica Girges
0
rajesh parmar
1264158211329
i add ‘application/binary’ as contentType but still not work
0
Erica Girges
It looks like you might be dealing with a content type mismatch. So the default for the client request method is application/x-www-form-urlencoded. It could possibly be that the server isn't reading the nested contentType value in the header and falling back on its default. As you'll see here, contentType is it's own standalone property to be passed and read. However, I also see you're using FormData() so you shouldn't have to specify the content type. Have you tried setting application/binary?
0
rajesh parmar
Hello 1264158211509
I have an issue with the POST request using client.request. Here is the code I'm working with:
The issue is that when I make the API call using Axios, like this:
It works fine and returns a response. However, when I call the API using the client.request, the payload doesn’t show up in the browser, and I get a 400 error with the following message:
Can you help me identify what might be wrong with the client.request approach?
0
Tipene Hughes
Can you provide the context of the issue you're running in to plus a screenshot of any errors you are seeing?
Thanks,
Tipene
0
Bruno Leite
I have the same problem. Fahev Dalebig, did you find a solution for this?
0
fahev dalebig
Is there any update or progress on the issue we've raised? We greatly value your assistance and insights in helping us resolve this matter.
Your prompt response and guidance would be greatly appreciated.
Thank you for your attention.
0
fahev dalebig
Hi Zendesk Team,
Is there any update on this matter?
0
fahev dalebig
Hi Zendesk Team,
Is there any update on this?
0
fahev dalebig
Hi Greg Katechis,
is there any update on this, how we can proceed?
0
Sign in to leave a comment.