Make HTTP requests - Fluid Topics - Latest

Fluid Topics Configuration and Administration Guide

Category
Reference Guides
Audience
public
Version
Latest

ADMIN users can make HTTP requests in the Profile mappers assistant drawer.

Enter http. followed by get, post, put, or delete. It is possible to add the following optional methods:

  • .body()
  • .clientCertificate()

  • .header()

    It is safe to include credentials. The JavaScript code runs in the backend of Fluid Topics.

  • .connectTimeout()

  • .responseTimeout()

    Both connectTimeout and responseTimeout take values in milliseconds.

  • .send()

  • .sendAsync()

    • The .send() and .sendAsync() methods give access to response methods.
    • .sendAsync() returns a promise.
    • When making API calls to the portal itself, it is possible to use the baseUrl variable. For doc.fluidtopics.com, the baseUrl value is https://doc.fluidtopics.com/.

POST fictional example using .send():

try {
    const response = http.post('https://example.com/api/accounts/create')
    .header('Content-Type', 'application/json')
    .body(JSON.stringify({
      "example": "value"
    })).send();

    const responseBody = response.asString();
    const jsonData = JSON.parse(responseBody);
    console.log(JSON.stringify(jsonData, null, 2));

} catch (issue) {
    console.error('An error occurred:', issue);
}

POST fictional example using .sendAsync():

http.post('https://example.com/api/accounts/create')
  .header('Content-Type', 'application/json')
  .body(JSON.stringify({
    "example": "value"
  }))
  .sendAsync()
  .then(response => {
    return response.asString();
  })
  .then(responseBody => {
    const jsonData = JSON.parse(responseBody);
    console.log(JSON.stringify(jsonData, null, 2));
  })
  .catch(issue => {
    console.error('An error occurred:', issue);
  });