Php 工作流:通过API添加作业
我正在尝试向Workflow Max API添加作业。我似乎遇到了API,但我一直收到错误消息:Php 工作流:通过API添加作业,php,api,Php,Api,我正在尝试向Workflow Max API添加作业。我似乎遇到了API,但我一直收到错误消息: Message not in expected format. The following required element was missing - Job/ClientID 我确定添加了客户ID,但似乎有问题。代码如下: function post_job_to_workflow_max($job_data) { // configure our connection to th
Message not in expected format. The following required element was missing - Job/ClientID
我确定添加了客户ID,但似乎有问题。代码如下:
function post_job_to_workflow_max($job_data) {
// configure our connection to the api
$api_token = 'API_KEY';
$acc_key = 'ACC_TOKEN';
$url = 'https://api.workflowmax.com/job.api/add?apiKey=' . $api_token . '&accountKey=' . $acc_key;
// Job data must match the format required by WorkflowMax
// currently accepts XML data
// see: https://www.workflowmax.com/api/job-methods#POST%20add
$xml = new SimpleXMLElement("<Job></Job>");
$xml->addChild('Name', $job_data[0]);
$xml->addChild('Description', $job_data[1]);
$xml->addChild('ClientID', 18754031);
// $clientID = $xml->addChild('Client');
// $clientID->addChild('ID', 18754031);
// $clientID->addChild('Name', "TEST CLIENT");
$xml->addChild('State', 'Planned');
$xml->addChild('StartDate', $job_data[2]);
$xml->addChild('DueDate', $job_data[3]);
// print_r($xml);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml->asXML());
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: text/xml',
'Content-Length: ' . strlen($xml->asXML()))
);
$output = curl_exec($ch);
curl_close($ch);
$result = simplexml_load_string($output);
print_r($result);
}
function post_job_to_workflow_max($job_data){
//配置与api的连接
$api_令牌='api_密钥';
$acc_密钥='acc_令牌';
$url='1https://api.workflowmax.com/job.api/add?apiKey=“.$api_令牌”。&accountKey=”.$acc_密钥;
//作业数据必须与WorkflowMax要求的格式匹配
//当前接受XML数据
//见:https://www.workflowmax.com/api/job-methods#POST%20add
$xml=新的SimpleXMLElement(“”);
$xml->addChild('Name',$job_data[0]);
$xml->addChild('Description',$job_data[1]);
$xml->addChild('ClientID',18754031);
//$clientID=$xml->addChild('Client');
//$clientID->addChild('ID',18754031);
//$clientID->addChild('Name',“测试客户端”);
$xml->addChild('State','Planned');
$xml->addChild('StartDate',$job_data[2]);
$xml->addChild('DueDate',$job_data[3]);
//打印(xml);
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$URL);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$xml->asXML());
curl_setopt($ch,CURLOPT_HTTPHEADER,数组(
'内容类型:text/xml',
“内容长度:”.strlen($xml->asXML()))
);
$output=curl\u exec($ch);
卷曲关闭($ch);
$result=simplexml\u load\u字符串($output);
打印(结果);
}
如果有人有使用WFM的经验,很高兴听到你是如何使用它的
谢谢,所以在回答我自己的问题时,我终于解决了这个问题 我这样做的方式是从用于将客户端发布到WorkFlow Max的函数返回客户端ID。请参见代码: 1) 投递客户
function post_client_to_workflowmax($client_data) {
// configure our connection to the api
$api_token = 'YOUR_TOKEN';
$acc_key = 'YOUR_KEY';
$url = 'https://api.workflowmax.com/client.api/add?apiKey=' . $api_token . '&accountKey=' . $acc_key;
// Client data must match the format required by WorkflowMax
// currently accepts XML data
// These indexes match up with how the data has been stored
// see: https://www.workflowmax.com/api/client-methods#POST%20add
$xml = new SimpleXMLElement("<Client></Client>");
$xml->addChild('Name', htmlspecialchars($client_data[2]));
$xml->addChild('Email', htmlspecialchars($client_data[9]));
$xml->addChild('Phone', htmlspecialchars($client_data[10]));
$xml->addChild('Address', htmlspecialchars($client_data[3]) . ' ' . htmlspecialchars($client_data[4]));
$xml->addChild('City', htmlspecialchars($client_data[5]));
$xml->addChild('Postcode', htmlspecialchars($client_data[7]));
$xml->addChild('Country', htmlspecialchars($client_data[8]));
$xml->addChild('IsProspect', 'No');
$contacts = $xml->addChild('Contacts');
$contact = $contacts->addChild('Contact');
$name = $contact->addChild('Name', htmlspecialchars($client_data[0]) . ' ' . htmlspecialchars($client_data[1]));
// POST request
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml->asXML());
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: text/xml',
'Content-Length: ' . strlen($xml->asXML()))
);
$output = curl_exec($ch);
curl_close($ch);
// Create an array from the data that is sent back from the API
$result = simplexml_load_string($output);
$clientID = NULL;
// here we get the ID created for this client and pass it into the variable $clientID
foreach($result->Client as $k => $v) {
$clientID = $v->ID;
}
return $clientID;
}
其中$client必须是一个数据数组。这适用于我的案例,但可能不适用于您的特定案例,因此您可能需要编辑字段等
希望这能帮助有同样问题的人。虽然不是最优雅的代码,但它完成了任务 Ryan,你弄明白了吗?我正在查看你的代码,似乎找不到任何与我的操作方式不同的地方。是的,请参见下面我自己的答案。
function post_job_to_workflow_max($job_data, $clientID) {
// configure our connection to the api
$api_token = 'YOUR_TOKEN';
$acc_key = 'YOUR_KEY';
$url = 'https://api.workflowmax.com/job.api/add?apiKey=' . $api_token . '&accountKey=' . $acc_key;
// Job data must match the format required by WorkflowMax
// currently accepts XML data
// see: https://www.workflowmax.com/api/job-methods#POST%20add
$xml = new SimpleXMLElement("<Job></Job>");
$xml->addChild('ClientID', $clientID);
$xml->addChild('Name', htmlspecialchars($job_data[0]));
$xml->addChild('Description', htmlspecialchars($job_data[1]));
$xml->addChild('State', 'Planned');
$xml->addChild('StartDate', htmlspecialchars($job_data[2]));
$xml->addChild('DueDate', htmlspecialchars($job_data[3]));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml->asXML());
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: text/xml',
'Content-Length: ' . strlen($xml->asXML()))
);
$output = curl_exec($ch);
curl_close($ch);
$result = simplexml_load_string($output);
}
$id = post_client_to_workflowmax($client);
post_job_to_workflow_max($job, $id);