Maximum message limit while sending message through incoming webhook - hangouts-chat

I am sending notification to chat rooms through incoming web hooks. I am using powershell and using following command:
Invoke-RestMethod -Uri $hangoutURL -Method Post -Body $payload -ContentType 'html'
My question is what is the maximum size limit of text message that could be sent through this command?

Testing this endpoint using curl, I have obtained the following response message:
{
"error": {
"code": 400,
"message": "Message is longer than 4096 characters",
"status": "INVALID_ARGUMENT"
}
}
This restriction applies to the content of your request. That is, if you have a request body like the following:
{
"text": "hello world"
}
This restriction applies to the contents of the value associated to the text key.

Related

Can i send raw like form-data in postman?

Can i send raw like form-data in postman? Because i think the server accepts only multipart data which we send via form-data but i need to send the same data via raw.
DATA -
{
"uploadRequest": {
"fileType": "OTHER_EVIDENCE",
"description": "other"
},
"uploadedFile": "cypress/fixtures/evidence.jpeg"
}
ERROR -
{
"httpStatusCode": 500,
"errors": [
{
"code": "1001",
"description": "A service exception has occurred",
"details": "Failed to parse multipart servlet request; nested exception is javax.servlet.ServletException: org.apache.tomcat.util.http.fileupload.impl.InvalidContentTypeException: the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is application/json"
}
]
}
but if i send this data via form-data it works fine
SUCCESS IMAGE

Get error sending POST request to openweathermap via postman

I'm starting to learn the REST API. I use POSTMAN for this and openweathermap.org.
I am sending the name of the city in the body. The body has json format:
{
"cityName" : "Poltava,UA"
}
Response from the server:
{
"cod": "400",
"message": "Nothing to geocode"
}
Please tell me where I am going wrong? I changed the name of the key to "q", "city" and wrote simply "Poltava" and always I get the same error.
API docs: https://openweathermap.org/current
Headers of my request is:
Headers

Flurl \ RestSharp: `\r\n` is added to each parameter of the Multipart request

I'm trying to write a call to the Freshdesk API using either Flurl or RestSharp library.
The API call I'm trying to write is Creating a Ticket: https://developers.freshdesk.com/api/#create_ticket
An example of cURL:
curl -v -u yourapikey:X -F "attachments[]=#/path/to/attachment1.ext" -F "attachments[]=#/path/to/attachment2.ext" -F "email=example#example.com" -F "subject=Ticket Title" -F "description=this is a sample ticket" -X POST 'https://domain.freshdesk.com/api/v2/tickets'
Note params are passed by -F (i.e. --form) flag.
With the following code calling Flurl:
var rs = await url.WithBasicAuth(_configuration.ApiKey, _configuration.Password)
.PostMultipartAsync(mp =>
{
mp.AddString("email", ticket.Email);
mp.AddString("subject", ticket.Subject);
mp.AddString("status", ticket.Status.ToString());
mp.AddString("priority", ticket.Priority.ToString());
mp.AddString("description", ticket.Description);
});
...Or the following code calling RestSharp:
var request = new RestRequest("tickets", Method.Post);
request.AlwaysMultipartFormData = true;
request.AddParameter("email", ticket.Email);
request.AddParameter("description", ticket.Description);
request.AddParameter("subject", ticket.Subject);
request.AddParameter("status", ticket.Status);
request.AddParameter("priority", ticket.Priority);
var rs = await client.ExecuteAsync(request);
...I'm receiving 400 BadRequest with the following information (in both cases):
{
"description": "Validation failed",
"errors": [
{
"code": "invalid_field",
"field": "email\r\n",
"message": "Unexpected/invalid field in request"
},
{
"code": "invalid_field",
"field": "subject\r\n",
"message": "Unexpected/invalid field in request"
},
{
"code": "invalid_field",
"field": "status\r\n",
"message": "Unexpected/invalid field in request"
},
{
"code": "invalid_field",
"field": "priority\r\n",
"message": "Unexpected/invalid field in request"
},
{
"code": "invalid_field",
"field": "description\r\n",
"message": "Unexpected/invalid field in request"
}
]
}
Note that:
Freshdesk API uses -F / --form as a way to pass parameters.
I want to use Multipart for handling attachments later on.
All data has proper values. If it wouldn't have a proper value, a validation error would come as a response.
When sending the same values in Postman (via form-data), I'm receiving 201 Created.
Update 1
Postman screenshot (working example):
Update 2
I tried to use Tiny.RestClient which has cURL listener and it came with the following cURL generated:
curl -X POST [...] -d "--1c3acb07-77bd-494d-bc56-21290dcd5088
Content-Type: text/plain
Content-Disposition: form-data; name=email
a#a.com
[...]
Perhaps, Flurl and RestSharp uses the same way to proceed with parameters and thus, the \r\n in fields.
It's the FreshDesk API issue. They want, for some reason, for multipart form-data parameter names to be enclosed in quotation marks. It's not a requirement per HTTP standards. RestSharp and Flurl use MultipartFormDataContent, and it adds uses parameter names as provided.
Following up on your issue, I added this property to RestRequest:
/// <summary>
/// When set to true, parameters in a multipart form data requests will be enclosed in
/// quotation marks. Default is false. Enable it if the remote endpoint requires parameters
/// to be in quotes (for example, FreshDesk API).
/// </summary>
public bool MultipartFormQuoteParameters { get; set; }
It is available in RS 107.3.0.
You can also make it work by adding parameters like this:
request.AddParameter("\"status\"", ticket.Status);

