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

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

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'}
]
}

Why is power automate custom connector returning same results for different request URLs?

I am trying to develop a custom connector on Microsoft Power Automate which connects to my Django API through an on-premises data gateway. Irrespective of the path names that I provide, it always returns the response body from the base API URL.
For eg, the response body that I get for my base URL (http://domain-name/) is:
Body
{
"ipaddresses": "http://domain-name/ipaddresses/",
"vlans": "http://domain-name/vlans/"
}
Here, you can see that my response body contains the valid paths that is available for my API. But when I change my request URL to any of the above path URLs, I still get the same response body instead of the correct responses(-an array of IP addresses and VLANs, respectively). The response code that I am getting is 200, so I can't troubleshoot any errors there. Also, all the path URLs are working fine when accessed via browser or Postman.
I am also including the request headers in my custom connector for your reference, below:
Headers
{
"allow": "GET,HEAD,OPTIONS",
"cache-control": "no-cache,no-store",
"content-encoding": "gzip",
"content-type": "application/json",
"date": "Wed, 06 Jan 2021 09:45:02 GMT",
"expires": "-1",
"pragma": "no-cache",
"referrer-policy": "same-origin",
"strict-transport-security": "max-age=31536000; includeSubDomains",
"vary": "Accept,Cookie,Accept-Encoding",
"x-content-type-options": "nosniff,nosniff",
"x-frame-options": "DENY,DENY",
"x-ms-apihub-cached-response": "true",
"x-ms-request-id": "******",
"x-powered-by": "ASP.NET"
}
Kindly help me where I am going wrong. Thank you!
For each request type, you need to create a unique Action, Request and Response in the Custom Connector.
See here:
Multiple Actions
Each with its own request path
And response schema

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

POST command to WebCeo API

Trying to connect to this WebCEO API.
function getProjects() {
var payload = {
"key": "CUSTOMER_KEY",
"method": "get_projects"
};
payload = JSON.stringify(payload);
var url = "https://online.webceo.com/api/";
var options = {
"method": 'POST',
"contentType" : "application/json",
"payload": payload
};
var response = UrlFetchApp.fetch(url, options);
}
Receiving "Request failed for https://online.webceo.com/api/ returned code 404".
Any hint on what else I need to include / change?
Body must contain the following:
json={"key": "YOUR_API_KEY", "method": "get_projects"}
Well, https://online.webceo.com/api/ does return a 404 when you just try to access it. Did you manage to get that page to not return a 404 error from another client?
Doing so will probably tell you what you're missing here.
However, I'd suspect their API might be having issues.
That's true, you don't make a GET request. You have to send parameters in the body of a POST request. Below is an example in CURL for a situation when you need to get the list of projects:
curl -X POST -d 'json={"key": "YOUR_API_KEY", "method": "get_projects" }' https://online.webceo.com/api/