Graph API: Check if feed post was made by a Page or User - json

When using the /page/feed endpoint in the Facebook Graph API I can't figure out how to know if the post was made by a Page or a User
Here's how I call the endpoint right now:
HTTP GET https://graph.facebook.com/v2.8/{page_id}/feed?fields=is_published,from,message
This yields the following JSON response:
{
"data": [
{
"from": {
"name": "Chad Smith", # <-- This is a User
"id": "806273209398023"
},
"message": "A really magical place! Best Christmas...",
"id": "103988597020_1445496708809010"
},
{
"from": {
"name": "Tivoli", # <-- This is a Page
"id": "103988597020"
},
"message": "Hello everybody...",
"id": "103988597020_10154040865527021"
},
]
}
How can I know if the post was from a Page or User without making additional API calls? I've tried using subfields, but can't figure out if they work on the from field.

I solved it by using ?fields=from{name,about} and marking it as a Page if the from JSON contains about.
This is not the best solution, but about is currently the only subfield of from that doesn't fail on User. (e.g. if I was using ?fields=from{fan_count} the Graph API will fail for posts made by User objects.

Related

Slack JSON - Custom Bot Username and Icon

I'm looking to send out a Post json request using Zapier's webhook function, together with Slack's incoming webhook set up.
I'm using block kit to develop the message style, and so far that's worked great. However, I'd like my bot to display with a custom username and emoji/icon and I'm having trouble.
Here is the JSON payload I'm trying, based off this tutorial https://api.slack.com/methods/chat.postMessage#args
The post seems to ignore the first two lines and posts as the standard bot name
{
"as_user": false,
"username": "test",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*78 Varet St #14*\n 2 Bed / $2300 \n <#ben> \n 3rd Deposit This Month"
},
"accessory": {
"type": "image",
"image_url": "https://p.sharinpix.com/3/3521a32/YXBwLnNoYXJpbnBpeC5jb20vaW1hZ2VzL2I2M2RkZTY4LWZkMDMtNGZlYy04OGUxLWYwZjA0N2E4NjQ3NS90aHVtYm5haWxzL29yaWdpbmFsLWI5MTdlNzAzY2U2LmpwZw/77-varet-st-building.jpg?timestamp=1639154285",
"alt_text": "cute cat"
}
},
{
"type": "divider"
}
]
}
Any help would be greatly appreciated!
If you just want to modify the icon and name of your bot ( will be the same throughout the app ), you should be able to do that on https://api.slack.com/apps/{YOUR_APP_ID}/general? under the Display Information section.
If you want to be able to change it from message to message, you will have to grant your app additional permissions scopes. See https://api.slack.com/methods/chat.postMessage#authorship

Sending dynamic variables in sendgrid v3 body using postman

I am trying to send the emails via Sendgrid using v3 API using postman, I have created 3 separate variables in 3 different requests, I want to pass all those 3 variables in a single mail, for that I have used below sendgrid
https://api.sendgrid.com/v3/mail/send
with below body
{
"personalizations": [
{
"to": [
{
"email": "testing#test.com",
"name": "API Testing"
}
],
"subject": "API testing successful"
}
],
"from": {
"email": "noreply#testApi.com",
"name": "API Testing"
},
"content": [
{
"type": "text/plain",
"value": "{{variable1}}" //In variable1 has a dynamic values
}
]
}
but the above format sending the mail body as {{Variable1}}, can someone help me on this?
For handlebar {{ variable_value }} substitutions in dynamic HTML templates, u need to pass the variable value as JSON structure with the key as "dynamic_template_data" as part of personalizations.
U also need to pass the (API Key) Authorization as "Authorization: and Value as "Bearer ".
In the Request Body pass the personalizations object.
{
"personalizations": [
{
"to": [
{
"email": "ron#***",
}
],
"dynamic_template_data": {
"<variable_name>": <variable_value>
}
}
],
"from": {
"email": "development#crosspaymt.com",
"name": "Development Team"
},
"content": [
{
"type": "text/html",
"value": "replace body with template content"
}
],
"template_id": "******"
}
From what I understand of the question you want to send multiple requests with different values.
Say, GET to https://google.com/q={{search}} and you have multiple search queries, (dog, chess, marvel, stackoverflow)
Create a collection in postman
Add a GET request to https://google.com/q={{search}} with necessary headers and hit Save
Create a CSV file with the header search and all search values under it
Hit the run button for the newly created collection
Set the Iterations field to the number of queries you have. In this example it is 4
Look for the field Data, select the created CSV file
Ensure the data is correctly being picked up by hitting the Preview button
Hit Run test
You can view the output in the Postman Console
To open Postman Console Head to View in the application menu, and click on "Show Postman Console" or use the keyboard shortcut (CMD/CTRL + ALT + C) to open.

REST API design: complex query with GET

