<tfoot id='Q6pGi'></tfoot>
<i id='Q6pGi'><tr id='Q6pGi'><dt id='Q6pGi'><q id='Q6pGi'><span id='Q6pGi'><b id='Q6pGi'><form id='Q6pGi'><ins id='Q6pGi'></ins><ul id='Q6pGi'></ul><sub id='Q6pGi'></sub></form><legend id='Q6pGi'></legend><bdo id='Q6pGi'><pre id='Q6pGi'><center id='Q6pGi'></center></pre></bdo></b><th id='Q6pGi'></th></span></q></dt></tr></i><div id='Q6pGi'><tfoot id='Q6pGi'></tfoot><dl id='Q6pGi'><fieldset id='Q6pGi'></fieldset></dl></div>

    <legend id='Q6pGi'><style id='Q6pGi'><dir id='Q6pGi'><q id='Q6pGi'></q></dir></style></legend>

    <small id='Q6pGi'></small><noframes id='Q6pGi'>

    • <bdo id='Q6pGi'></bdo><ul id='Q6pGi'></ul>

      尝试使用 PHP 中的 API 在 Dynamics CRM 中创建潜在客

      时间:2023-05-22
        <tbody id='wtGXU'></tbody>
          <bdo id='wtGXU'></bdo><ul id='wtGXU'></ul>

          <small id='wtGXU'></small><noframes id='wtGXU'>

            <tfoot id='wtGXU'></tfoot>

            <legend id='wtGXU'><style id='wtGXU'><dir id='wtGXU'><q id='wtGXU'></q></dir></style></legend>
            <i id='wtGXU'><tr id='wtGXU'><dt id='wtGXU'><q id='wtGXU'><span id='wtGXU'><b id='wtGXU'><form id='wtGXU'><ins id='wtGXU'></ins><ul id='wtGXU'></ul><sub id='wtGXU'></sub></form><legend id='wtGXU'></legend><bdo id='wtGXU'><pre id='wtGXU'><center id='wtGXU'></center></pre></bdo></b><th id='wtGXU'></th></span></q></dt></tr></i><div id='wtGXU'><tfoot id='wtGXU'></tfoot><dl id='wtGXU'><fieldset id='wtGXU'></fieldset></dl></div>
              1. 本文介绍了尝试使用 PHP 中的 API 在 Dynamics CRM 中创建潜在客户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                我正在尝试使用 PHP 中的 API 在 Dynamics CRM 中创建潜在客户,但出现 400 html 错误.我的 Dynamics CRM 使用 Active Directory 身份验证.我可以使用 API 成功获取潜在客户列表,但无法创建.这是我的代码:

                I am trying to create lead in Dynamics CRM using API in PHP but getting 400 html error. My Dynamics CRM uses Active Directory authentication. I can successfully get the lead list using API but unable to create one. Here is my code:

                $xml = '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
                <s:Body>
                    <Create xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
                      <entity xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts">
                        <a:Attributes xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
                          <a:KeyValuePairOfstringanyType>
                            <b:key>Firstname/b:key>
                            <b:value i:type="c:string" xmlns:c="http://www.w3.org/2001/XMLSchema">TestTopic</b:value>
                          </a:KeyValuePairOfstringanyType>
                          <a:KeyValuePairOfstringanyType>
                            <b:key>Lastname</b:key>
                            <b:value i:type="c:string" xmlns:c="http://www.w3.org/2001/XMLSchema">testName</b:value>
                          </a:KeyValuePairOfstringanyType>
                        </a:Attributes>
                        <a:EntityState i:nil="true" />
                        <a:FormattedValues xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />
                        <a:Id>00000000-0000-0000-0000-000000000000</a:Id>
                        <a:LogicalName>lead</a:LogicalName>
                        <a:RelatedEntities xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />
                      </entity>
                    </Create>
                  </s:Body></s:Envelope>';
                
                $headers = array ( 
                                    "POST " . "/Organization.svc" . " HTTP/1.1",
                                    "Host: " . $host,
                                    "Connection: Keep-Alive",
                                    "Content-type: application/SOAP+xml; charset=UTF-8"
                                    //,"Content-length: " . strlen ( $xml )
                            );
                
                $ch = curl_init ();
                            curl_setopt ( $ch, CURLOPT_URL, $crm_url  . "/XRMServices/2011/Organization.svc" );
                        //curl_setopt($ch, CURLOPT_HTTPHEADER, array('"POST " . "/Organization.svc" . " HTTP/1.1","Host: " . $host,"Connection: Keep-Alive","Content-type: application/json; charset=UTF-8"'));
                            curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
                            curl_setopt ( $ch, CURLOPT_CUSTOMREQUEST, "POST");
                            curl_setopt ( $ch, CURLOPT_TIMEOUT, 60 );
                            curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, false );
                            curl_setopt ( $ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1 );
                            curl_setopt ( $ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
                            curl_setopt ( $ch, CURLOPT_USERPWD, "$username:$password");
                            curl_setopt ( $ch, CURLOPT_HTTPHEADER, $headers );
                            curl_setopt ( $ch, CURLOPT_POST, 1 );
                            curl_setopt ( $ch, CURLOPT_POSTFIELDS, $xml );
                
                            $response = curl_exec($ch);
                            if( $response === false) { echo 'Curl error: ' . curl_error($ch);}
                            $status = curl_getinfo( $ch, CURLINFO_HTTP_CODE );echo "Status: $status ";
                            $response=json_decode($response, true);
                            print_r($response);
                            curl_close($ch);
                

                推荐答案

                此代码适用于使用 Active Directory 身份验证的 Dynamics crm on-premise 2015.

                This code works for Dynamics crm on-premise 2015 which uses Active directory authentication.

                $host = 'orgcrm.org.com:5555'; // org crm url without https://
                $organization = 'OrgName';
                $crm_url = "https://$host/$organization/";    
                
                         $headers = array(
                                              'Method: POST',
                                              'Connection: keep-alive',
                                              'User-Agent: PHP-SOAP-CURL',
                                              'Content-Type: application/json; charset=utf-8',
                                              'Accept: application/json',
                                              'Host: ' . $host);            
                
                    $create = json_encode(array('FirstName' => $firstname, 
                                                'LastName' => $lastname, 
                                                'Telephone1' => $tel, 
                                                'EMailAddress1' => $email), JSON_FORCE_OBJECT);         
                
                            $ch = curl_init();
                                curl_setopt ( $ch, CURLOPT_URL, $crm_url  . "/XRMServices/2011/OrganizationData.svc/LeadSet" );
                                curl_setopt ( $ch, CURLOPT_USERPWD, "$username:$password");
                                curl_setopt ( $ch, CURLOPT_POSTFIELDS, $create); 
                                curl_setopt ( $ch, CURLOPT_HTTPHEADER, $headers);
                                curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true);
                                curl_setopt ( $ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
                                curl_setopt ( $ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
                                //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                
                                $response = curl_exec($ch);
                                if( $response === false) { echo 'Curl error: ' . curl_error($ch);}
                                $status = curl_getinfo( $ch, CURLINFO_HTTP_CODE );echo "Status: $status ";
                
                                $response1 = json_decode($response, true); 
                                foreach ($response1 as $id) {
                                        $guid = $id['LeadId'];                  
                                        echo 'GUID: ' . $guid. ' ';
                                    }           
                                print_r($response1);
                
                                curl_close($ch);
                

                这篇关于尝试使用 PHP 中的 API 在 Dynamics CRM 中创建潜在客户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:“未将对象引用设置为对象的实例"从 PHP 连接 下一篇:更改 php 中的soap前缀

                相关文章

                最新文章

                  • <bdo id='0jiRi'></bdo><ul id='0jiRi'></ul>
                1. <small id='0jiRi'></small><noframes id='0jiRi'>

                  <tfoot id='0jiRi'></tfoot>
                  <i id='0jiRi'><tr id='0jiRi'><dt id='0jiRi'><q id='0jiRi'><span id='0jiRi'><b id='0jiRi'><form id='0jiRi'><ins id='0jiRi'></ins><ul id='0jiRi'></ul><sub id='0jiRi'></sub></form><legend id='0jiRi'></legend><bdo id='0jiRi'><pre id='0jiRi'><center id='0jiRi'></center></pre></bdo></b><th id='0jiRi'></th></span></q></dt></tr></i><div id='0jiRi'><tfoot id='0jiRi'></tfoot><dl id='0jiRi'><fieldset id='0jiRi'></fieldset></dl></div>

                  1. <legend id='0jiRi'><style id='0jiRi'><dir id='0jiRi'><q id='0jiRi'></q></dir></style></legend>