Curl

From Freebase

Jump to: navigation, search

Writing to Freebase from the command line using curl

This example logs into Sandbox and creates "Test Object 1" of type testobject. Since the Test Object 1 already exists, the graph won't actually be changed.

USERNAME='XXXXX'
PASSWORD='YYYYY'                                   # Use your freebase login details
API='http://api.sandbox-freebase.com/api'          # test on sandbox-freebase before using freebase.com
USER_AGENT='MyCommandLineApp myemail@example.com'  # so metweb can get in touch if something is going wrong

# Authenticate (only once)
curl -c cookies.txt -d "username=$USERNAME" -d "password=$PASSWORD" $API/account/login

QUERY='{"query":{"create":"unless_exists","name":"Test Object 1","type":"/base/mqlexamples/testobject","id":null,"guid":null}}'

# Do the write
#  (X-Requested-With must be set)
curl -b cookies.txt -H 'X-Requested-With:curl' --user-agent "$USER_AGENT" -d "query=$QUERY" "$API/service/mqlwrite"

Personal tools