Directus delete Item by ID - directus

How can you delete a item via Api in Directus?
According to the doku the path would be:
DELETE /items/:collection/:id
I tried this but only got an error:
DELETE /items/parking_reservations/61
"errors": [
{
"message": "\"value\" must contain at least one of [query, keys]",
"extensions": {
"code": "FAILED_VALIDATION"
}
}
]

You can delete an item via the API in Directus using the DELETE method. You can perform this action by sending a request with the item's id to the items endpoint. For example, if you wanted to delete an item with the id of 42, you would send a DELETE request to the following endpoint: /api/1.1/tables/<table_name>/rows/42.

Related

Shopware 6 Admin Api - Updating existing record through patch method. Not working

shopware 6 admin api patch - why it's failing? I get error "Only single write operations are supported"
Following is api for rule-condition entity in the database, I update it with Id.
For same api get method is working!
url: api/rule-condition/dbb0d904c7c14860a9a94cf26b94eca6
method: patch
json body
[
{
"op": "replace",
"path": "/data/attributes/value/email",
"value": "test#gmail.com"
}
]
response:
{
"errors": [
{
"code": "0",
"status": "400",
"title": "Bad Request",
"detail": "Only single write operations are supported. Please send the entities one by one or use the /sync api endpoint.",
.......
I also tried changing json body to following
{
"data": {
"attributes": {
"value": {
"email": "test#gmail.com"
}
}
} }
Still it's not updating. Can somebody check and let me know what am i missing?
Documentation I followed:
https://shopware.stoplight.io/docs/admin-api/ZG9jOjEyMzA4NTQ5-writing-entities
This website has all apis and example methods. https://swagger.docs.fos.gg/,
rule-condition entity can also be found there.
Btw : I used postman for testing api
You're passing an array of objects in the request body, suggesting you want to update multiple records, but the endpoint only supports updating a single record. The correct payload in your case should look like this:
{
"value": {
"operator": "=",
"email": "test#gmail.com"
}
}
Notice that value is a json field and not only includes a single value. The exact content and the names of the properties of value depend on the type of condition used and usually it also includes the operator used in the condition.

Shopware Product API response with no content and error 204 (No Content) Error

So while trying to test how to create a product, with as minimal data as possible, using the Shopware 6 API i get a Status 204 (No Content) response with an empty response.
When i press "Send" again i get a Status 400 error with this message:
{
"errors": [{
"status": "400",
"code": "CONTENT__DUPLICATE_PRODUCT_NUMBER",
"title": "Bad Request",
"detail": "Product with number \u002212345667891\u0022 already exists.",
"meta": {
"parameters": {
"number": "12345667891"
}
}
}]
}
When i check the Shopware Backend and search for the product, i get no result.
When i try searching the MySQL Product-Tables i get no result aswell.
Iam using this site: https://reqbin.com/
And I call the URL: https://www.my-url.de/api/product via POST Request.
As authorization i use a bearer token i grab from the getToken GET-Request.
My Request-Content looks like the following:
{
"name": "Aarons Testartikel of Doom",
"taxId": "f68a9c3c86864c2ea7597062fc457cf7",
"price": 3,
"productNumber": "12345667891",
"stock": 5,
"active": true
}
The 204 status code you get on your first request indicates that the request was handled successful. According to the HTTP-Standard all 2xx status codes can be considered successful. Shopware by default returns a 204 - No Content with en empty response body to all write requests over the API, but you can provide a _response query parameter to your POST-Request and Shopware will return a 200 response with the same data you'll get if you make a GET-Request to read the data of the added product.
In your case the URL would be https://www.my-url.de/api/product?_response=1.
The reason for the Error on the second request is that the product number needs to be unique, so you can't add another product with the same product number. Changing the product number before you do the second request should work again.
The Error also indicates that the first Write-Request was indeed successful, to make sure that your shopware installation is connected to the Database you think it is, you can check the .env file in the root folder of your installation, there should be a DATABASE_URL variable defined.

Magento 2 Rest API Can't Remove Category ID's from product

I am working on a REST API call which will remove the category ID from a live product. The below code returns true but this has not updated in the back end or on the site.
I have followed the magento documentation for the update request and that works well, I tried doing the inverse of that with the delete request and following some examples online.
The below method is DELETE.
If someone can advise how this category can be removed then please advise.
{
"product": {
"sku": "MRO2222",
"status": "0",
"category_links": [
{
"position": 100,
"category_id": "8"
}
]
}
}
Unfortunately there doesn't seem to be a proper way through a delete request with Magento Rest API.
The way to go is to unset the categories of the product and update with the desired categories afterwards.
You can unset the categories with a PUT request to endpoint:
https://www.yoursite.com/rest/all/V1/products/your_product_sku (replace url and sku)
with payload:
{
"product":{
"extensionAttributes":{
"category_links":[
]
}
}
}

Google Sheets API not accepting my API Key

I generated an API key through Google Developer's Console. I am trying to read data from a Google Sheet.
However when I do a GET request using the following link:
https://sheets.googleapis.com/v4/spreadsheets/1nUeRttOMn--b46Vt7FIlU_eoOqvvuOyukAEg2L_UGQQ/values/A1%3AF500?key={abcdefghijklmnopqrstuvwxyz0123456789}`
I get the error message:
API key not valid. Please pass a valid API key.
Full error:
{
"error": {
"code": 400,
"message": "API key not valid. Please pass a valid API key.",
"status": "INVALID_ARGUMENT",
"details": [
{
"#type": "type.googleapis.com/google.rpc.Help",
"links": [
{
"description": "Google developers console",
"url": "https://console.developers.google.com"
}
]
}
]
}
}
My API Key is valid. How can I resolve the error? I plan to make the API call via Alteryx.
Use this URL:
https://sheets.googleapis.com/v4/spreadsheets/PUT YOUR SHEET ID HERE/values/PUT YOUR SHEET NAME HERE (sheet name not spreadsheet name)?key=PUT YOUR API KEY HERE
I was going through the same error. The Key was valid and I even changed the keys but it was not working.
Here's what I did,
Before the error, it looked like this...
https://sheets.googleapis.com/v4/spreadsheets/PUT YOUR SHEET ID HERE/values/Sheet1?valueRenderOption=FORMATTED_VALUE&key=PUT YOUR API KEY HERE/HTTP/1.1
Then I removed the last bit and got the valid response.
https://sheets.googleapis.com/v4/spreadsheets/PUT YOUR SHEET ID HERE/values/Sheet1?valueRenderOption=FORMATTED_VALUE&key=PUT YOUR API KEY HERE
Worked like a charm!

Can we add multiple labelId in history.list API for gmail?

I want to get the result of all INBOX mails and all SENT mails in one API call using the historyID and the history.list Gmail-API.
Refer:
https://developers.google.com/gmail/api/v1/reference/users/history/list
When I am hitting the following GET request :
https://www.googleapis.com/gmail/v1/users/{userID}/history?startHistoryId={historyID}&labelId=SENT&labelId=INBOX
I only get the SENT label messages.
Seems like the API only accepts single & first query param for labelId.
Is there a way to get multiple labelIds' response in a single API call?
I think it would not be possible, I tried making a multiple request and it this response:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalidArgument",
"message": "Invalid label value in query"
}
],
"code": 400,
"message": "Invalid label value in query"
}
}
I would suggest to call it separately for each labelID but you can try filing a feature request for this.
Hope this helps.