insert multiple rows in a data extension by using rest api - 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

Related

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:

HTTP Response Error with Post to LinkedIn using Share API v2

I am trying to post a Share to LinkedIn using OAuth v2 - I have got authorisation correctly and have the appropriate access keys.
This code is supposed to share a link on LinkedIn, but for some reason it's not working - I'm not sure why. Can anyone help?
this is my request body:
{
"distribution": {
"linkedInDistributionTarget": {}
},
"owner": "urn:li:person:XXXXXX",
"subject": "Test Share Subject",
"text": {
"text": "Hello !"
}
And this my call API shares :
publishPostLink(body : any, token : any){
this.headers = new HttpHeaders(
{
'Content-Type': 'application/json',
'Authorization':'Bearer '+token,
'cache-control': 'no-cache',
'X-Restli-Protocol-Version':'2.0.0', });
return this.http.post("https://api.linkedin.com/v2/shares" , body, {headers: this.headers});}
I get this issue:
I've already installed the Moesif CORS and it didn't worked
I fixed the error using this post..
it should use REST API from the backend and not from frontend
http://localhost is an insecure request origin so its not supportted in many cases.
Try using tunneling software like Ngork https://ngrok.com/

How to make POST request with __RequestVerificationToken header in Postman

I want to send a POST request with Postman to receive back information from a database with a list of elements.
Case:
On a Home page, I have a search engine when I'm choosing parameters. URL://example.com
I'm clicking button: Display on a list URL://example.com
I'm receiving list with searched elements URL://example.com/Search/Result
Fist Test
Method: Post
URL: example.com
Headers: Content-Type - application/json
Temporary Headers: which include : __RequestVerificationToken
Body:
{
"options": "1",
"IsMember": "false",
"ID": "2",
"btnShowList" : "true"
}
Result:
Status: 200,
But in a body I have HTML of whole home page, so probably post was not executed
Second Test
Method: Post
URL: example.com/Search/Result
Headers: Content-Type - application/json
Temporary Headers: which include : __RequestVerificationToken
Body:
{
"options": "1",
"IsMember": "false",
"ID": "2",
"btnShowList" : "true"
}
Result:
Status: 404, Not Found
Questions:
Is it possible to do the post if in URL is no query parameres?
Any idea how can I write such a test case?
Have anyone writes post method with dynamic parameters such as eg. __RequestVerificationToken
Receiving an HTML in response is totally normal, especially if the technology used is ASP.net WebForms for instance.
To answer some of your questions: It is possible to make a post with no query params. All you need to do is hit the correct url with the expected body

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...

unable to get response from an api

I a requesting an API to get response but it gives below some "JWT_TOKEN_MiSSING" response:
{
"response": {
"ids": "",
"time": 1505890122982,
"error": "JWT_TOKEN_MISSING",
"status": "failure"
}
}
API is: "https://www.viu.com/api/container/load?appid=viu_desktop&iid=9fa3fec0-9457-11e7-bee5-ed8c9b3d7f48&regionid=all&ver=1.0&aver=5.0&fmt=json&contentCountry=in&contentFlavour=telugu&languageid=en&platform=desktop&vuserid=viu-guest-9fa3fec0-9457-11e7-bee5-ed8c9b3d7f48&userid=guest-9fa3fec0-9457-11e7-bee5-ed8c9b3d7f48&ccode=IN&geo=2&id=playlist-24926470&start=0&limit=20&geofiltered=false"
I tried passing all the headers but no luck.
It seems that this API use JWT TOKEN or other tokens (such as HTTP BASIC AUTHENTICATION) to authenticate, you need to know this and add it to your request headers.