Error in Targeting Company Shares Using JSON - json

I'm trying to Target company shares (https://developers.linkedin.com/documents/targeting-company-shares) using json with LinkedIn Rest Api.
My JSON object (https://developers.linkedin.com/forum/targeting-example-using-multiple-targeting-parameters-and-json) looks like :
{
"visibility": {
"code": "anyone"
},
"comment": "Targeting Shares",
"share-target-reach": {
"share-targets": {
"share-target": [{
"code": "geos",
"tvalues": {
"tvalue": "as"
}
}, {
"code": "companySizes",
"tvalues": {
"tvalue": "201-500"
}
}]
}
}
}
But this isn't working, i'm getting the following error :
{
"errorCode": 0,
"message": "Malformed json document. Encountered unexpected array.",
"requestId": "DRWYRUVMBJ",
"status": 400,
"timestamp": 1423283491818
}
I'm not able to figure out where's the problem??

I have been playing around with this for awhile now and near as I can tell the below format will work. Basically you have to remove all the arrays, I have tried them at every level and they always cause the malformed json error. I still have no idea how to target multiple sections at once though, since the official documentation on this is very wrong. The only way I figured this part out is by doing a whole lot of guessing.
{
"visibility": {
"code": "anyone"
},
"comment": "Targeting Shares",
"share-target-reach": {
"share-targets": {
"share-target": {
"code": "geos",
"tvalues": {"tvalue": "as"}
}
}
}

Related

Why can't I submit a record to Zoho Sales Order API?

I'm trying to insert a record using the Zoho API, and I keep receiving a cryptic INVALID_DATA error message.
I've tried using their sample code which, of course, produces another error. And the sample code they provide for running in Postman also produces an error.
Their docs are lacking and inconsistent, and nobody is getting back to me on their message boards, and I'm getting desperate as I need to have this done today. Can anyone see what I'm doing wrong?
This is what I'm submitting via Postman
{
"data": [
{
"Owner": {
"id": "3938209039489388001"
},
"Contact_Name": {
"id": "398129039938498309"
},
"Subject": "Test",
"Product_Details": [
{
"product": {
"id": "1234567"
},
"quantity": 1
}
]
}
]
}
This is the error response
{
"data": [
{
"code": "INVALID_DATA",
"details": {
"api_name": "product",
"index": 0,
"parent_api_name": "Product_Details"
},
"message": "invalid data",
"status": "error"
}
]
}
The solution was to POST a product first, then grab that product ID and insert it under Product_Details. This is not documented, so I assumed the product would be created automatically, which it wasn't.

Google fit API add multiple data type based on scope

I am using google fit API with multiple user scopes. How can I add multiple data type for each source. If possible, why I cannot add this as a datasource.
{
"dataStreamName":"MyDataSource",
"type":"derived",
"application":{
"detailsUrl":"http://example.com",
"name":"Foo Example App",
"version":"1"
},
"dataType":[
{
//1st data type
"name":"com.google.step_count.delta",
"field":[
{
"name":"steps",
"format":"int"
}
]
},
{
//2nd data type
"name":"com.google.calories.bmr",
"field":[
{
"name":"calories",
"format":"float"
}
]
}
],
"device":{
"manufacturer":"Example Manufacturer",
"model":"ExampleTablet",
"type":"tablet",
"uid":"1000001",
"version":"1.0"
}
}
And I got a response of
{
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name \"dataType\" at 'data_source': Proto field is not repeating, cannot start list.",
"errors": [
{
"message": "Invalid JSON payload received. Unknown name \"dataType\" at 'data_source': Proto field is not repeating, cannot start list.",
"reason": "invalid"
}
],
"status": "INVALID_ARGUMENT"
}
}
But when I only add one scope which is like this
{
"dataStreamName":"MyDataSource",
"type":"derived",
"application":{
"detailsUrl":"http://example.com",
"name":"Foo Example App",
"version":"1"
},
"dataType":{
"name":"com.google.step_count.delta",
"field":[
{
"name":"steps",
"format":"integer"
}
]
},
"device":{
"manufacturer":"Example Manufacturer",
"model":"ExampleTablet",
"type":"tablet",
"uid":"1000001",
"version":"1.0"
}
}
It returns me 200 which is successful. Did I miss something or is what I am trying to do possible? Thanks.
Google fit API reference
https://developers.google.com/fit/rest/v1/reference/users/dataSources/create
I believe the nesting your trying to do has to go at the dataField level rather than the dataType level.
dataType.field[]
I think this because I noticed that 'field[]' is a collection while dataType is not.

SparkPost email not sending

I"m trying to get SparkPost setup for my website but keep encountering problems. I'm sending the proper headers so I know that's the issue and am pretty sure it's something with my json body.
This is the endpoint I'm posting to: https://api.sparkpost.com/api/v1/transmissions?num_rcpt_errors=3
{
"content": {
"from":{
"name":"Testing Email",
"email":"testing#hidden.com"
},
"subject": "Thundercats are GO!!!",
"text": "Sword of Omens, give me sight BEYOND sight"
},
"recipients": [
{
"address": {
"email": "jscotto#hidden.com"
}
}
]
}
The response from the above is this:
{
"results": {
"total_rejected_recipients": 0,
"total_accepted_recipients": 1,
"id": "hidden"
}
}
I don't know what could be causing it to not send because from my knowledge, I've followed every guideline on the documentation.
Turns out the emails were sending, they're just hitting my spam box. I ended up setting up an ip_pool of sa_shared and that solved my issue.

Parse Push Notifications to multiple users through REST API

I'm sending push notifications from a rails app through the parse.com REST API.
Targeting a single user works great but targeting more users with $in doesn't seem to work in my scenario.
Here's my JSON Code:
{
"where":
{
"user":
{
"__type":"Pointer",
"className":"_User",
"objectId":
{
"$in":["AAA","BBB","CCC"]
}
}
},
"data":
{ ...
Isn't it possible to use $in when targeting multiple users? I noticed that I'm also not able to to so in the parse.com push backend.
The response is:
{
"code": 106,
"error": "key objectId should be a string"
}
Anyone got an idea? I don't want to make an separate REST Call for every notification.
Okay, sorry I found the answer here: REST in Parse $in to ObjectID of Pointer Error Code 106
Or in short, this code works:
{
"where":
{
"user":
{
"$inQuery":
{
"where": {
"objectId":
{
"$in":["AAA","BBB","CCC"]
}
},
"className":"_User"
}
}
},
"data":

Attempt by method 'System.Web.Helpers.Json.Decode(System.String)' to access field 'System.Web.Helpers.Json._serializer' failed

I have the following JSON;
{
"b2c": {
"languages": {
"de": {
"models": {
"t300": {
"name": "Aveo",
"bodyTypes": {
"t300-4d-my13": {
"trimLevels": {
"lt": {
"name": "LT",
"variants": {
"1.2_16V_86_Gas_MT": {
"name": "1.2 MT",
"price": {
"EUR": {
"value": 13990,
"formatted": "13.990,00 €"
}
},
"infoFeatures": {
"fuel_consumption_extra_urban#consumption": {
"name": "Kraftstoffverbrauch außerorts ",
"value": "4.6",
"formatted": "4,6"
},
"top_speed#kilometer_per_hour": {
"name": "Höchstgeschwindigkeit",
"value": "171",
"formatted": "171"
}
},
"images": null,
"documents": null
}
}
}
}
}
}
}
}
}
}
}
}
The values of b2c, de, t300, t300-4d-my13, It etc.. are dynamic but languages, models, bodyTypes, trimLevels, variants, inforFeatures, images and documents would remain same.
I need to extract all to access values like languages.["de"], models.["t300"].name, timeLevels.["It"], Variants and infoFeatures, as these keys [""] are dynamics so I am not sure what to refer.
I have tried,
var jsonSerializer = new JsonSerializer();
dynamic dynamicObject = jsonSerializer.Deserialize(new JsonTextReader(new StringReader(jsonString)));
//var level1 = dynamicObject.b2c
I have looked this as well
Deserialize JSON into C# dynamic object?
and tried
var dynamicObject = Json.Decode(jsonString);
but receiving following error;
Attempt by method 'System.Web.Helpers.Json.Decode(System.String)' to access field 'System.Web.Helpers.Json._serializer' failed.
For us it helped to uncheck "Enable the Visual Studio hosting process" in the Project properties > Debug tab, from the top answer to Attempt by method 'System.Web.Helpers.Json..cctor()' to access method 'System.Web.Helpers.Json.CreateSerializer()' failed
A general solution would be to use something like Json.net and serialize to C# Object - this is very flexible, and does not conflict with the dynamic nature of the json object coming from the client.
This error seems to occur when you have multiple projects with different versions of assemblies; eg, if you have JSON.NET 4.5.1 in one project and 5.0.6 in another. Things seem to get sorted if you make sure the same versions exist everywhere in the solution.