hi,
i need to create a http post request with content type "application/x-www-form-urlencoded",
I have created a request, but it's not working:
###############################################################################
# Cloud Workflow
###############################################################################
define ibm_add_tags($data,$tags_to_add, $$rs_optima_host, $api_key) return $all_response do
$$debug=true
$all_response=[]
$tags_obj={}
$response = http_request(
verb: "post",
host: "iam.cloud.ibm.com",
href: "/identity/token",
https: true,
headers:{
"Host": "iam.cloud.ibm.com",
"Content-Type": "application/x-www-form-urlencoded"
},
body: join(["grant_type=urn%3Aibm%3Aparams%3Aoauth%3Agrant-type%3Aapikey&apikey=", $api_key])
)
$all_response << $response
end
I use the same request in Datasource definition and works well:
###############################################################################
# Datasources
###############################################################################
datasource "ds_ibm_auth" do
request do
host "iam.cloud.ibm.com"
verb "POST"
path "/identity/token"
header "Host", "iam.cloud.ibm.com"
header "Content-Type", "application/x-www-form-urlencoded"
body join(["grant_type=urn%3Aibm%3Aparams%3Aoauth%3Agrant-type%3Aapikey&apikey=", $param_api_key])
end
result do
encoding "json"
collect jmes_path(response,"[@]") do
field "access_token", jmes_path(col_item,"access_token")
end
end
end
Any idea how to do this request?
How can i debug my code in cloud workflow? How can I log the response for throubleshooting?
Mar 07, 2023 12:01 PM
In the code provided you seem to be missing the access token in the CWF workflow (field "access_token", jmes_path(col_item,"access_token")) or did you do this deliberately to avoid exposing it here?
Thanks,
Mar 29, 2023 10:09 AM
Hi John,
The "access token" is a token to access my account.
I did this deliberately to avoid exposing it here
The "http request" above is correct, it works, but sometimes I get errors and I can't debug what's going on
Mar 29, 2023 11:11 AM
Please refer to How to get logs from cloud workflow
Thanks,
Apr 11, 2023 01:34 AM