# How to connect to a remote web service that provides tokens

**URL:** <https://community.dreamfactory.com/t/how-to-connect-to-a-remote-web-service-that-provides-tokens/2532>\
**Category:** Connecting to Web Services\
**Created:** [April 14, 2016, 10:18am UTC](https://community.dreamfactory.com/t/how-to-connect-to-a-remote-web-service-that-provides-tokens/2532 "2016-04-14T10:18:32Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mymanga](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/mymanga/32/673_2.png) [@mymanga](https://community.dreamfactory.com/u/mymanga)\
**Post date:** [April 14, 2016, 10:18am UTC](https://community.dreamfactory.com/t/how-to-connect-to-a-remote-web-service-that-provides-tokens/2532/1 "2016-04-14T10:18:32Z")

</div>

I am trying to access a remote rest api that generates a token after providing it with an app id and secret key. How do I add it to dreamfactory. I tried going over the edmunds api tutorial but I dont think it covers what I am trying to achieve.

---

<div class="post-metadata">

**Author:** ![andersonmuller](https://avatars.discourse-cdn.com/v4/letter/a/7feea3/32.png) [@andersonmuller](https://community.dreamfactory.com/u/andersonmuller)\
**Post date:** [April 14, 2016, 12:53pm UTC](https://community.dreamfactory.com/t/how-to-connect-to-a-remote-web-service-that-provides-tokens/2532/2 "2016-04-14T12:53:29Z")

</div>

Hi @mymanga,

I think edmunds api tutorial is a good start point, lets build a example:

First you need to create a new service, type: **Remote Service**

 ![](https://canada1.discourse-cdn.com/flex035/uploads/dreamfactory/original/1X/f58269fad6a98751b2c546fffef669d6ac739afb.png)

Go to the tab Config, insert the remote server URL and create the **Parameters** you want to send from your client to the remore server, check **Outbound** and all the **Verbs**

 ![](https://canada1.discourse-cdn.com/flex035/uploads/dreamfactory/original/1X/db24add5e6730618e06ea7c22d1b59d0b690600d.png)

Then paste this json in **Service Definition** tab, do this and your service will be displayed in API Docs:

```
{
  "swagger": "2.0",
  "info": {
    "version": "2.0",
    "title": "Remote WS Example",
    "description": "Remote ws example."
  },
  "paths": {
    "/remotews": {
      "post": {
        "tags": [
          "remotews"
        ],
        "description": "Get token.",
        "parameters": [
          {
            "name": "app_id",
            "in": "formData",
            "description": "application id",
            "type": "string",
            "required": true
          },
          {
            "name": "secret_key",
            "in": "formData",
            "description": "my secret key",
            "type": "string",
            "required": true
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "schema": {
              "$ref": "#/definitions/TokenSuccess"
            }
          },
          "default": {
            "description": "Error",
            "schema": {
              "$ref": "#/definitions/TokenError"
            }
          }
        }
      }
    }
  },
  "definitions": {
    "TokenSuccess": {
      "type": "object",
      "properties": {
        "token": {
          "type": "string"
        }
      }
    },
    "TokenError": {
      "type": "object",
      "properties": {
        "code": {
          "type": "integer",
          "format": "int32",
          "description": "Error code."
        },
        "message": {
          "type": "string",
          "description": "String description of the error."
        }
      }
    }
  },
  "parameters": {
    "app_id": {
      "name": "app_id",
      "in": "formData",
      "description": "application id",
      "required": true,
      "type": "string"
    },
    "secret_key": {
      "name": "secret_key",
      "in": "formData",
      "description": "my secret key",
      "required": true,
      "type": "string"
    }
  }
}

```

Go to the **API Docs** , find your service, complete the fields and hit the button **Try it out** :

 ![](https://canada1.discourse-cdn.com/flex035/uploads/dreamfactory/original/1X/28c450951a4ee866e8d8787af8759a5270cb94d1.png)

Hope it helps you 😉

---

<div class="post-metadata">

**Author:** ![mymanga](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/mymanga/32/673_2.png) [@mymanga](https://community.dreamfactory.com/u/mymanga)\
**Post date:** [April 14, 2016, 2:22pm UTC](https://community.dreamfactory.com/t/how-to-connect-to-a-remote-web-service-that-provides-tokens/2532/3 "2016-04-14T14:22:47Z")

</div>

Thanks but getting error:

> “405 Method not allowed”

It seems to only accept GET requests

When you run it in the browser

> [http://api.example.com/token/?appid=q1w2e3&key=1qazxsw23edc](http://api.example.com/token/?appid=q1w2e3&key=1qazxsw23edc)

It returns;

> {  
> “status”: “SUCCESS”,  
> “token”: “b9abb385c2f33434a3586295044e508d”  
> }

When I change the request to GET in the Service Definition, response on API DOCS is;

> “405 Content in response can not be resolved to acceptable content type.”

---

<div class="post-metadata">

**Author:** ![andersonmuller](https://avatars.discourse-cdn.com/v4/letter/a/7feea3/32.png) [@andersonmuller](https://community.dreamfactory.com/u/andersonmuller)\
**Post date:** [April 14, 2016, 2:45pm UTC](https://community.dreamfactory.com/t/how-to-connect-to-a-remote-web-service-that-provides-tokens/2532/4 "2016-04-14T14:45:44Z")

</div>

No problem, change the json in **service definition** to this:

```
 {
  "swagger": "2.0",
  "info": {
    "version": "2.0",
    "title": "Remote WS Example",
    "description": "Remote ws example."
  },
  "paths": {
    "/remotews": {
      "get": {
        "tags": [
          "remotews"
        ],
        "description": "Get token.",
        "parameters": [
          {
            "name": "appid",
            "in": "query",
            "description": "application id",
            "type": "string",
            "required": true
          },
          {
            "name": "key",
            "in": "query",
            "description": "my secret key",
            "type": "string",
            "required": true
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "schema": {
              "$ref": "#/definitions/TokenSuccess"
            }
          },
          "default": {
            "description": "Error",
            "schema": {
              "$ref": "#/definitions/TokenError"
            }
          }
        }
      }
    }
  },
  "definitions": {
    "TokenSuccess": {
      "type": "object",
      "properties": {
        "token": {
          "type": "string"
        }
      }
    },
    "TokenError": {
      "type": "object",
      "properties": {
        "code": {
          "type": "integer",
          "format": "int32",
          "description": "Error code."
        },
        "message": {
          "type": "string",
          "description": "String description of the error."
        }
      }
    }
  },
  "parameters": {
    "app_id": {
      "name": "appid",
      "in": "query",
      "description": "application id",
      "required": true,
      "type": "string"
    },
    "secret_key": {
      "name": "key",
      "in": "query",
      "description": "my secret key",
      "required": true,
      "type": "string"
    }
  }
}

```

I’m assuming that your **Remote Service** has the parameters **appid** and **key**

---

<div class="post-metadata">

**Author:** ![mymanga](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/mymanga/32/673_2.png) [@mymanga](https://community.dreamfactory.com/u/mymanga)\
**Post date:** [April 14, 2016, 3:20pm UTC](https://community.dreamfactory.com/t/how-to-connect-to-a-remote-web-service-that-provides-tokens/2532/5 "2016-04-14T15:20:01Z")

</div>

First hurdle…crossed/jumped/ 🙂 . Seeing how the url is meant only get a session token, how do I use that token to make subsequent requests to consume the api seeing how

token is:

> [http://api.example.com/token/?appid=q1w2e3&key=1qazxsw23edc](http://api.example.com/token/?appid=q1w2e3&key=1qazxsw23edc)

data is;

> [http://api.example.com/cows](http://api.example.com/cows)  
> [http://api.example.com/goats](http://api.example.com/goats)

Can all this goes into one Remote Web service??

---

<div class="post-metadata">

**Author:** ![andersonmuller](https://avatars.discourse-cdn.com/v4/letter/a/7feea3/32.png) [@andersonmuller](https://community.dreamfactory.com/u/andersonmuller)\
**Post date:** [April 14, 2016, 4:14pm UTC](https://community.dreamfactory.com/t/how-to-connect-to-a-remote-web-service-that-provides-tokens/2532/6 "2016-04-14T16:14:46Z")

</div>

You can config the Remote Service (remotews) with you base url ([http://api.example.com/](http://api.example.com/)), when you call the dreamfactory just append the endpoint (http://your\_dreamfactory/api/v2/remotews/cows, http://your\_dreamfactory/api/v2/remotews/gosts or http://your\_dreamfactory/api/v2/remotews/token)

If you are not developing some APP to consume dreamfactory services, you will need to make the calls one by one, changing the params.  
OR  
Create a [Custom Script](https://wiki.dreamfactory.com/DreamFactory/Tutorials#Scripting) ([read this too](https://wiki.dreamfactory.com/DreamFactory/Features/Scripting)) to call the remote api, get the token, insert the token in a new request and return the response.

For testing, you can use [Postman](http://www.getpostman.com/) (app for chrome) , if u dont know, you will like. 🙂

Cheers

---

<div class="post-metadata">

**Author:** ![mymanga](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/mymanga/32/673_2.png) [@mymanga](https://community.dreamfactory.com/u/mymanga)\
**Post date:** [April 14, 2016, 7:30pm UTC](https://community.dreamfactory.com/t/how-to-connect-to-a-remote-web-service-that-provides-tokens/2532/7 "2016-04-14T19:30:12Z")

</div>

Thank you. lemme work on that. Will update on progress. Thank you for the awesome support

---

<div class="post-metadata">

**Author:** ![andersonmuller](https://avatars.discourse-cdn.com/v4/letter/a/7feea3/32.png) [@andersonmuller](https://community.dreamfactory.com/u/andersonmuller)\
**Post date:** [April 14, 2016, 7:33pm UTC](https://community.dreamfactory.com/t/how-to-connect-to-a-remote-web-service-that-provides-tokens/2532/8 "2016-04-14T19:33:57Z")

</div>

Good luck with your work! I’m glad to help 🙂