I am designing a REST call that should deliver information for a location (lat/lon) and consider the user context/configuration.
As the number of user properties is high and nested, I am not sure, what is the correct way to design a new query (GET vs POST). Currently we use a POST request for simplicity - the query payload could look like this, but is custom and very different for each user. It also includes an array of multiple configuration items. Currently the request looks like this:
POST http://api.something.com/locationInformation
{
"location": {
"accuracy": 30,
"coordinates": [
16.34879820048809,
48.230067741347334
],
"provider": "network",
"timestamp": "2016-01-06T12:00:00.000Z"
},
"userConfiguration": [
{
"id": "asdfasdfasdfs09898sdf",
"values": [
"false"
]
},
{
"id": "iojkljio230909sdjklsdf",
"values": [
"99jkjiouio89",
"sdfilkjöjfoi093s09sdf"
]
}
]
}
So my question is: is it in such a case ok to "abuse" a POST request in order to query information?
Is there an elegant way to pass such data using a GET request?
Yes u can pass this data using a GET request by passing it to a request header.
use the header() method.Initialize a String variable say String data=//your json; and pass it to the header as follows header("data",data) in your client while building the request.

how can i post data using Mozilla rest add-on using mailgun api

I'm using this Mozilla ADD-ON to post the data in mailgun API
RestClient
Content-Type:application/json
URL I'm using
https://api.mailgun.net/v2/sandbox42924.mailgun.org/messages
Json Data I'm posting
[
{
"from": "Kaushik <kaushik#gmail.com>"
},
{
"to": "Kaushik <kaushikfb1#gmail.com>"
},
{
"subject": "Hello This is test mail"
},
{
"text": "Testing some Mailgun !"
},
{
"html": "<html>Hello These <h2>contents belongs</h2> to html content</html>"
}
]
OR
{
"from": "Kaushik <kaushik#gmail.com>",
"to": "Kaushik <kaushikfb1#gmail.com>",
"subject": "Hello This is test mail",
"text": "Testing some Mailgun !",
"html": "<html>Hello These <h2>contents belongs</h2> to html content</html>"
}
In both cases what I'm getting is
{
"message": "'from' parameter is missing"
}
I want to know how i can post the data.
In documentation they have not describe this process.
I'm curious to know how it is working?
Here is the link for the documentation Click Here. They are using library for using in each language. If you know the library in detail you can help.
Finally I found the answer of this so for the sake of other user so they may find a help from this post in future I'm submitting the answer.
the url is this one.
https://api.mailgun.net/v2/yourdoamin.com/messages
username = api
password = {your key}
Now after that set your content type:application/x-www-form-urlencoded.
Now post the data. for formatting the data you can use this link Click Here
Demo data format
from%3D%27Excited%20User%20%3Cme%40yourdoamin.com%3E%27%20%5C%0A%20%20%20%20%20to%3Dbaz%40example.com%5C%0A%20%20%20%20%20to%3Dbar%40example.com%20%5C%0A%20%20%20%20subject%3D%27Hello%27%20%5C%0A%20%20%20%20text%3D%27Testing%20some%20Mailgun%20awesomness!%27

Sencha touch get json error

Every time i try to work with sencha touch to get a json feed i always get this error.
XMLHttpRequest cannot load http://api.example.com/index.php/news/all/format/json?_dc=1342630239638&node=root. Request header field X-Requested-With is not allowed by Access-Control-Allow-Headers.
how can i fix a work around to stop this i really want to work with sencha but most of my work will be working with json feeds???
any help
also my json outputted looks like this it doesnt have a rootproperty node??
[{
"id": "7253",
"title": "hello",
"description": "",
"source": "syrianews",
"cat_name": "Syrianews"
}, {
"id": "7208",
"title": "hello",
"description": "",
"source": "syrianews",
"cat_name": "Syrianews"
}]
It appears you are trying to do a cross domain Ajax request, which is not allowed. Ajax requests have a security requirement of same domain, same port, same protocol. If you load your app from say http://www.tinyfactory.co/ and then try to make an Ajax request to http://api.example.com/ the security sandbox will not allow it.
But there is hope. Enter JSONP. JSONP or padded JSON (http://en.wikipedia.org/wiki/JSONP) is a way to bypass this security policy if the domain you are requesting the data from plays nice. Typically you will see a param on the API named "callback" What this does is wrap the data in a Javascript function you declare. for example:
http://api.example.com/datafeed.json?callback=foo
would return the data
foo({fName: 'Alex', lName: 'Rolek'});
JSONP is able to achieve this by dynamically inserting a script tag into the DOM with the 'src' attribute set to the API you are requesting with the callback request var. When the API returns the response the function 'foo' is called in your application and you can start working with the response data.
In Sencha Touch, change:
proxy: 'ajax'
to
proxy: 'jsonp'
On your request. As long as the API accepts callbacks, Sencha Touch will do the rest of the heavy lifting.
For additional information, check out:
http://docs.sencha.com/touch/2-0/#!/api/Ext.data.proxy.JsonP
Hope this helps.
Can Sencha read such non-root response?
[{
"id": "7253",
"title": "hello",
"description": "",
"source": "syrianews",
"cat_name": "Syrianews"
}, {
"id": "7208",
"title": "hello",
"description": "",
"source": "syrianews",
"cat_name": "Syrianews"
}]