Make POST requests with request template

Hello, just started making an integration app for Freshwork, only to get halfway and notice that API calls to the platform now uses a new syntax. I’ve been able to swap them out for the request-template, the GET requests work well, but how exactly does one make a POST request with this? The samples don’t have examples of this, and neither does the documentation.
Is the post body set in the query property or elsewhere?
Thanks.

Hi esi.re,

request example:

{
  "createNote": {
    "schema": {
      "method": "POST",
      "host": "<%= iparam.domain %>.freshservice.com",
      "path": "/api/v2/tickets/<%= context.id %>/notes",
      "headers": {
        "Authorization": "Basic <%= encode(iparam.apikey) %>",
        "Content-Type": "application/json"
      }
    }
  },
  "updateTicket": {
    "schema": {
      "method": "PUT",
      "host": "<%= iparam.domain %>.freshservice.com",
      "path": "/api/v2/tickets/<%= context.id %>",
      "headers": {
        "Authorization": "Basic <%= encode(iparam.apikey) %>",
        "Content-Type": "application/json"
      }
    }
  }
}

server.js:

await $request
          .invokeTemplate('createNote', {
            context: {
              id: args['data']['ticket']['id'],
            },
            body: JSON.stringify({
              body: msg,
            }),
          })
          .then(function (data) {
            console.log(data)
          })

await $request
          .invokeTemplate('updateTicket', {
            context: {
              id: args['data']['ticket']['id'],
            },
            body: JSON.stringify({
              custom_fields: {
                my_custom_check: true,
              },
            }),
          })
          .then(function (data) {
            console.log(data)
          })
1 Like

Hello @Mattia_Piparo
Thanks for the response, I’ll check this out.

This topic was automatically closed 6 days after the last reply. New replies are no longer allowed.