HTTP Post JSON statement

edited May 2016 in Library Questions

Hi there,

I am relatively new to Processing. What I am trying to do is get processing to send a formated JSON statement to an LRS (Learner registry store). I am using the http.requests library and trying to do a post request.

I thought it would be easy to send the statement like sending it in the body of a normal http post.

import http.requests.*;

PostRequest post = new PostRequest("http:" + "//openlabyrinth.ca/grassblade-lrs/xAPI/statements");
post.addUser("14-******", "****245*******");
post.addHeader("X-Experience-API-Version", "1.0.0");
post.addData("name", "rune");
post.send();
println("Reponse Content: " + post.getContent());
println("Reponse Content-Length Header: " + post.getHeader("Content-Length"));

Then it returns:
Reponse Content: Error: Invalid or empty statement
Reponse Content-Length Header: 33

the formated statement I am trying to send is

{
    "actor": {
        "mbox": "mailto:test@test.ca",
        "objectType": "Agent"
    },
    "verb": {
        "id": "http:// adlnet.gov/expapi/verbs/imported",
        "display": {
            "en-US": "imported"
        }
    },
    "object": {
        "id": "http:// adlnet.gov/expapi/activities/example",
        "definition": {
            "name": {
                "en-US": "Example Activity"
            },
            "description": {
                "en-US": "Example activity description"
            },
            "type": "http:// adlnet.gov/expapi/activities/cmi.interaction",
            "interactionType": "other",
            "extensions": "BMI:76, IBI:657,GSR:1800"
        },
        "objectType": "Activity"
    }
}

Any help would be amazing.

Thanks for your time

Sign In or Register to comment.