How do I use a remote web service

Most remote web service allow their APIs to be accessed from server on a different origin (domain) than their own by enabling Cross-Origin Resource Sharing (CORS). You can read more about CORS here: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS

However if this is not the case for the web service your application is using, you can use the SDK http proxy. The proxy ships with your Deskpro installation, meaning it is hosted on the same domain as your Deskpro installation.

The http proxy supports GET, POST, PUT, DELETE requests:

GET

    // obtain a reference to the API Client from the Application Client
    const { restApi } = this.props.dpapp;

    // issue a GET request
    restApi.fetchProxy(
      `https://us16.api.mailchimp.com/3.0/search-members?query=joe@example.com`,
      {
        method: 'GET',
        headers: {
          'Accept': 'application/json' ,
          'X-Proxy-SignWith': 'basic_auth anystring:{{apiKey}}'
        }
      }).then(({body, headers}) => {
        console.log('response: ', body, headers)
    });

DELETE

for POST and PUT requests you need to specify the Content-Length header:

POST

PUT

Last updated