3

I have a raspberry pi that is running a c++ program. It now needs to talk to the Parse.com cloud so it seems the REST API is the best choice. I've been programming for a year and have truly hit a wall here.

EDIT: I've been able to get the code below to run. It successfully posts "south" in a new row under the "direction" column. I had to link my compiler to -lcurl.

My remaining question is how can I in this syntax add conditions to the query? For me the limiting query is WHERE hardwareType = 2.

I can also GET all the results of my parse table if I comment out the CURLOPT_POSTFIELDS line inside curl_easy_init. How can I limit this request with the same query quoted above?

#include <iostream>
#include <curl/curl.h>
#include <string>
#include <sstream>
#include <stdexcept>

using namespace std;

int main()
{
    CURL *curl;
    CURLcode res;

    struct curl_slist *headerlist=NULL;

    headerlist = curl_slist_append( headerlist, "X-Parse-Application-Id: aaaaaaaaaaa");
    headerlist = curl_slist_append( headerlist, "X-Parse-REST-API-Key: bbbbbbbbbbbbbbbb");
    headerlist = curl_slist_append( headerlist, "Content-Type: application/json");
    //headerlist = curl_slist_append(headerlist, "-d '{"direction":"south"}'");

    curl = curl_easy_init();
    if(curl)
    {
        curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
        curl_easy_setopt(curl, CURLOPT_URL, "https://api.parse.com/1/classes/testing");
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "{\"direction\" : \"south\"}");

        res = curl_easy_perform(curl);

        if(res != CURLE_OK){
            fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
        }
    }
}
3
  • 1
    This seems to be a solution, using the full API rather than just curl_easy. PS: When you have a problem, please report the exact error message and you will get more replies. Commented May 14, 2015 at 5:43
  • What is the error that you are getting ? Commented May 14, 2015 at 5:48
  • My apologies Ken Y-N & s_b, I updated my post to reflect it was not an error message, but a blank post to Parse. Ken Y-N, thank you for the link - it did help with some understanding, but I am new to programming and have not had the change to study PHP yet . Commented May 14, 2015 at 22:47

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.