Override the method of packing HTTP form-urlencoded parameters in Meteor HTTP call - http

I'm using Meteor to consume a remote API. One of the endpoints of this API requires an (ordered) array of credentials, so the data would look like
{
"country": "de",
"credentials": ["admin", "password"],
"whatever": "whatever"
}
When I provide this plain-object as the value to param property of HTTP.post like this
HTTP.post('https://api.whatever.org/whatever', {
headers: {
"Authorization": "Basic ".concat(...)
},
params: {
"country": "de",
"credentials": ["admin", "password"],
"whatever": "whatever"
}
});
then the parameters are packed this way:
country=de
credentials=admin,password
whatever=whatever
but they should be packed this way:
country=de
credentials=admin
credentials=password
whatever=whatever
I tried using a Content-Type header but it didn't help.
I tried using content and data instead of params with different outcomes and then ended concatenating all the values into a query string an putting it into content property. But this isn't really a nice piece of code and surely not one that is easy to maintain.
I've read docs but haven't found anything that would help.
Where should I look for the information regarding this topic? Is there a better way to override the way HTTP.post (or, in general, HTTP.call) computes the body of the query to send?

Where should I look for the information regarding this topic?
In the source code.
I know nothing about Meteor, but I’m looking into its source code and I see no public hook which could help you. Of course, you can replace URL._encodeParams with your own function, but that is less maintainable than submitting the encoded params as raw data.

Related

Issues while expanding URNs in versioned creatives response

We are migrating our APIs from unversioned to versioned, and having an issue while trying to get assets data from creatives endpoint.The response has reference to a post, but we are unable to use the expand URNs concept and get the inner media details of the Post URN. Is there a different approach we need to follow here?
I've read through all the migration documents and the response decoration document is also pointing to v2 endpoint and projection parameters, instead of using rest endpoint and fields parameter. Document reference.
Previous Request
GET -
https://api.linkedin.com/v2/adCreativesV2?ids[0]=181794673&projection=(results(*(variables(data(com.linkedin.ads.SponsoredVideoCreativeVariables(userGeneratedContentPost~(specificContent(com.linkedin.ugc.ShareContent(shareCommentary,media(*(media~:playableStreams(),title)))))))))))
This request gets us the media details of the creatives without making multiple calls.
Current Request
GET - https://api.linkedin.com/rest/creatives?ids=List(urn%3Ali%3AsponsoredCreative%3A181794673)&fields=(results(*(content(reference~($URN)))))
I am looking at the response I got from https://api.linkedin.com/rest/creatives?ids=List(urn%3Ali%3AsponsoredCreative%3A181794673) and trying to create the fields request. But no luck yet and getting the below error.
{
"status": 400,
"code": "ILLEGAL_ARGUMENT",
"message": "Invalid projection parameter: (results(*(content(reference~($URN)))))"
}
But when tried with projection in place of fields I got a response
{
"results": {
"urn:li:sponsoredCreative:181794673": {
"content": {
"reference": "urn:li:ugcPost:6905584391779950593",
"reference!": {
"message": "Not enough permissions to access deco: ugcPosts.BATCH_GET.20230101",
"status": 403
}
}
}
}
}
Can someone help me getting the data similar to how we got it before, without making external calls? Otherwise I think I have to be making calls to Creatives -> Posts -> Video, Image, Share etc endpoints

Exclude nextjs api url from sentry events

I have nextjs app with sentry. I want to add new api route, for example api/status, but I want to exclude it from being sent to sentry as it will clutter logs really fast and use my qouta.
I did a small research and it seems that there is an array of urls you can exclude from being tracked. It's called denyUrls. Read more. I have tried to add my url to this array, but it still tracks this url as part of events:
Sentry.init({
...
denyUrls: [
/api\/status/i,
],
...
});
Am I configuring something wrong or this array is not for the purpose of filtering everts.
If so, what's the best way to filter those? Other option I found which I will try next is beforeSend but it feels a bit overkill to simply exclude url. denyUrls feels like much better fit for what I am trying to achieve
I had the same issue and contacted the support for it. I am directly quoting the support here.
The BeforeSend and DenyUrl are options to filter error events, not transactions. For transaction events, please use the tracesSampler function as described on the page: https://docs.sentry.io/platforms/javascript/guides/nextjs/configuration/sampling/#setting-a-sampling-function.
Here is an example to drop all transactions that match a certain name:
tracesSampler: samplingContext => {
if(samplingContext.transactionContext.name == "GET /api/health"){
return 0.0 // never send transactions with name GET /api/health
}
return 0.2 // sampling for all other transactions
}
Note that you might need to customise the function above to better match your scenario.
I hope it will help you ;)
Have a nice day.

Always get “Cannot parse non Measurement Protocol hits”

I have a little Python program that other people use and I would like to offer opt-in telemetry such that can get an idea of the usage patterns. Google Analytics 4 with the Measurement Protocol seems to be the thing that I want to use. I have created a new property and a new data stream.
I have tried to validate the request and set it to www.google-analytics.com/debug/mp/collect?measurement_id=G-LQDLGRLGZS&api_secret=JXGZ_CyvTt29ucNi9y0DkA via post and send this JSON payload:
{
"app_instance_id": "MyAppId",
"client_id": "TestClient.xx",
"events": [
{
"name": "login",
"params": {}
}
]
}
The response that I get is this:
{
"validationMessages": [
{
"description": "Cannot parse non Measurement Protocol hits.",
"validationCode": "INTERNAL_ERROR"
}
]
}
I seem to be doing exactly what they do in the documentation or tutorials. I must be doing something wrong, but I don't know, what is missing. What do I have to do in order to successfully validate the request?
Try to remove /debug part in the URL. In the example you followed it is not present so it is not quite exactly the same.
we just came across the same issue and the solution for us was to put https:// in front of the URL. Hope this helps.

