REST Example Phonebook Relations[Documentation error]

Hi, I’m studying on page 78 of the document Relations .
in curl I execute the following command , but I get this error :

curl \
-H application-id:xxx \
-H secret-key:xxx \
-H application-type:REST \
-H Content-Type:application/json \
-X POST \
-d @"{\""owner\"":{\""phone\"":\""214-555-1212\"",\""name\"":\""Bob\"", \""title\"": \""Chief Spy\"", \""age\"":30, \""___class\"":\""Contact\"", \""address\"":{\""street\"": \""123 Main St\"", \""city\"":\""Dallas\"", \""state\"":\""TX\"", \""___class\"": \""Address\""}}}"; \
-v https://api.backendless.com/v1/data/PhoneBook



how do i fix?


Warning: Couldn't read data from file 
Warning: "{"owner":{"phone":"214-555-1212","name":"Bob", "title": "Chief", 
Warning: this makes an empty POST.
curl: (3) [globbing] unmatched brace in column 49
curl: (6) Could not resolve host: Main
curl: (3) [globbing] unmatched close brace/bracket in column 58
-bash: -v: command not found


thanks
regards
Riccardo

Hi Riccardo,

What does this tell you:?

-bash: -v: command not found

Mark

ok , I have corrected the command like this:

curl \

-H application-id:xxx \
-H secret-key:xxx \
-H application-type:REST \
-H Content-Type:application/json \
-X POST \
-v 'https://api.backendless.com/v1/data/PhoneBook'\
-d @"{\"owner\":{\"phone\":\"214-555-1212\",\"name\":\"Bob\", \"title\": \"Chief Spy\", \"age\":30, \"___class\":\"Contact\", \"address\":{\"street\": \"123 Main St\", \"city\":\"Dallas\", \"state\":\"TX\", \"___class\": \"Address\"}}}"

Error:
HTTP/1.1 400 Bad Request

 
 
 
 
 
 
 
 
 
< Server: nginx/1.8.1 
 
< Date: Mon, 29 Aug 2016 19:53:47 GMT 
 
< Content-Type: application/json 
 
< Content-Length: 76 
 
< Connection: keep-alive 
 
< 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, PATCH 
 
< Access-Control-Allow-Origin: * 
 
< 
 
* Connection #0 to host api.backendless.com left intact 
 
{"code":8002,"message":"Could not parse request with message: Invalid Json"}curl: (3) [globbing] nested brace in column 11 
 



in the documentation , the json is wrong!..

You can supply the correct command ?, otherwise I do not understand the operation .

thanks

regards

Riccardo

I just ran this request and it worked just fine for me:

curl -H application-id:MYAPPID -H secret-key:MYSECRETKEY -H Content-type:application/json -X POST -d “{ “owner”:{“phone”:“214-555-1212”,“name”:“Bob”, “title”:“Chief Spy”, “age”:30, “___class”:“Contact”, “address”:{“street”:“123 Main St”, “city”:“Dallas”, “state”:“TX”, “___class”:“Address”}}}” http://api.backendless.com/v1/data/PhoneBook

It is a little difficult to write the json without mistakes , thus \
What can help me to understand the operation ? …

sorry, but i’m using curl from my shell(mac)…
I copied your request , but :









{"code":8002,"message":"Could not parse request with message: Invalid Json"}curl: (3) [globbing] nested brace in column 11



using your console , the body as a request must be written ?.
Excuse me trivial questions , but I never dealt with these issues .

i tried:

{ \"owner\":{\"phone\":\"214-555-1212\",\"name\":\"Bob\", \"title\":\"Chief Spy\", \"age\":30, \"___class\":\"Contact\", \"address\":{\"street\":\"123 Main St\", \"city\":\"Dallas\", \"state\":\"TX\", \"___class\":\"Address\"}}}

Request body is invalid!..

Hi Riccardo,

The https://api.backendless.com/v1/data/PhoneBook part should be the last in your command and not enclosed in quotes.

Try to copy-paste from Mark’s post above, it should work exactly as is (just change app id and secret key to your ones ofc).

hi Sergey,sorry but, for example
to create a user do ( syntax mac os x ) :

REGISTRATION

curl \
-H application-id:xxx \
-H secret-key:xxx \
-H Content-Type:application/json \
-H application-type:REST \
-X POST \
-v 'https://api.backendless.com/v1/users/register' \
-d '{"email":"john.smith@foo.bar", "name":"John", "password":"123456seven"}'


This is successful!

I will try to use postman tool to make the request .

from your console as I have to write the request body ?

thanks

ok,
It works ok !! Thank you

ok I changed the application in my program , successful but returns 404 - not found message.

my json raw from my application:

	string json = @"{\""owner\"":{\""phone\"":\""214-555-1212\"",\""name\"":\""Bob\"", \""title\"": \""Chief Spy\"", \""age\"":30, \""___class\"":\""Contact\"", \""address\"":{\""street\"": \""123 Main St\"", \""city\"":\""Dallas\"", \""state\"":\""TX\"", \""___class\"": \""Address\""}}}";

i solved!..

thanks