+ Reply to Thread
Results 1 to 3 of 3

Thread: REST API through PHP

  1. #1

    REST API through PHP

    Im trying to send a message using php and cURL; I've managed to get the access token but im having trouble with the required format for the request parameter, I no its "Body,ContainsMarkup,From,To" but all i get when i execute the code is an unhelpful "Request Error" page saying "The server encountered an error processing the request. Please see the service help page for constructing valid requests to the service.". Any help would be appreciated.

    /*got $access_token from OAuth reply*/

    $c = curl_init();

    $url = 'http://api.mxit.com/message/send/';

    curl_setopt($c, CURLOPT_URL, $url);
    curl_setopt($c, CURLOPT_POST, true);

    //not sure about "Content-Type" or "Accept"
    $h = array();
    $h [] = "Content-Type: application/json";
    $h [] = "Accept: application/json";
    $h [] = "Authorization: Bearer " . $access_token;
    curl_setopt($c, CURLOPT_HTTPHEADER, $h);

    //what should $requestString look like?!?!?!?!
    curl_setopt($c, CURLOPT_POSTFIELDS, $requestString);
    curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($c, CURLOPT_RETURNTRANSFER, true);


    //execute post
    $result = curl_exec($c);

    echo($result);


    //close connection
    curl_close($c);
    }

    }

  2. #2
    Since you're setting the Content-Type of the request to "application/json", you need to pass a JSON object in the body of the POST request.

    The format's of the JSON body is described on this page:
    http://api.mxit.com/message/help/ope...e#request-json

  3. #3
    I did try that but I had the wrong format for the json object *face palm*; but thanks man i checked it up and i was missing the key word: JSON_FORCE_OBJECT.

+ Reply to Thread

Similar Threads

  1. .NET API and REST API together?
    By rehan in forum Improvements and New Features
    Replies: 9
    Last Post: 14-11-2012, 03:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts