I'm trying to access the Google Classroom API with Javascript and am running into a syntax problem when trying to create a student.
The relevant code is
function createStudent () {
var course_id = '146694xxx'
var enrollment_code = '7ytxxx'
var student = {
userId: 'xxx#gmail.com'
}
student = gapi.client.classroom.courses.students.create({courseId:course_id,enrollmentCode:enrollment_code, params: student}).execute();
}
The problem is with the named parameter for the student object. It is where I have "params". I have tried every name I can think of like requestBody, body and a million others. The error I get is
{
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name \"params\" at 'student': Cannot find field.",
"status": "INVALID_ARGUMENT",
"details": [
{
"#type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"field": "student",
"description": "Invalid JSON payload received. Unknown name \"params\" at 'student': Cannot find field."
}
]
}
]
}
}
How should I be representing that request body object in the call?
Thanks.
Harry
Related
I am trying to query some data from a contentful API using gatsby's built-in graphiQL.
EDIT: after a suggestion from the comments, I made a introspection query to get the schema information:
{
"name": "contentfulStranNaslovQueryString_2",
"kind": "INPUT_OBJECT"
}
When I run this query:
{
contentfulStran {
id
naslov
}
}
I get the expected result (the first entry for the data model):
{
"data": {
"contentfulStran": {
"id": "c2tD44y2tDe8QC4yqkwMOgo",
"naslov": "Novice"
}
}
}
But now I would like to pass in a query parameter that only gets data specified on the naslov field. I tried this:
{
contentfulStran(naslov: "Ponudba") {
id
naslov
}
}
But I am getting the following error:
{
"errors": [
{
"message": "Argument \"naslov\" has invalid value \"Ponudba\".\nExpected \"contentfulStranNaslovQueryString_2\", found not an object.",
"locations": [
{
"line": 2,
"column": 27
}
]
}
]
}
What am I doing wrong?
Miha answered his own question in the comments. The correct way to filter is:
{
contentfulStran(naslov: {eq: "Ponudba"})
{
id
naslov
zaporedje
tekst
{
tekst
}
}
}
Note the {eq: "param"} object instead of just giving the param.
I'm fetching product details using an API which gives the response as a JSON object.
{
"productBaseInfo": {
"productIdentifier": {
"productId": "EKTDDD23232zYHR94E4",
},
"productAttributes": {
"title": "Nova KT 72BC 1 Electric Kettle",
"imageUrls": {
"400x400": "http://img5a.flixcart.com/image/electric-kettle/4/e/4/nova-kt-722-c-kt-722c-400x400-imadddh2fdvuzpxz.jpeg",
"75x75": "http://img6a.flixcart.com/image/electric-kettle/4/e/4/nova-kt-722-c-kt-722c-75x75-imadddh2fdvuzpxz.jpeg",
},
"sellingPrice": {
"amount": 599.0,
"currency": "INR"
},
"productUrl": "http://dl.mykart.com/dl/nova-kt-722c-1-electric-kettle/p/itmdddf398rhhhz2?pid=EKTDDDEGXYHR94E4&affid=userid"
}
}
}
Now I want to get the productId, title in ProductAttributes, and all the image urls and productURL.
I tried
var productURL = JSON["productAttributes"].productUrl
But it returns an error productUrl not found error. Looking for suggestion on how to extract the data. Thanks in advance.
productAttributes is inside productBaseInfo. So you need to access it like this
console.log(JSON.productBaseInfo.productAttributes.productUrl);
// http://dl.mykart.com/dl/nova-kt-722c-1-electric-kettle/p/itmdddf398rhhhz2?pid=EKTDDDEGXYHR94E4&affid=nikhilgeo
I'm trying to update a JSON file with the value of a textarea using jquery push. I'm receiving the following error: " JavaScript runtime error: Unable to get property 'push' of undefined or null reference"
My jquery:
function submittedMsg(ctx) {
var id = $('.msg-input form').attr('id');
var newMsg = $('.msg-input textarea').val();
var url = "/ajax.aspx?vtl=ajax-conversation-json&cv=" + id;
$.getJSON(url, function (messageString, message) {
var message = [];
message.push({
msgcontent: newMsg,
sendname: sendRname,
mbrhref: mbrUrl,
datetime: ""
});
});
}
My JSON:
{
"messageString" :
[
{ "subject": "hello",
"msgstring": "5",
"unread": "1",
"datetime": "Oct 1 2013 9:59PM",
"orderid": "17",
"recipient": [
{
"mbrname": "Jane Doe",
"mbrhref": "/profile.aspx?mem=1227"
},
{
"mbrname": "John Smith",
"mbrhref": "/profile.aspx?mem=1337"
}
],
"message": [
{
"datetime":"2013-10-01T21:59:33.063",
"sendname":"Jane Doe",
"mbrhref":"/profile.aspx?mem=1227",
"msgcontent": "<p>Hi. I would like to talk with you about Dwarf Beryl Beauty</p>"
},
{
"datetime":"2013-11-26T16:29:17.037",
"sendname":"John Smith",
"mbrhref":"/profile.aspx?mem=1337",
"msgcontent": "Tough luck."
}
]
}
]
}
I don't necessarily need to use push to update the JSON file if there is a better way, I'm open to suggestions. I've verified my URL path is correct. Am I just missing something obvious? I'm new to JSON and only have passable jquery skills. Help!
Thanks in advance for any direction.
Try to use:
data.message.push
instead of:
data.messageString.message.push
Ah I see the issue, you have a local var and parameter of the same name message:
$.getJSON(url, function (messageString, message) { //here is param message
var message = []; //here is a local var parameter
message.push({ //this is probably referencing the parameter which is not an array or object that supports .push
Instead:
$.getJSON(url, function (data) { //I renamed the param to be more consistent with documentation, although it doesn't really matter, just will generate confusion
data.messageString.push({ //modify the json we were passed in the data param
I am new to programming and would like to send a template via the mandrill api. Sending a message works fine.
What do I have to change in my code to send a template?
In the mandrill documentation I see that I can call a template I have stored in my account with this
"template_name": "example template_name",
But I don't know how to integrate this properly in my code below.
I would appreciate any help you can give. For the purpose of understanding the easiest would be if you can show me how the code would have to look in order to send the template.
function log(obj) {
$('#response').text(JSON.stringify(obj));
}
var m = new mandrill.Mandrill('API Key');
var params = {
"message": {
"from_email":"example#domain.com",
"from_name": "FromExampleName",
"to":[{"email":"recipient1#domain.com", "name": "Name of Recipient"}],
"subject": "Mandrill API Test",
"html": "Sending a template doesn't work."
}
};
function sendTheMail() {
m.messages.send(params, function(res) {
log(res);
}, function(err) {
log(err);
});
}
it's solved.
The template has to be included like this
var params = {
"template_name": "templatename",
"template_content": [
{
"name": "example name",
"content": "example content"
}
],
"message": {
"from_email":"example#domain.com",
"to":[{"email":"recipient#domain.com}],
"subject": "Subject line",
"text": "text in the message"
}
};
Then send like this
function sendTheMail() {
// Send the email!
m.messages.sendTemplate(params, function(res) {
log(res);
}, function(err) {
log(err);
});
}
I am trying to send message to Linked connections,how can send the message to 10 recipients and avoid the recipient to see the other recipients.
what is the property to add to Body Object??
var BODY = {
"recipients": {
"values": [
{
"person":
{
"_path": "/people/~",
}
},
{
"person":
{
"_path": "/people/RJO-_FYNp-",
}
},
{
"person":
{
"_path": "/people/U-GyYIV2ZU",
}
}
]
},
"subject": "Time line Cloud",
"body": "Hi All this is a test message im trying to use LinkedIn API and im so sorry if i bother you.\n http://goo.gl/OUvDP"
}
IN.API.Raw("/people/~/mailbox")
.method("POST")
.body(JSON.stringify(BODY))
.result(function error(e) { alert("Done"); })
.error(function error(e) { alert("Error"); });
There is no BCC setting for the member to member messages via the API at this time. You would need to send multiple messages, each to one person.