curl request says to address needs to be an array when it already is? - mailchimp

I'm trying to send an email out using Mandrill by adapting the curl command from https://mailchimp.com/developer/transactional/api/messages/send-new-message/ and using the API key from https://us1.admin.mailchimp.com/account/api/ and I'm getting an error that doesn't make a lot of sense to me. Here's the command I'm running:
curl -X POST \
https://mandrillapp.com/api/1.0/messages/send \
-d '{"key":"...","message":{"html":"hello, world!","subject":"hello, world!","from_email":"neubert#neubert.com","to":["neubert#neubert.com"]}}'
Here's the response:
{"status":"error","code":-2,"name":"ValidationError","message":"Validation error: {\"message\":{\"to\":[\"Please enter an array\"]}}"}
Here it is decoded:
{
"status": "error",
"code": -2,
"name": "ValidationError",
"message": "Validation error: {\"message\":{\"to\":[\"Please enter an array\"]}}"
}
I don't understand. "to" is an array...
Any ideas?
Thanks!

I also got the same error at first then going through the documentation keenly, I noticed that the to field in message is NOT a list of email addresses. I know it's intuitive that way!!
It's a list of object's with 3 fields: email, name and type.
An ideal JSON Body will be as follows:
{
"key": "<YOUR_MANDRILL_API_KEY>", # Caution! It is not a mailchimp API key
"message": {
"html": "testing html part",
"text": "testing text part",
"subject": "testing subject",
"from_email": "<FROM_EMAIL_ADDRESS>",
"from_name": "<FROM_NAME>",
"to": [
# Recipient 1
{
"email": "<Recipient1_EMAIL_ADDRESS>",
"name": "<Recipient1_NAME>"
},
# Recipient 2
{
"email": "<Recipient2_EMAIL_ADDRESS>",
"name": "<Recipient2_NAME>"
}
]
}
}

Related

Nexmo not sending SMS to US Number, but able to send to Indian Number

Curl for posting message to US number:
curl -X POST "https://rest.nexmo.com/sms/json" -d "from=1XXXXXXXXXX" -d "text=A text message set using the Nexmo SMS API" -d "to=1XXXXXXXXXX" -d "api_key=my_api_key" -d "api_secret=my_api_secret"
Response:
{
"message-count": "1",
"messages": [{
"to": "1XXXXXXXXXX",
"status": "15",
"error-text": "Illegal Sender Address - rejected",
"network": "XXXXXX"
}]
}
Curl for posting message to Indian number:
curl -X POST "https://rest.nexmo.com/sms/json" -d "from=1XXXXXXXXXX" -d "text=A text message set using the Nexmo SMS API" -d "to=91XXXXXXXXXX" -d "api_key=my_api_key" -d "api_secret=my_api_secret"
Response:
{
"message-count": "1",
"messages": [{
"to": "91XXXXXXXXXX",
"message-id": "0F000XXXXF05XXX6",
"status": "0",
"remaining-balance": "48.96XXXXXX",
"message-price": "0.00800000",
"network": "XXXXX"
}]
}
This was working fine for both US and Indian Number, but recently it is giving me Illegal Sender Address - rejected error.
Has nexmo changed anything?
Please see this page for restrictions on USA SMS features:
https://help.nexmo.com/hc/en-us/articles/204017023-USA-SMS-Features-Restrictions
Specifically:
"All SMS sent to the US must originate from either a U.S. pre-approved long number or short code that is associated with your Nexmo account. Alpha sender IDs are not supported."

Mandrill emails stuck in queued

I managed to figure out how to send emails via Mandrill and Parse Cloud Code with Back4App. When checking the API logs for Mandrill I see the following:
Full Request
{
"message": {
"text": "asdf Email Test",
"subject": "adsf Email Test",
"from_email": "no-reply#asdf.ca",
"from_name": "Site",
"to": [
{
"email": "myemail#gmail.com",
"name": "Martin",
"type": "to"
}
],
"headers": {
"Reply-To": "no-reply#adsf.ca"
}
},
"async": false,
"ip_pool": "Main Pool",
"send_at": "2018-03-13T17:14:41.645Z",
"key": "oc7ueJMLRGgaEDrjhk5DBg"
}
Full Response
[
{
"email": "myemail#gmail.com",
"status": "queued",
"_id": "7c28e80e4de1405f93d1d096600128d4",
"reject_reason": null
}
]
It seems as if the code is executing properly but the response body indicates that the email is queued. I decided to wait 24 hours and nothing has changed. I sent some more test emails and I get the same result. Basically, the emails are not sending. What is going on?
apparently for Mandrill work with Back4App you need to setup a own domain, and it looks like you're using a Gmail email address. Therefore, it is recommended to use SendGrid in this case :)

parse_exception - request body is required

