In Parse.com, Is it possible to receive entire row in the response after making Create Object call instead of receiving the objectId alone.
For example below command
curl -X POST \
-H "X-Parse-Application-Id: qEXLVybHgoqX79zKIpjA2wIGL5suvbVyZDA9Lt4A" \
-H "X-Parse-REST-API-Key: RSJfkl80UCLC24TYqaUjKqJmtoFtRojNRXTVPxMj" \
-H "Content-Type: application/json" \
-d '{"score":1337,"playerName":"Sean Plott","cheatMode":false}' \
https://api.parse.com/1/classes/GameScore
returns output response as
{
"createdAt": "2011-08-20T02:06:57.931Z",
"objectId": "Ed1nuqPvcm"
}
Instead of this is it possible to retrieve entire object in the response?
No, unfortunately the API does not support that (which I have missed on several occasions). You will need to re-fetch the object after it is saved.
Related
I am trying to run a bash script, where I would like to make POST calls in a for loop as follows:
for depId in "${depIds[#]}"
do
echo "$depId" <--------------------------------- THIS IS PRINTING PROPER VALUE
curl 'https://student.service.com/api/student' \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-H 'Cookie: UISESSION=abcd' \
--data-raw '{"name":"Student Name","description":"Dummy","depId":$depId}' \ <---- HERE I CANNOT GET THE VALUE OF THE VARIABLE
--compressed
echo "$content"
done
As mentioned above, I cannot get the value of the department id in the URL, with the above form, I am getting a Request Malformed exception. I have even tried with ${depId}, but no luck.
Could anyone please help here ?
Try flipping your quotes around the variable.
--data-raw '{"name":"Student Name","description":"Dummy","depId":'"$depId"'}' \
I have the following CURL request which pointing to my service:
curl -X POST \
http://go.example.com/ \
-H 'Cache-Control: no-cache' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'Postman-Token: cf0c1ab5-08ff-1aa2-428e-24b855e1a61c' \
-H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
-F fff=vvvvv \
-F rrrr=ddddd \
-F xx=something
I'm trying to catch the xx paramter in classic ASP code.
I tried 'Request("xx")' and 'Request.Form("xx")'.
Do you have any idea?
This is from the CURL documentation
-F, --form
(HTTP SMTP IMAP) For HTTP protocol family, this lets curl emulate a filled-in form in which a user has pressed the submit button. This causes curl to POST data using the Content-Type multipart/form-data according to RFC 2388.
When a form is submitted to Classic ASP using a content-type of multipart/form-data the only method available is Request.BinaryRead() as Request.Form is for application/x-www-form-urlencoded data.
Here is a quick example of calling Request.BinaryRead() to get you started:
<%
'Should be less than configured request limit in IIS.
Const maxRequestSizeLimit = ...
Dim dataSize: dataSize = Request.TotalBytes
Dim formData
If dataSize < maxRequestSizeLimit Then
'Read bytes into a SafeArray
formData = Request.BinaryRead(dataSize)
'Once you have a SafeArray its up to you to process it.
...
Else
Response.Status = "413 PAYLOAD TOO LARGE"
Response.End
End If
%>
Parsing a SafeArray isn't easy
If you want to still use Request.Form you can do by specifying the form parameters in the CURL command using -d instead of -F. From the documentation;
-d, --data
(HTTP) Sends the specified data in a POST request to the HTTP server, in the same way that a browser does when a user has filled in an HTML form and presses the submit button. This will cause curl to pass the data to the server using the content-type application/x-www-form-urlencoded. Compare to -F, --form.
So the CURL command would be something like;
curl -X POST \
http://go.mytest-service.com/ \
-H 'Cache-Control: no-cache' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d fff=vvvvv \
-d rrrr=ddddd \
-d xx=something
You would then retrieve the xx parameter in Classic ASP using;
<%
Dim xx: xx = Request.Form("xx")
%>
Useful Links
application/x-www-form-urlencoded or multipart/form-data?
MSDN - Request.BinaryRead Method
Example class for parsing a SafeArray (specifically the BuildUpload() method which takes a SafeArray and parses the binary)
Example implemenation of a File Uploader class using Request.BinaryRead() on Planet Source Code
I know how to store a string as a variable, for example: API="http://localhost:4741"
However, for the sake of a CURL request I would like to be able to store on object as a variable that I can access values on, something like OBJ="{name : Joe}". Is this possible?
Right now my CURL request looks like this:
curl --include --request POST localhost:3000/scrape \
--header "Content-Type: application/json" \
--data '{
"url": "http://www.oddsshark.com/stats/gamelog/basketball/nba/20736",
"team": "LA Clippers"
}'
I would like to be able to do something like this, using a dictionary or an object:
TEAM=( ["Clippers"]="http://www.oddsshark.com/stats/gamelog/basketball/nba/20736" )
curl --include --request POST localhost:3000/scrape \
--header "Content-Type: application/json" \
--data '{
"url": "http://www.oddsshark.com/stats/gamelog/basketball/nba/20736",
"team": "${TEAM[Clippers]}"
}'
I use curl to query data from Parse, like this:
curl -X GET \
-H "X-Parse-Application-Id: xxxxxxxxxxxx" \
-H "X-Parse-REST-API-Key: xxxxxxx" \
https://api.parse.com/1/classes/TestObject
and it always return {"results":[]}. But I could GET 'https://api.parse.com/1/users' successfully.
I"m using the following commands which i've copied over from the documentation. Assume that I'm passing in the application id and keys in each curl statement for brevity.
create player
curl -X POST \
-d '{"name":"abhinav", "rank" :"amazing"}' \
https://api.parse.com/1/classes/Player
Player objectId: HgMZF6H90L
Create game and add pointer relation
curl -X POST \
-d '{"Level" : "TWO"}' \
https://api.parse.com/1/classes/GameScore
GameScore objectId: cwYIEwFaq9
curl -X PUT \
-d '{"opponents":{"__op":"AddRelation","objects":[{"__type":"Pointer","className":"Player","objectId":"HgMZF6H90L"}]}}' \
https://api.parse.com/1/classes/GameScore/tDiFZSE0lQ
Now I check from the Data browser and the GameScore object has a field with Relation. clicking on the "View Relations" navigates me to the correct list underneath. Working fine except that it says "Relation" and not pointer. Not sure if that is relevant
HOWEVER, I'm not able to query this information from the REST API. A GET results in the relation data but no objectId for the player available.
curl -X GET \
https://api.parse.com/1/classes/GameScore/cwYIEwFaq9
result:
{"Level":"TWO","createdAt":"2014-06-11T08:49:43.325Z","objectId":"cwYIEwFaq9","opponents":{"__type":"Relation","className":"Player"},"updatedAt":"2014-06-11T08:51:01.093Z"}
tried with include option but that results in some error
curl -X GET \
--data-urlencode "include=opponents" \
https://api.parse.com/1/classes/GameScore/cwYIEwFaq9
result:
code 107, invalid JSON
What am I doing wrong?
why are you using "Remove" to add a relation? Look at the docs again.
go to Docs section "Creating Roles" again....
"__op": "AddRelation",
"objects": [
{
"__type": "Pointer",
"className": "_Role",
"objectId": "Ed1nuqPvc"
}
]
-- EDIT
to get using "include=opponents" you could create with this:
{"opponents":{"__op":"Add","objects":[{"__type":"Pointer","className":"_Role","objectId":"Ed1..."}]}}
Solved :
The problem is that i needed to create an array of pointers. So instead of the "AddRelation", i simply need to use the "AddUnique" operation to create an entry for the array. So
curl -X POST \
-d '{"Level" : "TWO", "opponents":{"__op":"AddUnique","objects":[{"__type":"Pointer","className":"Player","objectId":"5Q4QsKF8QR"}]}}' \
https://api.parse.com/1/classes/GameScore