Can i send raw like form-data in postman? - api

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

Related

insert multiple rows in a data extension by using rest api

I'm trying to insert multiple rows in my data extension by using a POST request on postman. I'm using this documentation :https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/postDataExtensionRowsetByKey.html.
Details of my first POST request :
My URL :
https://MY_SUBDOMAIN.auth.marketingcloudapis.com/v2/token
My body (by using the informations of the package created on marketing cloud) :
{
"client_id": "ssd6ssd6ssd6ssd6ssd6ss",
"client_secret": "p3sp3sp3sp3sp3sp3sp3sp3",
"account_id": "7842222",
"grant_type": "client_credentials"
}
I send the request => Status 200 OK
I copy the tokken access.
I create a second POST request.
Tab Authorization, Type = Bearer Token, I paste my token access
Details of my second POST request :
My URL :
https://MY_SUBDOMAIN.rest.marketingcloudapis.com/hub/v1/dataevents/key:EXTERNAL_KEY_OF_MY_DATA_EXTENSION/rowset
My body :
`
Host: https://MY_SUBDOMAIN.rest.marketingcloudapis.com
POST /hub/v1/dataevents/EXTERNAL_KEY_OF_MY_DATA_EXTENSION/rowset
Content-Type: application/json
[
{
"keys":{
"ID_Crawl": "test123"
},
"values":{
"Source": "2013-05-23T14:32:00Z",
"Type_contenu": "no",
"Statut_Notification": "non lu",
"Champ": "20081105",
"Origine_contenus": "test blablablablablablabla",
"Date_crawl": 02/02/2023
}
},
{
"keys":{
"ID_Crawl": "test"
},
"values":{
"Source": "2013-05-23T14:32:00Z",
"Type_contenu": "ok",
"Statut_Notification": "valide",
"Champ": "00000007",
"Origine_contenus": "test blablablablablablabla",
"Date_crawl": "02/02/2023"
}
}
]
I send the request and I had an error message (Status:400 Bad request means that bad synthax):
{"documentation":"https://developer.salesforce.com/docs/atlas.en-us.mc-apis.meta/mc-apis/error-handling.htm","errorcode":0,"message":"Bad Request"}
Does someone know where is my mistake ?
Sorry if it seems that my mistake is a stupid one, I'm completely a beginner in api call

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);

Sharing debuger from Graph API not working

I am sending a POST request to the API with data as on this page https://developers.facebook.com/docs/sharing/opengraph/using-objects
"id" : <domain>,
"scrape": True,
"access_token" : <token>
But in response I get an error
{
"error": {
"message": "Unsupported post request. Object with ID '<domain>' does not exist,
cannot be loaded due to missing permissions, or does not support this
operation. Please read the Graph API documentation at ...",
"type": "GraphMethodException",
"code": 100,
"error_subcode": 33,
"fbtrace_id": "A4szfMq_LpEo8ne_xipo3ky"
},
"__fb_trace_id__":"An9T1FjDJD2",
"__www_request_id__":"A4szfMq_LpEo8ne_xipo3ky"
}

mail.send is not accepting HTML/ CSS code

I have copied the (HTML) source code from a received email just to have the template/format of that email, and this is the error message that I am receiveing when running the API:
Internal : Unexpected error Error during Web API HTTP Request
HTTP Status Code: 400
HTTP Response Content: {
"error": {
"code": "BadRequest",
"message": "Unable to read JSON request payload. Please ensure Content-Type header is set and payload is of valid JSON format.",
"innerError": {
"date": "2020-12-02T17:01:05",
"request-id": "3ab50fc1-0c13-4536-96db-bf6b9b7a736d",
"client-request-id": "3ab50fc1-0c13-4536-96db-bf6b9b7a736d"
}
}
}
I have tested basic commands using HTML such as making text bold and line breaks which work, but anything more complex and I will receive an error.
Update**
Thank you for your response guys, the call that I'm using looks like this:
{
"message": {
"subject": "[Subject]",
"body": {
"contentType": "HTML",
"content": "[Email Body Content]"
},
"toRecipients": [
{
"emailAddress": {
"address": "[Email Address]"
}
}
],
"internetMessageHeaders":[
{
"name":"x-custom-header-group-name",
"value":"Nevada"
},
{
"name":"x-custom-header-group-id",
"value":"NV001"
}
]
}
}
**Another update ** Upon changing the content type to text/html is recieved this error:
Internal : Unexpected error Error during Web API HTTP Request
HTTP Status Code: 415
HTTP Response Content: {"error":{"code":"RequestBodyRead","message":"A supported MIME type could not be found that matches the content type of the response. None of the supported type(s) 'Microsoft.OData.ODataMediaType, Microsoft.OData.ODataMediaTyp...' matches the content type 'text/plain; charset=utf-8'."}}
note i also have tried text/plain as the content type.
Thank you
Ok, I tried the above payload (just updated the email address) and tested with Microsoft Graph Explorer. It works for me :)
Here's the payload:
{"message":{"subject":"[Subject]","body":{"contentType":"HTML","content":"[Email Body Content]"},"toRecipients":[{"emailAddress":{"address":"test#domain.onmicrosoft.com"}}],"internetMessageHeaders":[{"name":"x-custom-header-group-name","value":"Nevada"},{"name":"x-custom-header-group-id","value":"NV001"}]}}
Here's the snapshot:

how to fix 'InvalidRegistration' FCM

I'm getting the InvalidRegistration error in response of my post request for sending push notification.
When I use the Firebase console to send push notification it works all fine.
so I copy the exact registration token I've used in console. I also get my api-key from my project-settings/cloud-messaging.
for sending the post request I've used postman.
I've sent my post request to https://fcm.googleapis.com/fcm/send
my postman header has this attributes:
key: Authorization value: key=<api-key-i-got-from-console>
key: Content-Type value: application/json
my body is:
{
"to" : "fDj8iG5ajZI:APA91bHfs_AjdxOc5Qn-1Plr_OfitrdCTchb4syhPGC0DhPMGiWggJ9mQ5W00ombqowlUSCUOfH_0N3KA-KF0VjQvj5mcMNUMUBgTblpsNzra60kwrbtH2ikfdBa8lenh__olBpGZD4O'",
"collapse_key" : "type_a",
"notification" : {
"body" : "plz work",
"title": "title"
},
}
I get this response from the Firebase
{
"multicast_id": 5801302802423881516,
"success": 0,
"failure": 1,
"canonical_ids": 0,
"results": [
{
"error": "InvalidRegistration"
}
]
}
I did the same with fcm and django-push-notification and got the same result I have no clue what am I doing wrong since my token works with the console and I can send push notifications from the console.
it was my bad that I had an extra ' in the end of my token...