Replicating Postman endpoints with vanilla python requests

After not being able to get the provided python API to work (I simply do not know enough about authentication), but being able to use provided Postman collections to work,
I decided to try and replicate these Collection Endpoints in Python.
I got off to a good start with the auth endpoint
Here it is in Postman:
and my python code replicating this:
base_url = 'https://demo.docusign.net/restapi/v2/'
params = {'api_password':'true'}
headers = {'X-DocuSign-Authentication':json.dumps({"Username":username,"Password":password,"IntegratorKey": clientid}),
'Content-Type':'application/json'}
auth_req = requests.get(base_url+'login_information', params, headers=headers)
Auth request yields 200, just like Postman
But then I try another request to /templates/
Here it is in Postman:
and headers same as Auth request above
I tried many variations of the following:
params = {'accountId':'7787022'}
get_templates = requests.get(base_url+'templates', params, headers=headers)
No matter what I try, I get a 404 instead of a 200 like with postman.
Any idea what I'm doing wrong?
As per your comment, it looks like you don't have a fully built BaseUrl. The full body of a base URL will include the server, the rest API version and your account number. Aside from the Login Information and other authentication calls, all standard* REST API calls will start with https://{{server}}.docusign.net/restapi/v2/accounts/{{accountId}}/
A call to GET templates would be made to https://{{server}}.docusign.net/restapi/v2/accounts/{{accountId}}/templates.
*Organization API calls are coming soon and will likely use a different URL.
The following did not fix, but I thought it would fix, and still think it is importnat information:
In Postman auth call under 'Tests' there is the followign code
var jsonData = JSON.parse(responseBody);
postman.setEnvironmentVariable("accountId", jsonData.loginAccounts[0].accountId);
var jsonData = JSON.parse(responseBody);
postman.setEnvironmentVariable("baseUrl", jsonData.loginAccounts[0].baseUrl);
var jsonData = JSON.parse(responseBody);
postman.setEnvironmentVariable("password", jsonData.apiPassword);
even though this is 'Tests' it is useful for and often used to set variables, (some ppl at my old company used to do this).
In my python code, I need to take the response body from auth request:
{
"loginAccounts": [
{
"name": "Aiden McHugh",
"accountId": "7787022",
"baseUrl": "https://demo.docusign.net/restapi/v2/accounts/7787022",
"isDefault": "true",
"userName": "Aiden McHugh",
"userId": "e87........6a4eb",
"email": "aide....il.com",
"siteDescription": ""
}
],
"apiPassword": "HheDl......3MQ="
}
and use apiPassword variable to reset password in my header
You could also check out the python code example. It includes authentication and many examples.

ASP.net (VB code behind) JSON parsing facebook Graph API response

net but wanted to try to do this code in ASP.net instead of my normal classic ASP.
I have been trying to find code examples that would show me how to parse out the name & id in a returned JSON from a facebook API Graph call. The JSON return looks like this from Facebook:
{
"data": [
{
"name": "David xxxxxx",
"id": "05121212",
"administrator": true
},
{
"name": "Billy xxxxxxx",
"id": "0005128888"
}
],
"paging": {
"next": "https://graph.facebook.com/xxxxx/members?format=json&limit=5000&offset=5000&__after_id=xxxxx"
}
}
Any examples on how to go about parsing out just the name and id from the JSON response in ASP.net would be awesome!
Thanks,
David
Go for, http://james.newtonking.com/
string response = <your fb data>; // I am lazy :P
JObject obj = JObject.Parse(response);
JArray data = (JArray)obj["data"];
for(int i=0,int len=data.count; i < len ; i++)
{
string name = data[i]["name"].ToString();
string id = data[i]["id"].ToString();
string administrator = string.Empty;
if(data[i]["administrator"]!=null)
{
string administrator = data[i]["administrator"].ToString();
}
}
I think, this code is enough to get you going.
Always check for null as api data may or may not have that value.
Edit: I noticed that you wanted a VB code, sorry. But it may help others, so leaving it here. You can convert the code from any C# to VB convertor.
Regardless of whether or not there is a known library for .NET and Open Graph, Json is Json. The way I see it you have three options:
1) Use Newtonsoft Json. You can install this package using nuget into your ASP.NET project and from there there are lots of places on the web that talk about working with this library. http://james.newtonking.com/ is the home page of the library, there are also posts here.
2) Use .NET Json. Again, lots of info on the web here. I found a pretty good looking post here Parse JSON in C#
3) Use the C# Facebook SDK. The FacebookClient class has the ability to serialize and de-serialize Json. You can also install this library via Nuget. I admit the documentation on the C# SDK is lacking, but none the less it works well. More information about it can be found here: http://blog.prabir.me/category/Facebook-C-SDK.aspx
I hope this helps you down the right path.
-Eric
There are no known supported libraries for .net for the new graph api. https://github.com/facebook-csharp-sdk has a few samples for using .net though.

Resources