2016-11-28 14 views
1

自分のウェブサイトにフォームから収集したデータを投稿するAPIがあります。名前が存在するかどうか確認する

$org_payload = array(
     'name' => $_POST['billing_company'], 
     'phone' => $_POST['billing_phone'], 
     'email' => $_POST['billing_email'], 
     'note' =>$_POST['order_comments'], 
     'relation_type' => array(
      'id'=>'relationtype:c1ec3ae77036842d' //provide the relationtypeid, f.e. relationtype:796ce0d318a2f5db515efc18bba82b90 
     ), 
     'visiting_address' => array(
      'country_code'   => 'NL', 
      'line_1'    => $_POST['billing_address_1'], 
      'postal_code'   => $_POST['billing_postcode'], 
      'locality'    => $_POST['billing_city'], 
      'country'    => $_POST['billing_country'] 

     ), // can be extented with other address data 
     'postal_address' => array(
      'country_code'   => 'NL' 
     ) // can be extented with other address data 
); 

次にそれは次のように送られます:

$organization = $SimplicateApi->makeApiCall('POST','/crm/organization',json_encode($org_payload)); 

私は配列項目名がすでにそれが何かをエコー作るために存在する場合にすることを望ん データは、このような配列で収集されます。

すべて新しく入力されたデータは、このURLでJSON形式で保存されます:

/API/V2/CRM /組織

get要求は次のようになります。

$test = $SimplicateApi->makeApiCall('GET','/api/v2/crm/organization?q'); 

ここに擬似コードで欲しいものの例を示します。

答えて

1

使用

if (array_key_exists('name', $org_payload)) { 
    // do something 
    echo 'this name already exists' 
} else { 
    // make API call 
} 

他のオプションarray_key_exists()関数が(設定されている)変数がヌルでない場合もチェックisset()と変数が存在するかどうかをチェックnullでなく、空でないempty()あります。

+0

アレイキー名がmydomain.com/api/v2/crm/organization.json –

+0

内に存在するかどうかを確認したいので、json_decode()を使用してphp配列に入れ、array_key_existsで確認してください – Robert

+0

ありがとう –

関連する問題