Add Relation Error - REST API - with Thunkable

I am using Thunkable with Backendless and the REST API.
After successfully inserting a new record I am now trying Add a Relation to the Parent Object.
When I do the PUT request to Add the Relation as per the documentation:
https://backendless.com/docs/rest/data_explicit_relation_list.html#example

I get the following error:
{“code”:1043,"message:“Could not parse request body. Please, specify Content-Type:application/json”,“errorData{}}”

There is no error 1043 in the documentation plus I am definitely setting up the Content type header properly as well.
The relationship is as follows:

  1. I have a parent table called “Variety” and a child table called “Batch”.
  2. In the parent table “Variety” I have setup a 1:N relationship (called “Batches”) to the “Batch” table.
  3. After inserting a new “Batch” Record I get it’s objectId.
  4. I already have the parent’s objectId as well
  5. I then execute a PUT request to add the relationship using this type of URL:
    https://xxxx.backendless.app/api/data/<table-name>/<parentObjectId>/<relationName>

ie:
https://xxxx.backendless.app/api/data/Variety/7FB1EDEE-0815-45E1-AE75-3E2E5B3A3653/Batches

And then in the Body I put an array with the child “Batch” objectId (as required) and execute the PUT Request:
[“A164A49C-5F5E-431B-9B9D-A8CAE1DDFF21”]

and then I get the above error.
I have tried various formats in the body, and nothing works.

Please help.

Hello @Tony_B!

Could you please run another test using curl:

curl \  
-H Content-Type:application/json \  
-X PUT
-d "[ \"XXXXX-XXXXX-XXXXX-XXXXX\" ]" \  
https://xxxx.backendless.app/api/data/Variety/parentObjectId/Batches

Regards,
Alexander

Hi Alexander
Thanks for your reply.
I’m just using a straight http request using this:
https://xxxx.backendless.app/api/data/Variety/7FB1EDEE-0815-45E1-AE75-3E2E5B3A3653/Batches
and then including the objectId of the child in the Body of request as follows:
[“A164A49C-5F5E-431B-9B9D-A8CAE1DDFF21”]

I’m not sure how to interpret or use the curl request in Thunkable?

We need to make sure that the request is correct, so I ask you to run it using curl (you can do this in the terminal) or you can also do it in the REST Console:

Regards,
Alexander

Hi Alexander
That does indeed work in the console.

So you need to make sure there is no error elsewhere in your logic, because the query is correct.

Regards,
Alexander

Thanks Alexander
I’ve been through the code again and again and tried all sorts of things but I still get the same error.
So I’m stumped.
I’ve included a snippet of the Thunkable code and it looks like this, after I have Inserted the child item and got both objectId’s of Parent and Child. I use the Notes field and Message Alert in the UI to debug the body and response data in the meantime.

I put the Body data in, as-is. Do I need to convert it or modify it somehow first?
I think it must have something to do with how the body data is formatted or interpreted in the http call?
There is a “generate JSON from object” method which I have tried, when setting the body data as well and that also fails. Any ideas?

Let’s first make sure that the query is correct.
Repeat the query and copy it as a cURL:

Regards,
Alexander

My bad!
I realise now that I was setting the header incorrectly.
I was putting in text that said: Content-Type: application/json.
Instead it should ACTUALLY be a Thunkable object, ie:
image

Thanks for your help!

1 Like