If you’re looking for a way to run an HTTP request during the execution of your extension code, NetworkHTTPRequest may be what you need.
url
url
The URL of the request. (Writable property only for Importers).
A string
is returned. The getter method getUrl()
is also available and allows access to the URL as a DynamicString.
// Read use (Dynamic Value, Code Generator...): get the URL as a string
function evaluate(context) {
var request = context.getCurrentRequest();
return request.url; // equivalent to `request.getUrl(false)`
}
Mutation is only available in Importer extensions.
Either a string or DynamicString can be assigned.
// Write use (Importers): set the URL as a string
function import(context, items, options) {
var request = context.createRequest();
request.url = "http://api.domain.io/v1/path/"
}
// Write use (Importers): set the URL as a DynamicString
function import(context, items, options) {
var request = context.createRequest();
var dynamicValue = DynamicValue('com.luckymarmot.HashDynamicValue', {
'input':'MY_TOKEN'
});
request.url = DynamicString("http://api.domain.io/v1/path/?hash=", dynamicValue);
}
httpBasicAuth
httpBasicAuth
Returns the request HTTP Basic Auth configuration, if any, as an object
(dictionary) with the "username"
and "password"
keys containing strings. The getter method getHttpBasicAuth()
is also available and allows access to the HTTP Basic Auth parameters as DynamicString.
(Writable property only for Importers).
// Read use (Dynamic Value, Code Generator...):
// get the request HTTP Basic Auth parameters as strings
function evaluate(context) {
var request = context.getCurrentRequest();
// get configuration as an object: string -> string
// equivalent to `request.getHttpBasicAuth(false)`
var basicAuth = request.httpBasicAuth;
var username = basicAuth["username"]; // string
var password = basicAuth["password"]; // string
return "" + username + "/" + password;
}
Mutation is only available in Importer extensions.
Assign HTTP Basic Auth "username"
and "password"
parameters through an object (dictionary). Values can be either strings or DynamicString.
The object fields username, password are required.
// Write use (Importers):
// set the request HTTP Basic Auth parameters as strings
function import(context, items, options) {
var request = context.createRequest();
request.httpBasicAuth = {
"username":"paw",
"password":"pass"
};
}
// Write use (Importers):
// set the request HTTP Basic Auth parameters as DynamicStrings
function import(context, items, options) {
var request = context.createRequest();
// create a DynamicValue
var dynamicValue = DynamicValue('com.luckymarmot.HashDynamicValue', {
'input':'Something to hash...'
});
// set basic auth parameters as DynamicStrings
request.httpBasicAuth = {
"username":DynamicString("paw"),
"password":DynamicString(dynamicValue)
};
}
oauth1
oauth1
The request OAuth 1 configuration, if any, as an object
(dictionary) containing strings
. The getter method getOAuth1()
is also available and allows access to the OAuth 1 parameters as DynamicStrings.
(Writable property only for Importers).
// Get OAuth 1 conf values
function evaluate(context) {
var request = context.getCurrentRequest();
// get configuration as an object: string -> string
var oauth1 = request.oauth1;
var consumerKey = oauth1["oauth_consumer_key"];
var consumerSecret = oauth1["oauth_consumer_secret"];
var token = oauth1["oauth_token"];
var tokenSecret = oauth1["oauth_token_secret"];
var nonce = oauth1["oauth_nonce"];
var timestamp = oauth1["oauth_timestamp"];
var callback = oauth1["oauth_callback"];
var signature = oauth1["oauth_signature"];
var signatureMethod = oauth1["oauth_signature_method"]; // either "HMAC-SHA1" or
"PLAINTEXT"
var version = oauth1["oauth_version"]; // always "1.0"
var additionalParameters = oauth1["oauth_additional_parameters"];
return "" + consumerKey + "/" + token;
}
Mutation is only available in Importer extensions.
Assign the request OAuth 1 parameters through an object
(dictionary). Values can be either strings or DynamicStrings.
Here are the possible object fields:
oauth_consumer_key
: Required Consumer key (app credential).
oauth_consumer_secret
: Required Consumer secret (app credential).
oauth_token
: Required Token value (user credential).
oauth_token_secret
: Required Token secret (user credential).
oauth_nonce
: Optional, don’t include this if you’re not sure The nonce to use in the OAuth signature. Defaults to a randomly generated nonce.
oauth_timestamp
: Optional, don’t include this if you’re not sure The timestamp of the request to use in the signature. Defaults to the current UNIX timestamp
oauth_callback
: Optional Defaults to an empty string.
oauth_signature_method
: Optional Defaults to "HMAC-SHA1"
.
oauth_additional_parameters
: Optional Defaults to an empty string.
// Write use (Importers):
// set the request OAuth 1 parameters as strings
function import(context, items, options) {
var request = context.createRequest();
request.oauth1 = {
oauth_consumer_key: 'CONSUMER_KEY', // required
oauth_consumer_secret: 'CONSUMER_SECRET', // required
oauth_token: 'TOKEN', // required
oauth_token_secret: 'TOKEN_SECRET', // required
oauth_signature_method: 'HMAC-SHA1' // either 'HMAC-SHA1' or 'PLAINTEXT'
};
}
oauth2
oauth2
The request OAuth 2 (see RFC 6749) configuration, if any, as an object
(dictionary) containing strings
. The getter method getOAuth2()
is also available and allows access to the OAuth 2 parameters as DynamicStrings.
(Writable property only for Importers).
// Get OAuth 2 conf values
function evaluate(context) {
var request = context.getCurrentRequest();
// get configuration as an object: string -> string
var oauth2 = request.oauth2;
// client credentials
var clientId = oauth2["client_id"];
var clientSecret = oauth2["client_secret"];
// authorization, access token, redirect URIs
var authorizationUri = oauth2["authorization_uri"];
var accessTokenUri = oauth2["access_token_uri"];
var redirectUri = oauth2["redirect_uri"];
// scope
var scope = oauth2["scope"];
// state
var state = oauth2["state"];
// token (and its prefix)
var token = oauth2["token"];
var tokenPrefix = oauth2["token_prefix"]; // default: "Bearer "
// grant type
var grantType = oauth2["grant_type"]; // always "authorization_code"
return clientId;
}
Mutation is only available in Importer extensions.
Assign the request OAuth 2 parameters through an object
(dictionary). Values can be either strings or DynamicStrings.
Here are the possible object fields:
client_id
: Required Client key.
client_secret
: Required Client secret.
authorization_uri
: Required The URL of the authorization page.
access_token_uri
: Required The URL to use to get an access token from the temporary code.
redirect_uri
: Required The URL to where the client will be redirected after authorization.
grant_type
: Optional Defaults to "authorization_code"
(if set, should always be the default value).
scope
: Optional Optional The authorization scope. Defaults to an empty string.
state
: Optional, don’t include this if you’re not sure In most cases you want to omit this field. Defaults to a randomly generated value.
token
: Optional The OAuth 2 token to send, in most cases you want to leave this value empty and let the client visually gets the authorization. Defaults to an empty string.
token_prefix
: Optional The string that will prefix the token (e.g. "Bearer "
is the prefix in the header Bearer TOKEN_STRING
). Defaults to "Bearer "
.
// Write use (Importers):
// set the request OAuth 2 parameters as strings
function import(context, items, options) {
var request = context.createRequest();
request.oauth2 = {
ent_id: 'CLIENT_ID', // required
client_secret: 'CLIENT_SECRET', // required
authorization_uri: 'AUTHORIZATION_URI', // required
access_token_uri: 'ACCESS_TOKEN_URI', // required
redirect_uri: 'REDIRECT_URI', // required
scope: 'SCOPES',
token: 'TOKEN', // optional, can be generated via the app
token_prefix: 'Bearer ', // default 'Bearer '
grant_clitype: 'authorization_code' // always set to 'authorization_code'
};
}
body
body
The body of the request, A string is returned. The getter method getBody(
is also available and allows access to the body as a DynamicString.
(Writable property only for Importers).
// Read use (Dynamic Value, Code Generator...): get the request body as a string
function evaluate(context) {
var request = context.getCurrentRequest();
return request.body; // equivalent to `request.getBody(false)`
}
Mutation is only available in Importer extensions.
Either a string
or DynamicString can be assigned.
// Write use (Importers): set the body as a string
function import(context, items, options) {
var request = context.createRequest();
request.body = 'REQUEST BODY CONTENT'
}
// Write use (Importers): set the body as a DynamicString
function import(context, items, options) {
var request = context.createRequest();
var dynamicValue = DynamicValue('com.luckymarmot.HashDynamicValue', {
input:'REQUEST BODY CONTENT (to hash)'
});
request.body = DynamicString("BODY CONTENT,hash=", dynamicValue);
}
urlEncodedBody
urlEncodedBody
Returns an object
(dictionary) of the request’s application/x-www-form-urlencoded
body parameters. All values are returned as strings. The getter method getUrlEncodedBody()
is also available and allows access to the values as DynamicStrings.
(Writable property only for Importers).
// Read use (Dynamic Value, Code Generator...):
// form url-encoded body parameters as a strings
function evaluate(context) {
var request = context.getCurrentRequest();
// equivalent to `request.getUrlEncodedBody(false)`, e.g.
// {
// "name":"Paw",
// "type":"app"
// }
var bodyParameters = request.urlEncodedBody;
// enumerate parameters
for (var key in bodyParameters) {
var value = bodyParameters[key]; // string
console.log("" + key + "=" + value);
}
// return parameters keys
return Object.keys(bodyParameters).join(',');
}
Mutation is only available in Importer extensions.
Assign an object
(dictionary) containing the request body as application/x-www-form-urlencoded
body parameters. Keys must be strings
, value can either be strings or DynamicStrings. Existing body will be erased.
// Write use (Importers): set body values as strings
function import(context, items, options) {
var request = context.createRequest();
request.urlEncodedBody = {
name: 'Paw',
type: 'app'
};
}
// Write use (Importers): set body values as either DynamicStrings or strings
function import(context, items, options) {
var request = context.createRequest();
request.urlEncodedBody = {
name: 'Paw', // string
// DynamicString
type: DynamicString("Random=", DynamicValue('com.luckymarmot.NonceDynamicValue')),
};
}
multipartBody
multipartBody
Returns an object
(dictionary) of the request’s multipart/form-data
body parameters. All values are returned as strings. The getter method getMultipartBody()
is also available and allows access to the values as DynamicStrings.
(Writable property only for Importers).
// Read use (Dynamic Value, Code Generator...):
// multipart body parameters as a strings
function evaluate(context) {
var request = context.getCurrentRequest();
// equivalent to `request.getMultipartBody(false)`, e.g.
// {
// "name":"Paw",
// "type":"app"
// }
var multipartBody = request.multipartBody;
// enumerate body multipart parameters
for (var key in multipartBody) {
var value = multipartBody[value]; // string
console.log("" + key + "=" + value);
}
// return parameters keys
return Object.keys(multipartBody).join(',');
}
Mutation is only available in Importer extensions.
Assign an object
(dictionary) containing the request body as multipart/form-data
body parameters. Keys must be strings
, value can either be strings or DynamicStrings. Existing body will be erased.
// Write use (Importers): set body values as strings
function import(context, items, options) {
var request = context.createRequest();
request.multipartBody = {
name: 'Paw',
type: 'app'
};
}
// Write use (Importers): set body values as either DynamicStrings or strings
function import(context, items, options) {
var request = context.createRequest();
request.multipartBody = {
name: 'Paw', // string
// DynamicString
type: DynamicString("Random=", DynamicValue('com.luckymarmot.NonceDynamicValue')),
};
}
jsonBody
jsonBody
The request body as an object
(dictionary or array), when it uses the JSON body format.
(Writable property only for Importers).
// Read use (Dynamic Value, Code Generator...):
function evaluate(context) {
var request = context.getCurrentRequest();
// e.g.
// {
// "name":"Paw",
// "type":"app",
// "ratings":5,
// "enabled":true
// }
var jsonBody = request.jsonBody;
// parse some body keys...
return jsonBody["name"]; // "Paw"
}
Mutation is only available in Importer extensions.
Assign an object
to the request JSON body.
// Write use (Importers):
function import(context, items, options) {
var request = context.createRequest();
request.jsonBody = {
"name":"Paw",
"type":"app",
"ratings":5,
"enabled":true
};
}
followRedirects
followRedirects
Boolean value, whether the request should follow redirections when run.
(Writable property only for Importers).
// Read use (Dynamic Value, Code Generator...)
function evaluate(context) {
var request = context.getCurrentRequest();
return request.followRedirects; // true if follows redirections
}
Mutation is only available in Importer extensions.
// Write use (Importers)
function import(context, items, options) {
var request = context.createRequest();
request.followRedirects = true; // follows redirections
}
redirectMethod
redirectMethod
Boolean value, whether the request should be sent using its original HTTP method (verb) after a redirection, or should use GET
for requests after a redirection.
(Writable property only for Importers).
// Read use (Dynamic Value, Code Generator...)
function evaluate(context) {
var request = context.getCurrentRequest();
return request.redirectMethod; // true, next requests will use original method
}
Mutation is only available in Importer extensions.
// Write use (Importers)
function import(context, items, options) {
var request = context.createRequest();
request.redirectMethod = false; // next requests will all use GET
}
sendCookies
sendCookies
Boolean value, whether cookies stored in the current cookie jar will be sent (if match host, path, secure, etc.). If false
no cookies are sent (unless specified in a manually set Cookie
header).
(Writable property only for Importers).
// Read use (Dynamic Value, Code Generator...)
function evaluate(context) {
var request = context.getCurrentRequest();
return request.sendCookies; // true if cookies will be added
}
Mutation is only available in Importer extensions.
// Write use (Importers)
function import(context, items, options) {
var request = context.createRequest();
request.sendCookies = false; // do not send cookies automatically
}