patch request using axios fail in directusCMS - reactjs

i am trying to send a patch request to update or maybe change the image in directus CMS.. (changing it require only id of the item and the file which is already solved.. in this link
Make Multiple Post Requests In Axios then get all the response to make another request)
below is the simplified code of it because the thing i am trying to achieve is making an item that have name, email, date, etc. then sending file or an image to the files ..
then i need to patch the item that i just made which is where i am not able to do yet..
for information only.. i am using gatsbyjs..
i have already tried it in postman and it works.. maybe there is something wrong with my code. thanks..
axios.patch( `${process.env.GATSBY_DIRECTUS_API_URL}/gemaclc/items/pendaftar/49?access_token=${process.env.GATSBY_DIRECTUS_TOKEN}`, {
data: JSON.stringify( {
kartu_keluarga: 1,
}),
})

i deleted JSON.stringify and it works
axios( `${process.env.GATSBY_DIRECTUS_API_URL}/gemaclc/items/pendaftar/50?access_token=${process.env.GATSBY_DIRECTUS_TOKEN}`,
{
method:"patch",
data :{
kartu_keluarga: 1,
nama: "zidsadanaaa"
},
}
)

Related

Cypress testing and waiting for axios requests

Can anyone explain how or why my test isn't waiting for my data from an axios request before moving on? I'm completely new to this but have most simple stuff worked out but can't seem to navigate the docs to find where i'm going wrong.
Here's the relevant info..
cy.get('.day').eq(4).click() //Change the day
cy.route('/api/practice/available-slots').as('apiCheck') //Get available slots for that day
cy.wait('#apiCheck') //Wait for the days available slots to be returned
So you can see below I click the fourth day and my post URL is showing and getting data like it normally does but then my wait function throws that error. I like to think i'm close but as I said i'm new and not entirely sure what's going wrong. Thanks
For what it's worth here's the axios request:
axios
.post(this.props.reqProto + this.props.reqHost + '/api/practice/available-slots', {
startDate: this.state.appointmentSlotsDate,
})
.then((res) => {
....
}
})
Thanks Hiram,
That was one issue. Also the order of my code was incorrect. I need to allow cypress to anticipate the POST request instead of it trying to double back to it. This seems to work
cy.route({
method: 'POST',
url: '/api/practice/available-slots',
}).as('apiCheck')
cy.get('.day').eq(4).click()
cy.wait('#apiCheck')

How to update a record in react native

I am using firebase to store my data. When I am adding or getting data, there is no problem. But I can't update an existing report. For example, I have notes. And user can open a note, edit and save. On save, it should save the changes on existing record. But I can't do that.
Here is how I tried.
fetch('https://shared-places-***.firebaseio.com/notes.json/' + this.state.updatedNote,{
method:'POST',
body: JSON.stringify({
Header: this.state.newNoteHeader,
Explanation: this.state.newNoteSub,
Date: new Date(),
})
})
.then(res => console.log(res))
.catch(err => console.log(err))
I have added my id to request link hoping I directly effect it but it didn't work. Also tried changing method to Update but also didn't work of course. I have searched but couldn't find an answer.
Thank you in advance.
I have found the answer that I was making small mistakes. First of all, method should be PUT not POST. Also address should be https://shared-places-***.firebaseio.com/notes/' + this.state.updatedNote + '.json'

Restangular DELETE request, send data in body

I am using restangular to send DELETE request.
I send some data in the request, and data is added to query string. But I want to use body instead of URI. I've found this question on stackoverflow. Mgonto said, that this problem can be resolved, by using customDELETE method.
I've tried something like this:
Restangular.all("all").customDELETE("one", {
firstParam: 1,
secondParam: 2
});
Unfortunately parameters still sent in the URI.
Is there any way to send parameters in body?? Like in POST request??
My teamlead helped me to find a solution!
We can use customOperation to send data in body of our request.
Here's an example:
Restangular.all("all/one").customOperation("remove", null, null, {
firstParam: 1,
secondParam: 2
});
It works fine for me!
Hope it'll help someone!

"Failed to parse UUID" error message on attempting to login via TrueVault api

On attempting to login via the truvault api using angular js, I am getting this error message: Failed to parse UUID. I am passing the username, password and account_id as params. I am successful using the curl command and get the success response.
The 400 error is not described in the api docs for authorization. I am not sure about if this UUID is linked to the schema_id. Would anyone (truevault guys!!) know what I am doing wrong?
I contacted truevault support on this one. Dan helped me get through it.
I was passing the username/password/account_id as url string query parameters. I had to make two changes to the code:
1. Pass the above as form data parameters
2. add the angular-post-fix.js to my project.
(Note: I am not adding the link as there are editors who will disallow the post with links to elsewhere. It has happened in the past!)
When using Node.js, the querystring API is really useful. Just pass an object to the querystring.stringify() function, and the resulting output is ready to be sent to TrueVault for login.
Additionally, I found that adding the header 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8' might be necessary (which is one of the things the Angular post-fix library does).
#orthodoc is right, but is kind of tricky how to actually build the request. Lets say we are using fetch with formData params, I'd like to add an example of a successful request:
...
var formData = new FormData();
formData.append('username', username);
formData.append('password', password);
formData.append('account_id', accountId);
return fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8'
},
body: formData
});
...

Connection between Playframework and ExtJs

I am doing a project were I am trying to make the backend with playframework and the frontend with Extjs.
I can retrieve the data from the server with Json and show it in a grid with all it's fields.
The problem comes when I try to modify, remove or add any record.
The request sent by Ext: DELETE lista?_dc=1318409614652
(I solved _dc with "noCache: false" over the proxy)
The request right now is: DELETE lista
The request I need is: DELETE lista/"parameter of the object like ID or name"
Do you have any idea about this? If you need any information let me know
Thanks in advance!
I suppose you are not yet using the Rest proxy (of ExtJS) for this, but you should, as it does exactly what you are asking for. You set it up with an url like /lista in your case. Now, when you delete a record, the proxy automatically sends a DELETE request to the url, appending it with the id. Check out the documentation (linked above) for more info - you can control the url generation a little bit, but in your case it looks like you can do with the default options.
even if you don't want to use Rest Proxy, you use still use Ext.Ajax.request like below.
Ext.Ajax.request({
waitMsg: "Saving... Please wait",
url: "myserverscript.php",
method: "POST",
params: {
action: "delete",
id: myForm.down('#id').getValue(),
data: jsonData
}
});

Resources