HTTP Request Agent Credential

With the HTTP Request Agent Credential type, data retrieved from the response of an existing HTTP Request Agent can be used with a credential widget. When an agent with a HTTP Request Agent credential runs, Tines will run the corresponding agent in the background and embed the data at the specified path in the response.

Creating a HTTP Request Agent Credential

When creating a HTTP Request Agent Credential, you will need to specify the name of the credential, an existing HTTP Request Agent (this can be in any story) and the JSONPath where the data that sould be used in the credential can be located in the response.

Example

Suppose we have a HTTP Request Agent called Get auth token that makes a request to a service to get an access token for subsequent requests. The agent config for this agent is shown below:

{
  "url": "https://www.token-generator.com/oauth2/token",
  "content_type": "form",
  "method": "post",
  "payload": {
    "assertion": "{% credential token_generator %}"
  },
  "expected_update_period_in_days": "1"
}

When this agent runs, it emits an event similar that shown below:

{
	"get_auth_token": {
		"body": {
			"access_token": "ya29.Gn9qB-2K9xbys1DCgzyXNrIWuIIE0CuoAuSj5dYqWiMa7JNjarCZxhjgxbPkAGtADLIck87KIuDtYp3o71NRppfyA2tpTfD1uRG6lsjfoQD4g86jbzyjcTLbOn-oD_i8eQf4hQnUhkcrrktQ70GBJmnLwrOCaH7bTthMQLzV21p5",
			"expires_in": 3600,
			"token_type": "Bearer"
		},
		"headers": {},
		"status": 200
	}
}

We would use the access_token defined at {{.get_auth_token.body.access_token}} in subsequent requests. We can use this agent in a HTTP Request Agent Credential. See screenshot below:

HTTP Request Agent Credential
HTTP Request Agent Credential

We can now use another HTTP Request Agent to make requests using the new credential. When the below agent runs, it will first run the Get auth token agent in the background, extract the returned access_token and embed it in Authorization header, where the credential widget is defined:

{
  "url": "https://www.another-service.com/admin/login",
  "content_type": "json",
  "method": "get",
  "headers": {
    "Authorization": "Bearer {% credential Get auth token %}"
  },
  "expected_update_period_in_days": "1"
}