HTTP Request Action Workflow

Hello Developers,

I was going through the Workflow documentation but couldn’t find any sample related to HTTP action. Can anyone please share the sample workflows for the “HTTP Request” action?

Thank you,
Subash

The HTTP Request action has undergone a major update. Some of the information in this solution may no longer be valid.

Hi @schouhan ,

There’s some non-intuitive quirks to the HTTP request action in beta Workflows, some of which may be inadequate for your needs. The workflows team is working on resolving these shortcomings in HTTP for GA or soon after. For the beta HTTP request action, I was able to get a simple GET call working with the following script.

{
	"name": "HTTP Test",
	"description": "",
	"definition": {
		"start": "HTTP Request",
		"steps": {
			"HTTP Request": {
				"actionId": "sp:http",
				"attributes": {
					"body": "",
					"headers": {
						"Authorization": "Bearer <access_token>"
					},
					"method": "GET",
					"url": "https://devrel.api.identitynow.com/v3/sources"
				},
				"nextStep": "Send Email",
				"selectResult": "$.sources",
				"type": "action"
			},
			"Send Email": {
				"actionId": "sp:send-email",
				"attributes": {
					"body.$": "$.sources.body.body[*].name",
					"recipientId.$": "$.id",
					"subject": "Sources"
				},
				"nextStep": "success",
				"type": "action"
			},
			"success": {
				"type": "success"
			}
		}
	},
	"creator": {
		"type": "IDENTITY",
		"id": "2c9180867624cbd7017642d8c8c81f67",
		"name": "colin.mckibben"
	},
	"trigger": {
		"type": "EVENT",
		"attributes": {
			"id": "idn:source-created"
		}
	}
}

If you want to upload this to your workflows environment, be sure to use your ID when invoking a test event:

Things to note:

  1. response bodies are wrapped in two body objects. The GET sources API call that I’m using returns a list of objects.
[
  { ... },
  { ... },
]

Workflows wraps the response in additional body objects so that it actually looks like this:

{
  "body": {
    "body": {
       [
         { ... },
         { ... }
       ]
    }
  }
}

Hence, the need for the JSON path $.sources.body.body[*].name

  1. Workflows currently doesn’t support variable substitution, which means there is no way to create strings that mix literal values with variables. You can either provide a static string literal, or a single JSONpath. This proves problematic for post bodies (or any other parameter for that matter) where you need to construct a complicated JSON string from several variables in the data model. Unless your post body is a static string literal, or you can create the post body from a single JSONpath expression, you will find it impossible to use POST. We are planning on implementing variable substitution to alleviate this problem.
2 Likes

Hello @colin_mckibben any news about the variable substitution limitation? We are trying to create a workflow with a HTTP request step in which we will try to send a JSON body with variables such as “key” : “$.trigger.attributes.contracttype” . The information is beign sent, but as $.trigger.attributes.contracttype instead of the real value. Any idea?

Thank you in advance.
Beatriz.

1 Like

Variable insertion is on the roadmap, but it won’t be available this quarter. I don’t have a firm date on when this will be added.

Hello @colin_mckibben thanks for your reply. So there is a workaround to this? As prerequisite, we will need to perform a HTTP action with a JSON body like:

{“u_contracttype”:"$.trigger.attributes.sfId",“u_costcenter”:"$.trigger.attributes.endDate",“Xu_employeecategory”:"$.trigger.attributes.sfId"}

As you can see, the values are calculated based on the identity information. How we can do that? I saw there is an option to set the body selecting a predifined variable but I cannot find the way to store all the body in one variable and then use it on the HTTP body .

Regards,
Beatriz.

Unfortunately, there is no way to accomplish what you are trying to do as of today, but it will be supported in a future release of Workflows. For now, you can only use a string with no variables, or a single variable defined in JSONpath. There is no in-between.

Hi @colin_mckibben ! As workaround we are trying to definyng the body on a previus step, send email type. We are trying to call the body on the HTTP request step as variable but we can’t. If I remember well, we can send information from one step to another, something change? it’s a new tech limitation. Find bellow a little diagram about we are trying to do:

Trigger > Send Email (create the body) > HTTP request ( use the body created on the step before)

Thank you in advance.
Regards.

Beatriz.

Hi @Beatriz ,

I’m don’t recall if Send Email ever had an output. I tested on my end and can confirm that send email doesn’t return any variables that can be used in subsequent actions, so you can’t craft the HTTP body using a previous Send Email template.

Hello @colin_mckibben,

Yes, the Send Email step doesnt return any value. As an alternative we are going to send by email the body that we wanted initially sent using an HTTP request step. The issue we are facing now is that one week ago, we were able to send a body with the information calculated on the Context, now is failing. Do you know is something changes?

The error we are getting is:
{
“type”: “WorkflowExecutionFailed”,
“timestamp”: “2022-05-23T16:44:26.436650878Z”,
“attributes”: {
“error”: “actionStep(Send Email) Error: bad json path: must start with $”
}
}

One week ago the same step with the same logic worked.

@Beatriz,

I’m not sure what changed, but looking at your code it appears you context value is no longer valid. The context should be a simple JSONpath, like $, and then you can use JSONpath to reference individual variables in your body. Please see below for an example that works in my environment.

I also hope we’ll be able to use the same variables when they come out in the URL field and not just the body. I would think this would work similar to the way the email template works.

Hi @colin_mckibben ,

Any timelines for release of the variable insertion within the HTTP workflow step?

Thanks!

Looking for an update on this functionality as well. This would be super useful!

Looks like it possible now

2 Likes

A post was split to a new topic: Workflows: Use HTTP Request to authenticate to OAuth endpoint