Can we add multiple labelId in history.list API for gmail?

I want to get the result of all INBOX mails and all SENT mails in one API call using the historyID and the history.list Gmail-API.
Refer:
https://developers.google.com/gmail/api/v1/reference/users/history/list
When I am hitting the following GET request :
https://www.googleapis.com/gmail/v1/users/{userID}/history?startHistoryId={historyID}&labelId=SENT&labelId=INBOX
I only get the SENT label messages.
Seems like the API only accepts single & first query param for labelId.
Is there a way to get multiple labelIds' response in a single API call?
I think it would not be possible, I tried making a multiple request and it this response:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalidArgument",
"message": "Invalid label value in query"
}
],
"code": 400,
"message": "Invalid label value in query"
}
}
I would suggest to call it separately for each labelID but you can try filing a feature request for this.
Hope this helps.

Forward an email using rest api and powershell (Azure Automation)

I'm trying to forward emails with attachments to a specific email address via Azure Automation (with message ID). I get the error message at the bottom after I run the code. I'm not really sure am I on the right track here (both with email sending and sending of attachments). Perhaps there's a better way to do this.
Could anyone lend a hand?
$credObject = Get-AutomationPSCredential -Name "Myscreds"
$url = "https://outlook.office365.com/api/v1.0/me/AAMkADA1MTAAAH5JaL/forward"
$body = "{
""Message"":{
""Subject"": ""This is a test"",
""Importance"": ""Low"",
""Body"": {
""ContentType"": ""HTML"",
""Content"": ""This is great!""
},
""ToRecipients"": [
{
""EmailAddress"":{
""Address"": ""myname#test.com""
}
}
]
}}"
Invoke-RestMethod -Uri $url -Method Post -Credential $credobject -ContentType "application/json" -Body $Body
I get the following error message:
Invoke-RestMethod : The remote server returned an error: (400) Bad Request.
At line:24 char:1
+ Invoke-RestMethod -Uri $url -Method Post -Credential $credobject -Con ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod],
WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
Thanks.
Per the Microsoft documentation, you need to modify your request.
https://outlook.office.com/api/v1.0/me/messages/AAMkAGE0Mz8DmAAA=/forward
It looks like you forgot to include /messages/ in your request.
However, it looks like you want to change the body of a message when you forward it. This is more complicated, and you need to follow this workflow instead:
Alternatively, if you need to modify any updateable properties in the message to be forwarded, you can first create a draft forward message, update the message properties, and then send the reply.
Here's how that would look.
First, make a Draft of the message you want to forward
$request = "https://outlook.office365.com/api/v1.0/me/messages/AAMkADA1MTAAAH5JaL/createforward"
$body = {
"ToRecipients":[
{
""EmailAddress"":{
""Address"": ""myname#test.com""
}
}
],
"Comment": "Your sample message here"
}
The response back is going to include some properties, including the ID of the new message. You then use that to edit the Draft (to change the subject, etc) and then send it off. Let me know if you need any further help.
Ok. I had the incorrect message ID, that was my main problem. It's all resolved. I can forward messages with attachments using the message ID. Thanks again.
$credObject = Get-AutomationPSCredential -Name "mycreds"
$url = "https://outlook.office365.com/api/v1.0/Users('it-test#test.com')/messages/ASHJFKHFUISDFWIzLT=/forward"
$body = "{
""Comment"": ""A mail with some attachments (hopefully)"",
""ToRecipients"": [
{
""EmailAddress"":{
""Address"": ""myname#test.com""
}
}
]
}"
Invoke-RestMethod -Uri $url -Method Post -Credential $credobject -ContentType "application/json" -body $body