تخطي إلى المحتوى الرئيس

Recipe: API request that uses the proxy

في Widgets
قائمة المؤلفين
منشور: 11 نوفمبر 2021|آخر تحديث: 12 نوفمبر 2021

In this recipe we’re going to create a widget that will fetch some HTML content from a remote server via the apps proxy and render it within the widget.

Firstly, create a new widget and under the “Description” tab, give the widget a title and description.

We don’t to define any settings or special permissions. We do need to define the following:

  • Ticket Target - Under the "Settings" tab check "Ticket" under targets

  • Proxy Whitelist - Under the "Proxy" tab add the following URL: https://dinoipsum.com/api.* Method: GET with a Timeout of 5 seconds.

image.png

Under the “Code” tab, in the “body” section add the following code:

<div class="container" id="content"></div> <script> Deskpro.client.onShow(function () { Deskpro.utils.fetch("https://dinoipsum.com/api/?format=html").then(function (response) { response.text().then(function (content) { document.getElementById('content').innerHTML = content; Deskpro.client.resize(); }); }); }); </script>
copy

image.png

In this example we're requesting some HTML from a third party API and injecting it directly into the widget container element. Notice that we've set an id on the container div so that we can reference it once we have a successful response from the API. Also notice the call to Deskpro.client.resize(). This tells Deskpro to resize the app window as we've added content that may overflow.

Ok, let's take a look at the widget in the Deskpro agent interface. Select any ticket and click on our newly created widget in the ticket sidebar and you should see the following:

image.png

مفيد.غير مفيد

وجد 0 من 1 شخص هذه الصفحة مفيدة

الصفحة التاليةRecipe: API request that uses a secret and proxy
الصفحة السابقةRecipe: API request that returns JSON (prettified)

الرجاء تسجيل الدخول أو التسجيل لتقديم تعليق.