I am trying send email through Microsoft graph api. I created a message object like the following.
{"message":{"subject":"hellowolrd","body":{"contentType":"text","content":"wow"}},"toRecipients":{"emailAddress":{"address":"example#yahoo.com"}}}
But gets 400 error with invalid recipient. Can anybody help me why I am getting this error.
It seems you have a syntax issue in your JSON request.Look closely after content you have an extra closing } which means you are not posting 'toRecipients' in the message.
{"message":{"subject":"hellowolrd","body":{"contentType":"text","content":"wow"}},"toRecipients":{"emailAddress":{"address":"example#yahoo.com"}}}
Instead try below JSON to make it work -
{
"message": {
"subject": "hellowolrd",
"body": {
"contentType": "text",
"content": "wow"
},
"toRecipients": [
{
"emailAddress": {
"address": "example#yahoo.com"
}
}
]
}
}
Thanks!
The invalid recipient was caused by a different json structure. I had to exactly match the following structure that was provided in one of their example.
$mailArgs ='
{
"message": {
"subject": "Meet for lunch?",
"body": {
"contentType": "Text",
"content": "Lunch Invited"
},
"toRecipients": [
{
"emailAddress": {
"address": "example#example.com"
}
}
]
}
}';
So I created a JSON array to match exactly the same structure and it worked!
Related
I'm posting data to my API endpoint. it's simple JSON data. But I'm getting error 404 when posting data as raw JSON but if I post the same data at the same endpoint as raw text its works.
working as raw text
getting error 404 as raw JSON
<?php
var_dump(http_response_code());
echo "hello";
var_dump($_POST);
echo file_get_contents("php://input");
I have removed all code from the API end point and just trying to print post data.
Sample JSON :
{
"object": "whatsapp_business_account",
"entry": [
{
"id": "456",
"changes": [
{
"value": {
"messaging_product": "whatsapp",
"metadata": {
"display_phone_number": "123456789",
"phone_number_id": 123456789
},
"contacts": [
{
"profile": {
"name": "NAME"
},
"wa_id": 123456789
}
],
"messages": [
{
"from": 123456789,
"id": "wamid.ID",
"timestamp": 123456789,
"text": {
"body": "MESSAGE_BODY"
},
"type": "text"
}
]
},
"field": "messages"
}
]
}
]
}
I have checked JSON and it's a valid JSON. no special character but still unable to solve this issue.
One more thing its working on my local machine under XAMPP but not on Linux shared server.
So, basically I need a way to send the current URL link to A Discord webhook.
So for example, the URL would be https://www.example.com and I need that link to send to my Discord webhook.
Is there any way someone could help me with this? If this is not possible, are there any alternative methods?
I would recommend you first reading this—it explains in detail how to format the payload so that it renders as a message in Discord properly, you can even use markdown!
Second, I'm not sure what language you want to code this in, but here's a simple example using Python and httpx
The idea to take away here is
Pick a client library
Study the Discord webhook message format
Create a client for HTTP
Set the logic to send the payload to the webhook you want
Create and send the payload with the formatted webhook message in a POST request
data = {
"username": "Webhook",
"avatar_url": "https://i.imgur.com/4M34hi2.png",
"content": "Text message. Up to 2000 characters.",
"embeds": [
{
"author": {
"name": "Birdie♫",
"url": "https://www.reddit.com/r/cats/",
"icon_url": "https://i.imgur.com/R66g1Pe.jpg"
},
"title": "Title",
"url": "https://google.com/",
"description": "Text message. You can use Markdown here. *Italic* **bold** __underline__ ~~strikeout~~ [hyperlink](https://google.com) `code`",
"color": 15258703,
"fields": [
{
"name": "Text",
"value": "More text",
"inline": true
},
{
"name": "Even more text",
"value": "Yup",
"inline": true
},
{
"name": "Use `\"inline\": true` parameter, if you want to display fields in the same line.",
"value": "okay..."
},
{
"name": "Thanks!",
"value": "You're welcome :wink:"
}
],
"thumbnail": {
"url": "https://upload.wikimedia.org/wikipedia/commons/3/38/4-Nature-Wallpapers-2014-1_ukaavUI.jpg"
},
"image": {
"url": "https://upload.wikimedia.org/wikipedia/commons/5/5a/A_picture_from_China_every_day_108.jpg"
},
"footer": {
"text": "Woah! So cool! :smirk:",
"icon_url": "https://i.imgur.com/fKL31aD.jpg"
}
}
]
}
import httpx # pip install httpx, or poetry add httpx
with httpx.Client() as client:
request = client.post("https://www.discordwebhook.com", data=data) # needs to be a POST
print(request.status_code)
I am able to gent email using https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~)) and able to get name and profile pic using https://api.linkedin.com/v2/me.My question is that how can i get it together.Is there any single API to call and get all profile info together?
The documentation says something about lite and basic profile permissions but unfortunately there doesn't seem to be a way to get both in one query.
Profile Json Response:
{
"firstName":{
"localized":{
"en_US":"Bob"
},
"preferredLocale":{
"country":"US",
"language":"en"
}
},
"localizedFirstName": "Bob",
"headline":{
"localized":{
"en_US":"API Enthusiast at LinkedIn"
},
"preferredLocale":{
"country":"US",
"language":"en"
}
},
"localizedHeadline": "API Enthusiast at LinkedIn",
"vanityName": "bsmith",
"id":"yrZCpj2Z12",
"lastName":{
"localized":{
"en_US":"Smith"
},
"preferredLocale":{
"country":"US",
"language":"en"
}
},
"localizedLastName": "Smith",
"profilePicture": {
"displayImage": "urn:li:digitalmediaAsset:C4D00AAAAbBCDEFGhiJ"
}
}
Contact Json Response:
{
"elements": [
{
"handle": "urn:li:emailAddress:3775708763",
"handle~": {
"emailAddress": "ding_wei_stub#example.com"
},
"primary": true,
"type": "EMAIL"
},
{
"handle": "urn:li:phoneNumber:6146249836070047744",
"handle~": {
"phoneNumber": {
"number": "158****1473"
}
},
"primary": true,
"type": "PHONE"
}
]
}
The reason might be that there are separated APIs, Contact API and Profile API.
i'm trying to make a post on facebook using api with using child_attachments param, so i can pass multiple urls in 1 post.
In facebook debugger i'm passing json like that
{
"message": "test debug",
"child_attachments": [
{
"link": {
"link": "https://google.com"
}
},
{
"link": {
"link": "https://ft.com"
}
}
]
}
but i'm getting following error message
{ "error": {
"message": "Invalid parameter",
"type": "OAuthException",
"code": 100,
"error_data": {
"blame_field_specs": [
[
"child_attachments[0][link]"
]
]
},
"error_subcode": 2061006,
"is_transient": false,
"error_user_title": "URL Can't Be Used",
"error_user_msg": "The URL you entered, \"https://google.com\" doesn't direct to a website. Please enter a valid URL and try again.",
"fbtrace_id": "xxxxxxxx"
}
}
i've tried setting urls in app domains , i tried use urls with / without https and with/without www.
still no luck, can some one give me some advise?
Thanks,
Roman.
ok, so i figured, the correct format should be like that:
{
"message": "message to post",
"link": "https://yahoo.com",
"child_attachments": [
{
"link": "https://yahoo.com",
"name": "name -1",
"picture": "https://images.all-free-download.com/images/graphiclarge/ethereal_image_185195.jpg"
},
{
"link": "https://google.com",
"name": "name - 2 ",
"picture": "https://images.all-free-download.com/images/graphiclarge/ethereal_image_185195.jpg"
}
]
}
note that even despite of the thing you adding links in the child_attachments, you must provide 'link' parameter also for post
I'm trying to use Tumblrs API and when I visit the URL for the API I get this below
{
"meta": {
"status": 200
"msg": "OK",
},
"response": {
"blog": {
"title": "Ex-Sample",
"posts": 20,
"name": "example",
"url": "http://example.tumblr.com/",
"updated": 1327794725,
"description": "A sample document used to provide examples of the various [and <i>varying</i>] HTML tags Tumblr puts out. Quote, specifically, has a lot of variants.",
"ask": false
}
}
}
The URL is http://api.tumblr.com/v2/blog/example.tumblr.com/info?api_key=(APIKEY)
I'm trying to get what the "post" number is with that URL above. How would I do that in PHP and echo the number only out?.
That looks like a JSON string, so...
$msg = '{"meta" etc.....';
$data = json_decode($msg);
echo $data['meta']['response']['blog']['posts'];
You can use
var_dump($data);
to dump the entire response in a nicely formatted tree structure.