[英]Is it possible to perform a POST API call in PHP with authorization first?
我刚在大学开始 CS,想在假期创建一个小的 webdev 项目。 我创建了一个简单的联系表单,它要求用户提供一些数据(文本、下拉选项)。 按下提交按钮后,我想对 UiPath Orchestrator 执行 POST api 调用以触发机器人......
由于这是我第一次处理 PHP 我不太确定如何解决这个问题。 我能够从提交的表单中获取数据。 但是现在我正在为 API 调用而苦苦挣扎。 我已经在 Swagger UI 和 Postman 中对其进行了测试,并且可以正常工作。
问题:我必须通过批处理器 ID 进行身份验证,该 ID 也可以通过 API 调用检索。
问题:
创建一个负责 API 调用的新 function 是否有意义,因为我可能想添加其他触发其他机器人进程的 forms?
根据我的研究,我很确定我必须使用 cURL 调用(或者这是错误的吗?)。如果我每次按下提交按钮时都需要进行身份验证,如何检索令牌并将其作为 header 传递(或处理实际 POST 调用的 idk) 参数?
如果你不能理解我的问题,我很抱歉,我会尽力重新制定它。 但由于我根本没有这方面的经验,我希望你能原谅我。
已经期待您的帮助!
到目前为止,这是我的代码:
add_action('wpcf7_mail_sent','cf7_api_sender');
function cf7_api_sender($contact_form){ $title = $contact_form ->title;
if ($title === 'MA_Demo'){
$submission = WPCF7_Submission::get_instance();
if ($submission){
$posted_data = $submission->get_posted_data();
$firstname = $posted_data['Firstname'];
$lastname = $posted_data['Lastname'];
$department = $posted_data['Departement'][0];
$workload = $posted_data['Workload'][0];
/*
this is what I found so far but ofc it does not work at all.. do I have to put the body (itemData) into the args?
and where can i pull the beacon token and add it?
$url = '"https://cloud.uipath.com/..../..../orchestrator_/odata/Queues/UiPathODataSvc.AddQueueItem"
$args =[
accept: application/json
X-UIPATH-OrganizationUnitId: .....
{ \"itemData\": { \"Name\": \"...\", \"Priority\": \"...\", \"Reference\": \"...\", \"SpecificContent\": {\"key1\": \"Rick \", \"key2\": \"Roll\"} }}
]
*/
/* this was to test if it works to pull data
$myfile = fopen("data.txt", "w") or die("Unable to open file!");
$txt = $firstname.$lastname.$department.$workload;
fwrite($myfile, $txt);
fclose($myfile);
*/
}
}
}
首先,您需要使用您的租户、用户名和密码调用 /api/Account/Authenticate。 它会返回类似的东西
{
"result": "HzptFsZpGMS64j5DTb4TqX-cHVv2AtC4noVCQrkHKr54r...",
"targetUrl": null,
"success": true,
"error": null,
"unAuthorizedRequest": false,
"__abp": true
}
然后,通过添加 header 项目,在 Add Queue Item 调用中使用该结果
"Authorization":"Bearer " & result ("Bearer HzptFsZpGMS64...")
这适用于 Orchestrator on-prem 2019.10,因此云可能会有所不同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.