I have 2 tables with a 1:1 relationship between them. Country and CountryState. The relationshp is done through the country field of the CountryState table.
I am able to update each table row using the DataBrowser in the console, but I cannot do a bulk update using HTTP POST request of the REST API.
Even the body response returns the number of the updated objects, when I check the DataBrowser again, there is no field changed.
I appreciate your help
BR
Hi Helder,
Could you please show what the bulk update request looks like? (URL, headers, body).
Regards,
Mark
URL: https://api.backendless.com/v1/data/bulk/CountryState
REQUEST:
PUT /v1/data/bulk/CountryState HTTP/1.1
Host: api.backendless.com
application-id: APPLICATION-ID
secret-key: SECRET-KEY
Content-Type: application/json
application-type: REST
Cache-Control: no-cache
{
"country":"889D5CF8-00BE-DAAD-FFD4-DD94B206CD00"
}
Response Body:
16
The URL is missing the “where” query argument.
Also, to update a relation, you need to change the body to:
{
“country” : { “objectId” : “889D5CF8-00BE-DAAD-FFD4-DD94B206CD00”, “___class”:“Country” }
}
Now, I have got an “Unexpected ‘I’” response from the server
Request:
PUT /v1/data/bulk/CountryState HTTP/1.1
Host: api.backendless.com
application-id: E60401CC-DC5A-2D9B-FF4A-ECA4D5782300
secret-key: 8E06AD59-9237-FA65-FF6D-3F2D3B64D300
Content-Type: application/json
application-type: REST
Cache-Control: no-cache
{
"country" : { "objectId" : "889D5CF8-00BE-DAAD-FFD4-DD94B206CD00", "___class":"Country" }
}
Response:
Unexpected 'I'
In my case, I want to update all rows of the table. Should I really include “where” query argument?
BR
PS: I would like to include one information to this case. My first atempt to populate this table was to import the rows using a CSV file.
name, country__Country__bcklsFK__ONE_TO_ONE
ALAGOAS, 889D5CF8-00BE-DAAD-FFD4-DD94B206CD00
AMAZONAS, 889D5CF8-00BE-DAAD-FFD4-DD94B206CD00
BAHIA, 889D5CF8-00BE-DAAD-FFD4-DD94B206CD00
CEARA, 889D5CF8-00BE-DAAD-FFD4-DD94B206CD00
ESPIRITO SANTO, 889D5CF8-00BE-DAAD-FFD4-DD94B206CD00
MARANHAO, 889D5CF8-00BE-DAAD-FFD4-DD94B206CD00
MATO GROSSO DO SUL, 889D5CF8-00BE-DAAD-FFD4-DD94B206CD00
MINAS GERAIS, 889D5CF8-00BE-DAAD-FFD4-DD94B206CD00
PARAIBA, 889D5CF8-00BE-DAAD-FFD4-DD94B206CD00
PARANA, 889D5CF8-00BE-DAAD-FFD4-DD94B206CD00
PERNAMBUCO, 889D5CF8-00BE-DAAD-FFD4-DD94B206CD00
RIO DE JANEIRO, 889D5CF8-00BE-DAAD-FFD4-DD94B206CD00T
For this attempt, the table was populated, BUT without the country field filled.
BR
The URL must contain the “where” argument. Please see the documentation here (scroll down to “Bulk Update”):
https://backendless.com/documentation/data/rest/data_updating_data_objects.htm
Thanks for your feedback. I have got a questions then:
1- How can I retrieve or update the rows where “country” (that is the relationship field) is null?
BR
I have already tried that without success:
https://api.backendless.com/v1/data/bulk/CountryState?where=country.objectId%20is%20null
Complete request:
PUT /v1/data/bulk/CountryState?where=country.objectId%20is%20null HTTP/1.1
Host: api.backendless.com
application-id: E60401CC-DC5A-2D9B-FF4A-ECA4D5782300
secret-key: 8E06AD59-9237-FA65-FF6D-3F2D3B64D300
Content-Type: application/json
application-type: REST
Cache-Control: no-cache
{
"country" : { "objectId" : "889D5CF8-00BE-DAAD-FFD4-DD94B206CD00", "___class":"Country" }
}
Response
Internal server error with id 9C6ACA02-48AE-CD8C-FFA5-9D30B2341E00
Server didn’t like the request. The internal error said “CountryState is specified twice, both as a target for ‘UPDATE’ and as a separate source for data”. I am afraid that update operation would need to be performed in the code with each Country object individually.
Thank you Mark.
So, this is a bug in the platform. Do you intend to fix it?
Regards
Hélder
Hi Helder!
I opened an internal task and we will look into it.
Regards,
Kate.