Wrong values on Summary of Social Actions? - linkedin

It seems that the LinkedIn API returns incorrect values when retrieving a comment's summary of social actions.
I did a GET request on https://api.linkedin.com/v2/socialActions/urn%3Ali%3Acomment%3A%28urn%3Ali%3Aactivity%3A6546403695196811264%2C6546405316437790720%29
Here is the API response body:
{
'commentsSummary': {
'totalFirstLevelComments': 0,
'aggregatedTotalComments': 0
},
'$URN': 'urn:li:comment:(urn:li:activity:6546403695196811264,6546405316437790720)',
'likesSummary': {
'likedByCurrentUser': False,
'aggregatedTotalLikes': 0,
'totalLikes': 0
},
'target': 'urn:li:comment:(urn:li:activity:6546403695196811264,6546405316437790720)'
}
And the expected response body:
{
'commentsSummary': {
'totalFirstLevelComments': 3,
'aggregatedTotalComments': 3
},
'$URN': 'urn:li:comment:(urn:li:activity:6546403695196811264,6546405316437790720)',
'likesSummary': {
'likedByCurrentUser': True,
'aggregatedTotalLikes': 2,
'totalLikes': 2
},
'target': 'urn:li:comment:(urn:li:activity:6546403695196811264,6546405316437790720)'
}
Here are the response headers to help the LinkedIn team debugging:
{
'X-LI-ResponseOrigin': 'RGW',
'Content-Type': 'application/json',
'X-RestLi-Protocol-Version': '2.0.0',
'Content-Length': '327',
'Date': 'Tue, 18 Jun 2019 11:49:38 GMT',
'X-Li-Fabric': 'prod-lor1',
'Connection': 'keep-alive',
'X-Li-Pop': 'prod-efr5',
'X-LI-Proto': 'http/1.1',
'X-LI-UUID': 'i07XV5tIqRWAdyFKiSsAAA==',
'Set-Cookie': 'lidc="b=OB36:g=1847:u=345:i=1560858577:t=1560936475:s=AQEK0vHcIcV0LWfWF-E4uJW6AanRPr4r"',
'X-LI-Route-Key': '"b=OB36:g=1847:u=345:i=1560858577:t=1560936475:s=AQEK0vHcIcV0LWfWF-E4uJW6AanRPr4r"'
}
Any explanation about the API response?
Best regards.

Related

How do I change the JSON stream I get back from Fetch using Deno?

I am new to Deno and have the following simple code...
const getCOP = async()=>{
const resp = await fetch("....", {
headers: {
accept: "application/json",
apiKey
},
});
return await resp.body;
}
let resp = {}
return new Response(resp.body, {
status: resp.status,
headers: {
"content-type": "application/json",
},
});
resp.body = await getCOP();
resp.status = 200;
It returns
{
"success": true,
"timestamp": 1675621083,
"base": "COP",
"date": "2023-02-05",
"rates": {
"EUR": 0.000199,
"GBP": 0.000179,
"USD": 0.000216
}
}
What I would like to do would be the equivalent of this in normal JS...
return {
rate : resp.body.rates,
copPerDollar : 1 / resp.body.rates.USD
}
Of course this doesn't seem to work because instead of an actual json obj it is a readable stream. How do I transform this stream into a json object and then restream it to the body of the sent request?

Why am I getting a different response from programmatically querying this endpoint?

I am trying to use the createChatInviteLink API method to create a chat invite.
This is the response I get when I try to access it through my browser:
{"ok":true,
"result":{"invite_link":"https://t.me/+4MooeJCENSORED",
"creator":{"id":CENSORED,"is_bot":true,"first_name":"CENSORED","username":"CENSORED"},
"expire_date":1674321925,
"creates_join_request":true,
"is_primary":false,
"is_revoked":false}}
However, none of that useful response shows up when I try the same exact query through my web app. Instead, I get this:
RESPONSE Response {
size: 0,
timeout: 0,
[Symbol(Body internals)]: {
body: PassThrough {
_readableState: [ReadableState],
_events: [Object: null prototype],
_eventsCount: 2,
_maxListeners: undefined,
_writableState: [WritableState],
allowHalfOpen: true,
[Symbol(kCapture)]: false,
[Symbol(kCallback)]: null
},
disturbed: false,
error: null
},
[Symbol(Response internals)]: {
url: 'https://api.telegram.org/botCENSORED/createChatInviteLink?chat_id=CENSORED&expire_date=1674422960&creates_join_request=true',
status: 200,
statusText: 'OK',
headers: Headers { [Symbol(map)]: [Object: null prototype] },
counter: 0
}
}
Is there a specific part of the response I need to access? Even response.body isn't returning anything useful.
This is the code that tries to fetch the response:
export async function generateGroupInviteURL(
botToken: string,
groupId: string
) {
const fiveMinutesLaterTimestamp = Math.round(new Date().getTime() / 1000) + 300;
fetch(
`https://api.telegram.org/bot${botToken}/createChatInviteLink?chat_id=${groupId}&expire_date=${fiveMinutesLaterTimestamp}&creates_join_request=true`
).then((res) => {
console.log("RESPONSE", res);
});
}
Any ideas on what I'm doing wrong or need to be doing to access the useful part?

swagger-client request body missing, content-length 0, and 415 response

