Parse-server cloud code function 'Cannot POST'
Asked Answered
W

2

8

Most parts of my migration to open source parse-server are successful, with my data correctly stored, accessible.

I am however having problems with cloud code, specifically with running simple curl tests.

The initial parse-server installation includes a sample main.js file that contains a hello world function

My own parse installation is hosted at '/parse' so URLs use this as the root

The following is a simple request test

 curl -X POST \   
 -H "X-Parse-Application-Id: myAppId" \   
 -H "X-Parse-REST-API-Key:myRESTKey" \   
 -H "Content-Type: application/json" \   
 -d '{}' \  
 http://localhost:1337/parse/1/functions/hello

The response I get is

Cannot POST /parse/1/functions/hello

Which I take to be curls perfunctory statement that it cannot find a suitable POST endpoint

What is going wrong here? I have simply changed the sample curl example from Parse.com's documentation on using cloud-code to use my parse-server installation details

Whiteeye answered 19/2, 2016 at 11:32 Comment(3)
The Cannot POST /parse/1/functions/hello looks like a response from the server, not something curl said. Possibly adding -v to the command line helps you with some more clues. (and the "-X POST" part should be removed)Menjivar
Yes, correct the message is a response from the server that an end point cannot be found. The answer works as describedWhiteeye
how do I make the parse client js sdk make the calls without the /1?Freewheeling
W
14

The answer is that unlike with Parses hosted solution the API version path is not something hosted with parse-server

if you host parse at e.g.: /parse as I have done above, then that is the relative URL where the functions API is available. So simply remove the /1/ from the path

The same curl command works with this URL

http://localhost:1337/parse/functions/hello

eg:

curl -X POST \   
-H "X-Parse-Application-Id: myAppId" \   
-H "X-Parse-REST-API-Key:myRESTKey" \   
-H "Content-Type: application/json" \   
-d '{}' \  
http://localhost:1337/parse/functions/hello
Whiteeye answered 19/2, 2016 at 11:36 Comment(0)
A
0

I applied the "hello post" logic below to run a function that is defined in Parse Open Source cloud code in main.js hosted on heroku. I am trying to replace a former job that ran on parse.com. Started with Curl to try and be able to run function at will.

error: Cannot GET /parse/functions/sendOutboundProgressReport STATE: PERFORM => DONE handle 0x6000578c0; line 1981 (connection #2) multi_done Curl_http_done: called premature ==0 Connection #2 to host test-fake-app.herokuapp.com left intact Expire cleared


curl -v POST \

-H 'X-Parse-Application-Id: sadf435hsdgfatea' \ -H 'X-Parse-Master-Key: asdfsaasdfae4235dsgd' \ -H 'REST_KEY': asdfasq435636 \ -H "Content-Type: application/json" \ -H "X-Parse-Url: http://test-fake-app.herokuapp.com/parse" \

-d @send-template.json \

http://test-fake-app.herokuapp.com/parse/functions/sendOutboundProgressReport

Athome answered 20/4, 2017 at 18:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.