can't create object using REST

I am using REST in Python 3.4 to create a data object in a table Latency. I’m following the documentation but nothing is being added to my table. I have four tables:
Latency
Location
Carrier
Latency
Location
LocationID
LocationCity
Carrier
CarrierID
CarrierName
Here is my curl code:

Popen(['curl', '-H', appid, '-H', secretkey, '-H', apptype, '-H', contenttype, '-X', 'POST', '-d', '{\"ownerId\":%d, \"Location\":{ \"LocationID\":1, \"LocationCity\":\"San Jose, CA\", \"___class\":\"Location\" }, \"Carrier\":{ \"CarrierID\":1, \"Carrier Name\":\"AT&T\", \"___class\":\"Carrier\" }, \"Latency\":%d} % (objectid, curl)', '-v', 'https://api.backendless.com/v1/data/Latency'])

This does absolutely nothing. I have tried removing the variables from the string and have gotten the same result.

Popen(['curl', '-H', appid, '-H', secretkey, '-H', apptype, '-H', contenttype, '-X', 'POST', '-d', '{\"ownerId\":\"1\", \"Latency\":\"250\"}', '-v', 'https://api.backendless.com/v1/data/Latency'])

What am I doing wrong? I know it’s not a problem with the authentication headers since I am able to retrieve the objectId without any problems.
Side question: Does the objectId act as a unique key? Does adding an objectId to an ownerId of another object create a relationship between the two?
Thanks in advance.

Hi Eric,

Would it be possible for you to capture the actual HTTP request? It would make it easier to see where the problem is that way.

ownerId (when assigned) should contain the “objectId” value from an object in the Users table. It is used when you need to load objects which “belong” to a user. You can read more about it here: https://backendless.com/feature-60-loading-data-objects-which-belong-to-the-logged-in-user-owner-policy/

In order to create a relationship, you save an object property with a value as a JSON object which has ___class:tableName assignment.

Regards,
Mark

Mark,

Thanks for replying. So using that method, I would be able to create a relationship between any two tables, correct? I’ve decided to not use the User table altogether.

Here is the HTTP request.

* Trying 52.0.2.178...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Connected to api.backendless.com (52.0.2.178) port 443 (#0)
* TLSv1.0, TLS handshake, Client hello (1):
} [99 bytes data]
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* TLSv1.0, TLS handshake, Server hello (2):
{ [81 bytes data]
* TLSv1.0, TLS handshake, CERT (11):
{ [2708 bytes data]
* TLSv1.0, TLS handshake, Server key exchange (12):
{ [652 bytes data]
* TLSv1.0, TLS handshake, Server finished (14):
{ [4 bytes data]
* TLSv1.0, TLS handshake, Client key exchange (16):
} [134 bytes data]
* TLSv1.0, TLS change cipher, Client hello (1):
} [1 bytes data]
* TLSv1.0, TLS handshake, Finished (20):
} [16 bytes data]
* TLSv1.0, TLS change cipher, Client hello (1):
{ [1 bytes data]
* TLSv1.0, TLS handshake, Finished (20):
{ [16 bytes data]
* SSL connection using TLSv1.0 / DHE-RSA-AES128-SHA
* Server certificate:
* 	 subject: OU=Domain Control Validated; CN=*.backendless.com
* 	 start date: 2013-02-22 19:45:36 GMT
* 	 expire date: 2016-02-22 19:45:36 GMT
* 	 subjectAltName: api.backendless.com matched
* 	 issuer: C=US; ST=Arizona; L=Scottsdale; O=Starfield Technologies, Inc.; OU=[url=http://certificates.starfieldtech.com/repository]http://certificates.starfieldtech.com/repository[/url]; CN=Starfield Secure Certification Authority; serialNumber=10688435
* 	 SSL certificate verify ok.
> GET /v1/data/Request/last HTTP/1.1
> User-Agent: curl/7.41.0
> Host: api.backendless.com
> Accept: */*
> application-id:xxxxxxxxx
> secret-key:xxxxxxxx
> application-type: REST
> Content-Type: applicaton/json
>
< HTTP/1.1 200 OK
< Access-Control-Allow-Headers: origin, application-id, application-type, content-type, secret-key, request, user-token
< Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE
< Access-Control-Allow-Origin: *
< Cache-Control: no-cache
< Cache-Control: : no-store, no-cache, must-revalidate, private
< Cache-control: no-cache="set-cookie"
< Content-Type: application/json; charset=utf-8
< Date: Thu, 30 Apr 2015 16:36:21 GMT
< Expires: Thu, 01 Jan 1970 00:00:01 GMT
< Pragma: : no-cache
< Server: nginx/1.4.7
< Set-Cookie: AWSELB=EFE705250E930025BC0553646066CB6092AE0B3BDDB056937DB3184407DF3C4C0B0296340466DA436574E82E71094B1433911EB2CEB08B9844CFEE2F70B3EB18AFD8CEE2E7;PATH=/;MAX-AGE=9000000
< Content-Length: 481
< Connection: keep-alive
<
{ [481 bytes data]
100 481 100 481 0 0 526 0 --:--:-- --:--:-- --:--:-- 860
* Connection #0 to host api.backendless.com left intact
E4F3FE8B-8138-3759-FF69-9A83AA9D8F00
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 112 0 112 0 0 116 0 --:--:-- --:--:-- --:--:-- 169
Process finished with exit code 0

Hi Eric,

This does not help as the actual payload data is not shows. Try changing the URL for Backendless to: http:// (right now it is https://), perhaps that will let you see what’s being sent on the wire.

Regards,
Mark

Mark,

I found out what was wrong. I had misspelled “Content-Type: application/json”. After fixing it, I was able to add data to one table using the second code above. The first one with relationships still doesn’t do anything. It must be a problem with the syntax. Are you able to see what’s wrong with it? Changing https to http did nothing.

Popen(['curl', '-H', appid, '-H', secretkey, '-H', apptype, '-H', contenttype, '-X', 'POST', '-d', '{\"ownerId\":%d, \"Location\":{ \"LocationID\":1, \"LocationCity\":\"San Jose, CA\", \"___class\":\"Location\" }, \"Carrier\":{ \"CarrierID\":1, \"Carrier Name\":\"AT&T\", \"___class\":\"Carrier\" }, \"Latency\":%d} % (objectid, curl)', '-v', 'https://api.backendless.com/v1/data/Latency'])