I am maintaining someone else's web app (manual JavaScript files and MVC using swagger-js to connect to a .NET API).
The one POST route is returning 415 (Unsupported Media Type), but all the other GET routes work ok. I've had a look at the existing questions on this topic and they refer to incorrect specs or other issues which don't apply to me... I think.
You can quite clearly see from the Request Headers that nothing is posted in the body. But I don't know why:
POST /api/Trip/search HTTP/1.1
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Connection: keep-alive
Content-Length: 0
Host: localhost:44393
Origin: https://localhost:44316
Referer: https://localhost:44316/
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-site
User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36
accept: application/json
sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="102", "Google Chrome";v="102"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "Windows"
The Swagger spec is generated from dotnet core 3.1 using this route:
[Route("search")]
[HttpPost]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<ActionResult<TripInformationSearchResponse>> TripInformationSearch(TripInformationSearchRequest request)
{
...
}
Part of the generated spec is:
"/api/Trip/search": {
"post": {
"tags": [
"Trip"
],
"operationId": "TripInformationSearch",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Cust.API.Models.Trip.TripInformationSearchRequest"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/Cust.API.Models.Trip.TripInformationSearchRequest"
}
},
"application/*+json": {
"schema": {
"$ref": "#/components/schemas/Cust.API.Models.Trip.TripInformationSearchRequest"
}
}
}
},
"responses": {
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Cust.API.Models.Trip.TripInformationSearchResponse"
}
}
}
},
"400": {
"description": "Bad Request",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Microsoft.AspNetCore.Mvc.ProblemDetails"
}
}
}
}
}
}
}
The webapp client uses swagger-js from JavaScript (not exactly how I would do it but I'm not about to rewrite it just now) to call the search_trips function which calls the above API route:
CUSTAPI = {
swagger_client: function (urlBase) {
var specUrl = urlBase + '/swagger/v1/swagger.json';
SwaggerClient.http.withCredentials = true; // this activates CORS, if necessary
var swaggerClient = new SwaggerClient(specUrl);
return swaggerClient;
},
// ...and later
search_trips: function (keywords, tripNumbersArr, status, routeType, hasGLPostDate, successCallback) {
var failedSwaggerLoadSpecCallback = function (reason) { CUSTAPI.error_display("Unable to connect to the API: " + reason); };
var failedApiRequestCallback = function (reason) { CUSTAPI.error_display("Unable to fulfill the API request: " + reason); };
CUSTAPI.swagger_client(oldApiClient_UrlBase)
.then(
function (swaggerClient) {
var searchRequest = {
keywords: keywords,
tripNumbers: tripNumbersArr, //array
status: status,
routeType: routeType,
hasGLPostDate: hasGLPostDate
};
return swaggerClient.apis.Trip.TripInformationSearch(searchRequest); // chaining promises
}, failedSwaggerLoadSpecCallback)
.then(function (response) {
if (response.ok)
successCallback(response.obj);
//else
// return response
}, failedApiRequestCallback);
},
...
}
And from there no amount of debugging can show me why nothing is put in the body. Can you see why?

Run Azure Notebook By API (external)

I am trying to run the notebook from node, everything is working fine except the parameters are not accepted by the notebook instead it is sending the output based on default params. I am not getting where I am doing wrong.
Below is my call:
var job_payload = {
"run_name": runName,
"existing_cluster_id": 'cluster_id',
"notebook_task":
{
"notebook_path": notebookPath
},
"notebook_params": notebook_params //{'x':1,'y':2}
}
var url = "https://<location>.<azr_databricks>.net/api/2.0/jobs/runs/submit";
var options = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer token'
},
body: JSON.stringify(job_payload),
};
My notebook:
import json
dbutils.widgets.text("x", '3', "firstParam")
dbutils.widgets.text("y", '4', "secondParam")
x=int(dbutils.widgets.get("x"))
y=int(dbutils.widgets.get("y"))
sum=x+y
class Output:
def __init__(self, val):
self.resultTest2 = val
p1 = Output(sum)
print(p1.resultTest2)
result=json.dumps(p1.__dict__)
#RETURNING THE OUTPUT
dbutils.notebook.exit(result)
I am sending x:1 and y:2 as param but instead of getting output 3 I am getting 7 which is default value.
As I am not getting much help from the documentation, please help:
Document URL: Microsoft link
I got the answer that where I was wrong from the below link :
StackOverflow Link
the job_payload will look like below:
var job_payload = {
"run_name": runName,
"existing_cluster_id": 'cluster_id',
"notebook_task":
{
"notebook_path": notebookPath,
"base_parameters":notebook_params //{'x':1,'y':2}
},
}
var url = "https://<location>.<azr_databricks>.net/api/2.0/jobs/runs/submit";
var options = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer token'
},
body: JSON.stringify(job_payload),
};
Now, it is working fine.

Parse.com Send a push notification with query restriction on installation field via REST API

I'm trying to send push notifications (at 12 PM the next day) to installations whose "updatedAt" field is not older than two days. Here's the code:
var two_days_ago_date = new Date()
two_days_ago_date.setDate(two_days_ago_date.getDate() - 2)
var push_time = new Date()
push_time.setDate(push_time.getDate() + 1)
push_time.setHours(12)
push_time.setMinutes(00)
push_time = push_time.toISOString()
push_time = push_time.substring(0, push_time.length - 1)
Parse.Cloud.httpRequest({
method: "POST",
headers: {
"X-Parse-Application-Id": "XXX",
"X-Parse-REST-API-Key": "XXX",
"Content-Type": "application/json"
},
body: {
"where":{
"appVersion":"1.4",
"updatedAt" : {"$gte" : two_days_ago_date}
},
"push_time": push_time,
"data": {
"alert":"",
"sound": ""
}
},
url: "https://api.parse.com/1/push"
}).then(function() {
console.log("Successful push");
}, function(error) {
console.log(error);
})
If I remove the restriction the code works fine, otherwise not.

Resources