httpPost
Runs an HTTP Post request and returns the HTTP response from the server. Also see callPostMethod.
The content type provided in the request's header is set by default to application/json. Use this function when the endpoint expects a JSON object parameter.
This is suitable for all modules of business service components.
Syntax
function httpPost(url: string, body: any, timeout?: number, customHeaders?: any): IFtosHttpResult
function httpPost(url: string, body: any, options?: IFtosHttpGetOptions): IFtosHttpResult
| Parameter | Type | Description |
|---|---|---|
url
|
string | The service endpoint's URI. For instance, the address of a REST API endpoint. |
body optional |
any | Key-value pairs in JSON format to be passed in the request's body. |
timeout optional |
number | Maximum number of seconds to wait for the HTTP response. |
customHeaders optional |
any | Key-value pairs in JSON format to be passed in the request's custom headers. |
options (optional) |
IFtosHttpGetOptions | Additional options to be passed to the HTTP request. |
Type Aliases
Allows you to define the HTTP request's additional options.
{
additionalHeaders? : any;
clientCertificate? : WorkflowClientCertificate;
httpVerb? : string;
multipartArguments? : IFtosHttpPostMultiPartArgument[];
responseType? : "Default" | "String" | "JSON" | "ByteArray";
timeout? : number;
}
| Property | Type | Description |
|---|---|---|
additionalHeaders(optional)
|
any | Key-value pairs in JSON format to be passed as the request's custom headers. |
clientCertificate(optional)
|
WorkflowClientCertificate | Registered client certificate required for client authentication via TLS/SSL. For information on how to register client certificates, see the Platform documentation. For information on how to retrieve a registered client certificate, see ftos.utils.getCertificate. |
httpVerb(optional)
|
string | Allows you to use an HTTP request method different from POST, such as GET, DELETE, etc. |
multipartArguments(optional)
|
IFtosHttpPostMultiPartArgument[] | Allows you to define settings for HTTP range requests when sending multpart documents over the network. |
responseType (optional) FintechOS 21.1.2 and later |
"Default" | "String" | "JSON" | "ByteArray" | The format in which the HTTP response will be returned:
|
timeout(optional)
|
number | Maximum number of seconds to wait for the HTTP response. |
Allows you to define settings for HTTP range requests when sending multpart documents over the network.
{
bytes : number[];
contentType : string;
fileName : string;
name : string;
}
| Property | Type | Description |
|---|---|---|
bytes
|
number[] | Indicates the range of bytes retrieved from the server. |
contentType
|
string | Value of the Content-Type header of the HTTP request. |
fileName
|
string | Name of the file transmitted. |
name
|
string | Name of the HTML field transmitted. |
Return Value
Returns the HTTP response of the HTTP Post request. For example:
{
"IsSuccess": true,
"Response": {
"NumberOfResults": 0,
"TotalNumber": 0,
"RequestedSkip": 0,
"RequestedTake": 0,
"Records": [
{
"previousBSId": "d056648b-fb96-4210-b253-6de285f27c48",
"businessStatusId": "cfad132f-d24b-49b3-a7ac-73d5b6905902",
"nextBusinessStatusId": null,
"ServerSDKTestid": "e796bdd6-efe6-43e6-b76a-6842d3197735",
"method": "M2",
"userId": "4afdc8a9-eb91-4359-81d6-c3a462fae866",
"createdByUserId": "4afdc8a9-eb91-4359-81d6-c3a462fae866",
"modifiedByUserId": "4afdc8a9-eb91-4359-81d6-c3a462fae866",
"businessUnitId": "a3d2909b-df67-49d6-b7e0-2dc912c12484",
"createdOn": "2020-01-10T10:24:48Z",
"modifiedOn": "2020-01-31T13:58:25Z",
"entityStatusId": "faccc388-151a-4c83-8953-cbac7d6c442a",
"file": "[{\"Name\":\"Quote_and_Buy_extended_data_model.png\",\"RealName\":\"Quote_and_Buy_extended_data_model_d9bf2c95-ab7d-4acc-befb-4b5d448f09f6.png\",\"IsSuccess\":true,\"Message\":null,\"ClientScript\":null,\"Serialized\":null,\"ErrorCode\":0,\"UIResult\":null}]",
"primaryattributedisplayname": "Methodology",
"aLookup1_name": "status2",
"previousBSId_displayname": "status2",
"aLookup2_name": "status3",
"businessStatusId_displayname": "status3",
"aLookup3_name": null,
"nextBusinessStatusId_displayname": null,
"aLookup4_userName": "jdoe",
"userId_displayname": "jdoe",
"aLookup5_userName": "jdoe",
"createdByUserId_displayname": "jdoe",
"aLookup6_userName": "jdoe",
"modifiedByUserId_displayname": "jdoe",
"aLookup7_name": "root",
"businessUnitId_displayname": "root",
"aLookup8_name": "Active",
"entityStatusId_displayname": "Active"
}
],
"Message": null,
"IsSuccess": true,
"ClientScript": null,
"Serialized": null,
"ErrorCode": 0,
"UIResult": null
},
"StatusCode": 200
}
If the response is returned in JSON format, the following properties are supported by the return value, corresponding to its first level keys: .IsSuccess, .Response, and .StatusCode.
The
Response key in the result is a JSON object, not a string as when using the callGetMethod function.Examples
In this example:
- We issue an httpGet request to the https://www.fintechos.com/Studio/api/authorize/GetToken endpoint to retrieve an access token. For details, see httpGet.
- We issue an httpPost request to the https://https://www.fintechos.com/Studio/api/OpenApi/GetById endpoint using the above token to retrieve data about the e796bdd6-efe6-43e6-b76a-6842d3197735 record in the Customers entity.
- We extract the Records from the request's Response.
- We save the result in a variable called cutomer_record.
token = httpGet('https://www.fintechos.com/Studio/api/authorize/GetToken?client_id=123&username=user&password=pass&response_type=token', null, null).Response['access_token'];
var customer_record = httpPost('https://www.fintechos.com/Studio/api/OpenApi/GetById', {
"ApiInfo": {
"Token": token
},
"Request": {
"EntityName": "Customers",
"EntityId": "e796bdd6-efe6-43e6-b76a-6842d3197735"
}
}).Response['Records'];
In this example:
- We connect to the /api/v3/pet API endpoint on the https://petstore3.swagger.io web server.
- We add a new pet to the store based on the Swagger pet store OpenAPI specification.
- The HTTP request includes the following custom headers:
Key Value api_key ftos Content-Type application/json Content-Length 281 - We display a feedback message, depending on whether the request was successful or not. For more information, see ftos.context.response.setMessage.
let request = httpPost('https://petstore3.swagger.io/api/v3/pet',
{
"id": 10,
"name": "doggie",
"category": {
"id": 1,
"name": "Dogs"
},
"photoUrls": [
"string"
],
"tags": [
{
"id": 0,
"name": "string"
}
],
"status": "available"
},{
"api_key": "ftos",
"Content-Type": "application/json",
"Content-Length": 281
});
if (request.isSuccess){
ftos.context.response.setMessage('Doggie added', true)
}else{
ftos.context.response.setMessage('Something went wrong', false)
}