How to make POST request with __RequestVerificationToken header in Postman - api

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

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

Request body missing from POST requests made using Postman scripting

I am trying to run a pre-request script for authenticating all my requests to the Spotify API. It works via the Postman GUI, but when I try to make the request via scripting, it fails because there is no body. Here is my code
const postRequest = {
url: pm.environment.get("spotifyAuthApi"),
method: "POST",
header: {
"Content-Type": "application/x-www-form-urlencoded",
"Accept": "*/*",
"Content-Length": 29,
"Authorization": "Basic " + btoa(pm.environment.get("client_id") + pm.environment.get("client_secret"))
},
body: {
grant_type: "client_credentials",
}
}
I get a
error: "unsupported_grant_type"
error_description: "grant_type parameter is missing"
And when I examine the request via the postman console, there is no request body, even though the request was built exactly like my fetch token request that does the same thing successfully in postman, only via the GUI instead of via a pre-request script. I have searched far and wide about this issue and tried multiple variations of the body object but to no avail. Either the body object doesn't generate my desired field, or it doesn't get created at all.
Mode might be missing in the body object. Try this:
body: {
mode: 'raw',
raw: JSON.stringify({ grant_type: 'client_credentials' })
}
More details might be found in Postman docs for RequestBody.
If you're using urlencoded, the body of the request would be structured like this:
body: {
mode: 'urlencoded',
urlencoded: [
{ key: 'grant_type', value: 'client_credentials'}
]
}

How to load search params to Leankit Post request from Google Apps Script