I'm trying to insert a JSON data file in my elasticsearch instance.
curl -s -H “Content-Type: application/x-ndjson” -XPOST localhost:9200/_bulk —-data-binary “#restaurants.json”; echo
However, after executing this command I get an error that says
{"error":{"root_cause":[{"type":"parse_exception","reason":"request body is required"}],"type":"parse_exception","reason":"request body is required"},"status":400}
The JSON file basically has an array of the below object.
Only thing is that I've put just one object here to save space. However, there are more than one objects present.
Structure is like given below;
[
{
"address": {
"building": "351",
"coord": [
-73.98513559999999,
40.7676919
],
"street": "West 57 Street",
"zipcode": "10019"
},
"borough": "Manhattan",
"cuisine": "Irish",
"name": "Dj Reynolds Pub And Restaurant",
"grades": [
{
"date": {
"$date": "2014-09-06T00:00:00.000Z"
},
"grade": "A",
"score": 2
},
{
"date": {
"$date": "2013-07-22T00:00:00.000Z"
},
"grade": "A",
"score": 11
},
{
"date": {
"$date": "2012-07-31T00:00:00.000Z"
},
"grade": "A",
"score": 12
},
{
"date": {
"$date": "2011-12-29T00:00:00.000Z"
},
"grade": "A",
"score": 12
}
],
"id": "30191841"
}
]
The bulk API requires one document per line, which means you can't have newlines in your documents. Try stripping all the white spaces from the JSON you're submitting. You are also just submit a stream of documents, and not a JSON array of objects. See Bulk API documentation here: https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html
I had this same issue in Windows and am posting this here for anyone that comes across the same question with this error referenced.
{"error":{"root_cause":[{"type":"parse_exception","reason":"request body is required"}],"type":"parse_exception","reason":"request body is required"},"status":400}
I found at least two causes:
cURL doesn't know where the file you are trying to load is:
In this case, make sure to run cURL from the directory where the file is located. Try executing the following command and making sure you see the file.
more file.json
Windows command line DOES NOT support single quotes within the cURL command line:
BAD
curl -H 'Content-Type: application/x-ndjson' -XPOST 'localhost:9200/_bulk' --data-binary '#file.json'
GOOD
curl -H "Content-Type: application/x-ndjson" -XPOST "localhost:9200/_bulk" --data-binary "#file.json"
I solved it by wrapping the url with quotation mark.
curl -s -H “Content-Type: application/x-ndjson” -XPOST "localhost:9200/_bulk —-data-binary “#restaurants.json”;

Skype/MS Team REST API not working

I'm creating a bot using REST API. Indeed, I want to send a message from my bot to me as following
I start with 'Authentification'
Request:
curl -k -X POST https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token -d "grant_type=client_credentials&client_id={app_id}&client_secret={app_password}&scope=https://graph.microsoft.com/.default"
Response:
{
"token_type": "Bearer",
"expires_in": 3599,
"ext_expires_in": 0,
"access_token": "<access_token>"
}
Next, I start a new conversation
Request:
POST https://skype.botframework.com/v3/conversations
Authorization: Bearer <access_token>
Content-Type: application/json
{
"bot": {
"id": "standupalice",
"name": "Standup Alice"
},
"isGroup": false,
"members": [
{
"id": "<my bot id>",
"name": "Standup Alice"
},
{
"id": "<my user id>",
"name": "Bao"
}
],
"topicName": "News Alert"
}
NOTE: and are obtained from a callback message sent from Skype app to Standup Alice bot.
Response:
{
"id": "<conversation id>"
}
It's weird since the conversation ID is identical to . Well, now I compose a message to send to me as following
Request:
POST https://skype.botframework.com/v3/conversations/<conversation id>/activities
Authorization: Bearer <access_token>
Content-Type: application/json
{
"type": "message",
"from": {
"id": "<my bot id>",
"name": "Standup Alice"
},
"conversation": {
"id": "<conversation id>",
"name": "News Alert"
},
"recipient": {
"id": "<my user id>",
"name": "Bao"
},
"channelId": "skype",
"text": "My bot's reply"
}
Response (http error 400 - bad request):
{
"error": {
"code": "ServiceError",
"message": "The conversationId <conversation id>and bot <my bot id> doesn't match a known conversation"
}
}
Do you have an idea what's wrong with my requests and parameters?
Note 1: I tried to fire request to https://api.botframework.com/v3/conversations as described in https://docs.botframework.com/en-us/core-concepts/overview/#navtitle, but always receives http error 404 - Resource not found.
Note 2: I just tried the same way for webchat and it works fine, but MS Teams doesn't work (http error 500 - Internal Server Error)
Note 3: my channel settings
Your second API request (the one starting a conversation) should have returned something looking like this:
{
"activityId": "string",
"serviceUrl": "string",
"id": "string"
}
The fact that it didn't suggests to me that that's where the problem is (although full disclosure, I wasn't able to re-create it).
Looking at your "members" array, I see you added the bot. I'm not sure, strictly speaking, that a bot is a member (I think members are human, but I can't find a good definition). So, my best suggestion would be to remove the bot from the members array in that second API call.
Good luck!

Mandrill Forward a friend and Unsubscribe

Full Request in sending mail.
{
"message": {
"subject": "Test message",
"from_email": "",
"html": "this is a test message with Mandrill's PHP wrapper!.Unsubscribe | Forward A friend",
"to": [
{
"email": "*",
"name": "Recipient 1"
}
]
},
"async": false,
"ip_pool": "",
"send_at": "",
"key": "*" // API KEY
}
Full Response
[
{
"email": "*",
"status": "sent",
"_id": "********",
"reject_reason": null
}
]
Getting the mail but Unsubscribe and Forward A friend not work in mail.
I am using the mandrill API.
Please guided me.
Those merge tags are specific to MailChimp and won't work by default in Mandrill. More info can be found in the Mandrill KB: Can I use MailChimp merge tags in Mandrill emails?

Resources