I'm using an IBM Cloud Functions web action but can not access the parameters.
Parameters:
Code:
function main(params) {
module = params.module;
attribute = params.attribute;
var options = {
method: 'POST',
uri: params.uri,
headers: {
'Content-Type': 'application/json; charset=utf-8',
},
body: {
module: module
},
json: true
};
console.log(options);
return { message: options };
}
IBM Cloud Functions Output:
Postman Output
Remove the quotations from the parameter name field, then try it again. it works for me.Parameters
Related
I use fabric Kony and I have given to Postman Username pass of Fabric to authenticate
enter image description here
and entered this prerequest script:
const postRequest = {
url: 'https://sandbox-api.marqeta.com/v3/swagger.json',
method: 'POST',
timeout: 0,
header: {
"Content-Type": "application/x-www-form-urlencoded"
},
body: {
mode: 'urlencoded',
urlencoded: [
{key: "grant_type", value: "password"},
{key:"username", value: "........."},
{key:"password", value: ".........."},
]}
};
pm.sendRequest(postRequest, function (err, res) {
var responseJson = res.json();
console.log(responseJson);
pm.environment.set('ACCESS_TOKEN', responseJson['access_token']);
});
I'm not an user of POSTMAN, but I know a little of Kony Fabric.
If you hit the web url of a Kony Fabric you'll notice that the first call will generate an oauth_token (for example 0526b30c-6579-4965-a774-87224815ea3a) that will be used for further calls.
I think that you should catch this token before trying to connect to the Kony Fabric with a user's credentials.
Cordially,
Hervé N.
I have the API from the backend and I need to call the API with id's changing dynamically.
ex API:
http://13.567.544/api/meters/start?id=m1 (for id 'm1')
and for m2
http://13.567.544/api/meters/start?id=m2 (for id 'm2') and so on.
How to call the above API with id's(m1,m2,m4,....) passing dynamically(pass ids dynamically in API),and I want the typescript and service code for the same. Also I want to check with the console if it is working or not in developer tools.
In
Postman, I received the following.
{
"status": true,
"action": "m1 meter started"
}
and for 'm4'
{
"status": true,
"action": "m4 meter started"
}
the 'm' values will be changed according to the server.
.service.ts
meterstart( token) {
let httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json',
'Authorization': 'Token ' + token
}),
Params:new URLSearchParams({
'id':this.meters.name;
})
};
this.http.get(environment.apiUrl+'/api/meters/start'+this.id,httpOptions).subscribe(
(data:any)=>{
console.log(data);
}
.component.ts
jammerstop(){
this.data=JSON.parse(localStorage.getItem("data"));
console.log(data);
}
I want the hard code for the above component and service code for calling the API, because I have not involved in this scenario
I want to call an Apify actor and specify a parameter value via a call to the Apify API.
The actor is the Google Search Results Scraper located here.
Here is where the docs say to use queries as the object property name in the API call payload.
The following table shows specification of the actor INPUT fields as defined by its input schema. These fields can be [...] provided in a JSON object when running the actor using the API. Read more in docs.
...
Search queries or URLs
Google Search queries (e.g. food in NYC) and/or full URLs (e.g. https://www.google.com/search?q=food+NYC).
Enter one item per line.
Optional
Type: String
JSON example
"queries": "Hotels in NYC
Restaurants in NYC
https://www.google.com/search?q=restaurants+in+NYC"
After I run my Google Apps Script code, I expect to see a change in the searchQueries.term parameter to be the following.
Apify — what I expect to see
"searchQuery": {
"term": "Banks in Phoenix", // what I am trying to change to by API call
// [...]
},
But what I actually get is the same parameter value as existed the last time I ran the actor manually. As follows.
Apify — what I actually see
"searchQuery": {
"term": "CPA firms in Newark", // remaining from last time I ran the actor manually
// [...]
},
Here is the code I'm running from Google Apps Script.
Code.gs
const runSearch = () => {
const apiEndpoint= `https://api.apify.com/v2/actor-tasks/<MY-TASK-NAME>/run-sync?token=<MY-TOKEN>`
const formData = {
method: 'post',
queries: 'Banks in Phoenix',
};
const options = {
body: formData,
headers: {
'Content-Type': 'application/json',
},
};
UrlFetchApp.fetch(apiEndpoint, options,);
}
What am I doing wrong?
You are missing the payload property in the request object.
Change:
queries: 'Banks in Phoenix',
to:
payload: {
queries: 'Banks in Phoenix',
}
Code.gs
const runSearch = () => {
const apiEndpoint= `https://api.apify.com/v2/actor-tasks/<MY-TASK-NAME>/run-sync?token=<MY-TOKEN>`
const formData = {
method: 'post',
payload: {
queries: 'Banks in Phoenix',
},
};
const options = {
body: formData,
headers: {
'Content-Type': 'application/json',
},
};
UrlFetchApp.fetch(apiEndpoint, options,);
}
I am trying to return odata as "nometadata" as listed here: JSON Light for SharePoint
I have set my headers in my factory as follows:
appServices.factory('appItems', ['$resource', function ($resource) {
return $resource("/_api/web/lists/getbytitle('Todo Task List')/Items", {},
{
'query': { method: "GET", isArray: false },
'update': { method: 'PATCH' },
'headers': { Accept: 'application/json;odata=nometadata'}
}
);
}]);
However, it does not return the nometadata option, but rather defaults to:
Key Value
Accept application/json, text/plain, */*
How can I get it to pass in the nometadata option?
According to the docs for $resource, the headers object should be placed within an action:
appServices.factory('appItems', ['$resource', function ($resource) {
return $resource("/_api/web/lists/getbytitle('Todo Task List')/Items", {},
{
'query': { method: "GET", isArray: false, headers: { 'Accept': 'application/json;odata=nometadata'} },
'update': { method: 'PATCH', headers: { 'Accept': 'application/json;odata=nometadata'} },
}
);
}]);
As your code stands, headers would become a new action for your resource to be called as: appItems.headers() which wouldn't produce/do what you would expect.
To be honest, the docs aren't completely clear on what type headers: should be or how to set a header globally for all the $resource operations, so you could write your own wrapper around $http if adding/overriding actions becomes tedious.
This answer shows another example
I'm using bootstrap 3 and jquery to develop my app. My question is, why i got null object if not using JSON.stringify instead formValues?
Before using JSON.stringify
var that = this;
var formValues = {
userId: 315,
locale: "en",
};
this.collection.fetch({
type: "POST",
contentType: 'application/json',
dataType: "json",
data: formValues,
success: function(collection, response) {
var template = _.template(accountsSummaryTemplate, {
accounts: that.collection.models
});
that.$el.html(template);
console.log(that.collection);
},
error: function(collection, response) {
console.log(that.collection);
}
});
After using JSON.stringify
var that = this;
function formToJSON() {
return JSON.stringify({
"userId": 315,
"locale": "en",
});
}
this.collection.fetch({
type: "POST",
contentType: 'application/json',
dataType: "json",
data: formToJSON(),
success: function(collection, response) {
var template = _.template(accountsSummaryTemplate, {
accounts: that.collection.models
});
that.$el.html(template);
console.log(that.collection);
},
error: function(collection, response) {
console.log(that.collection);
}
});
Thanks a lot in advance.
If the data property is an object, jQuery serializes it with $.param:
> $.param({userId: 315, locale: "en"});
"userId=315&locale=en"
If you pass in a string instead, jQuery doesn't serialize it. Look at the requests using your web browser's developer tools.
Because that's not a proper data string.
var formValues = "userid=5&locale=en";
Because JS object is not JSON. JSON is string, JS object is an object. If fetch uses jQuery.ajax, it expects either a JS object, or a query string (which is not JSON): "userId=315&locale=en".