I have set up a working api call using Postman that returns the information that I want to return. I need to set up the same API call using google apps script but for some reason the search params are not loading. The api response gives the same result as the Postman response was without any search params being loaded.
My code so far is shown below. I've tried removing and adding back different settings in various orders but haven't found anything that finds the card related to the search term that I used.
function cardSearch(part) {
var settings = {
"method": "POST",
"contentType": "application/json",
"headers": {
"async": true,
"crossDomain": true,
"Authorization": "Basic *********",
"User-Agent": "PostmanRuntime/7.15.0",
"Accept": "*/*",
"Cache-Control": "no-cache",
"Postman-Token": "************",
"accept-encoding": "gzip, deflate",
"contentLength": "60",
"Connection": "keep-alive",
"cache-control": "no-cache"
},
"payload": JSON.stringify({"searchOptions": { "SearchTerm": part, "Page": 1 } })
// part is loaded into this function as a variable
}
var url = "https://**********.leankit.com/kanban/api/board/********/searchcards";
var response = UrlFetchApp.fetch(url,settings);
Logger.log(response);
var result = JSON.parse(response.getContentText());
var results = result.ReplyData[0].Results;
Logger.log(results);
}
Expected Result:
JSON describing 1 or more cards titled or header'd with the search term of my choosing if one exists.
Actual Result:
JSON describing the first 20 cards that were uploaded to the leankit board I'm referencing.
{TypeName=Test, ClassOfServiceId=0, Size=1, BlockReason=null, IsOlderThanXDays=true, SystemType=Card, Index=139, ActualStartDate=9/12/2018 4:11:09 PM, DrillThroughStatistics=null, CreateDate=9/10/2018, PriorityText=High, StartDate=9/12/2018, CurrentTaskBoardId=*****, ExternalCardIdPrefix=null, LastComment=null, AssignedUserIds=[******], CardTypeIconColor=212121, Version=84, LaneTitle=Finished As Planned, DrillThroughBoardId=null, Tags=Testing, SmallGravatarLink=********, ClassOfServiceCustomIconName=null, TypeId=*******, ClassOfServiceIconPath=null, DrillThroughProgressSizeComplete=null, ParentBoardId=0, Priority=2, Color=#0084FF, CurrentContext=Tasks, ExternalCardID=Material Testing, AssignedUsers=[{AssignedUserId=*********, AssignedUserName=*********, FullName=******** *****, Id=********, EmailAddress=******#*****.com, GravatarLink=*********, SmallGravatarLink=**********}], GravatarLink=********, DrillThroughProgressComplete=null, HasDrillThroughBoard=false, Active=false, ExternalSystemName=null, ExternalSystemUrl=null, Icon=, Id=********, DrillThroughCompletionPercent=null, CountOfOldCards=0, Description=<p>***********</p>, AssignedUserId=*******, ClassOfServiceTitle=null, LastAttachment=null, BoardId=**********, TypeColorHex=#0084FF, ActualFinishDate=9/15/2018 8:28:55 PM, HasMultipleDrillThroughBoards=false, CardDrillThroughBoardIds=[], TypeIconPath=null, ClassOfServiceColorHex=null, BoardTitle=********, TaskBoardTotalCards=3, DueDate=09/19/2018, DrillThroughProgressSizeTotal=null, IsBlocked=false, ParentCardId=null, ParentCardIds=[], AssignedUserName=******, TaskBoardCompletedCardSize=11, Title=Test Card, ClassOfServiceCustomIconColor=null, ParentBoardIds=[], CardTypeIconName=blank_icon, LastActivity=09/18/2018 03:28:55 PM, AttachmentsCount=0, DrillThroughProgressTotal=null, TaskBoardCompletionPercent=100, TaskBoardTotalSize=11, Type={Id=********}, CommentsCount=0, DateArchived=01/15/2018, LaneId=********, ParentTaskboardId=null, LastMove=09/16/2018 04:18:34 PM, TaskBoardCompletedCardCount=3, BlockStateChangeDate=null}
You need to put both the keys and values of the JSON request in quotes, as specified in the documentation E.g. 'method':'post'
Everything that is not a valid parameter for options for UrlFetchApp.fetch() goes into headers or payload - depending on the required syntax of the API you are calling. In particular: async and crossDomain belongs into headers, while everything inside data should be assigned to payload
The documentation for the request you are using specifies that the page number should not be in quotes
Those questions might be helpful for you:
https://stackoverflow.com/a/35155175/11599789
Unable to send Post Request on Google Apps Script

How to POST json parameters from Postman to Jenkins?

I need to call a Jenkins job using its API through Postman. This job requires parameters (HOST, VERBOSITY and PMSP).
Auth works using Jenkins token and header Content-type:application/json is used.
I tried to call the endpoint https://jenkins_server/job/job_name/build/api/json adding the following body to the request but the result is Nothing is submitted, and the job doesn't run.
I tried to call the endpoint https://jenkins_server/job/job_name/buildWithParameters/api/json adding the same body. I get 201 Created (job is running) but no parameters are given to the job.
{
"parameter": [
{
"name": "HOSTS",
"value": "[linux]\n1.2.3.4"
},
{
"name": "VERBOSITY",
"value": "vv"
},
{
"name": "SANS_PMSP",
"value": true
}
]
}
Is my JSON well constructed ? Which endpoint do I need to call ?
If it's Postman that you would like to focus on, you can import the curl command straight into the application.
This creates a new request for you to use and it populates this request, based on the details in the command.
From here, you should be able to add your own URL and point this at the location you need.

Shopify API, unable to create order

I created private application on my test shop and I am trying to create simple order via the Shopify API following the instructions found here:
http://docs.shopify.com/api/order#create
I am using the last example, and sending POST request to admin/orders.json with this in the body of the request:
{
"order": {
"line_items": [
{
"quantity": 1,
"variant_id": 500775053
}
]
}
}
500775053 is a valid variant id.
The response I'm getting is:
{
"errors": {
"line_items": [
"must have at least one line item"
]
}
}
I don't understand what am I doing wrong? Is there some special parameter that I should pass along the request? Some special header?
Thank you for your help!
Try adding these custom headers:
Content-Type: application/json
Accept: application/json