bjsmasth/php-salesforce-rest-api

v0.2 2017-05-29 17:39 UTC

This package is auto-updated.

Last update: 2024-08-31 00:27:50 UTC


README

Bijesh Shrestha bjsmasth bjsmasth@gmail.com bjsmasth php rest api

安装

通过 Composer

composer require bjsmasth/php-salesforce-rest-api

入门指南

设置连接应用程序

  1. 登录到您的 Salesforce 组织
  2. 点击右上角的“设置”菜单
  3. 在“构建”下点击 创建 > 应用程序
  4. 滚动到页面底部并点击“连接应用程序”下的“新建”
  5. 为远程应用程序输入以下详细信息
    • 连接应用程序名称
    • API 名称
    • 联系邮箱
    • 在 API 下拉菜单中启用 OAuth 设置
    • 回调 URL
    • 选择访问范围(如果您需要刷新令牌,请在此处指定)
  6. 点击保存

保存后,您将获得消费者密钥和消费者密钥。更新您的配置文件,为 consumerKeyconsumerSecret 设置值

设置

身份验证

    $options = [
        'grant_type' => 'password',
        'client_id' => 'CONSUMERKEY',
        'client_secret' => 'CONSUMERSECRET',
        'username' => 'SALESFORCE_USERNAME',
        'password' => 'SALESFORCE_PASSWORD AND SECURITY_TOKEN'
    ];
    
    $salesforce = new bjsmasth\Salesforce\Authentication\PasswordAuthentication($options);
    $salesforce->authenticate();
    
    $access_token = $salesforce->getAccessToken();
    $instance_url = $salesforce->getInstanceUrl();
    
    Change Endpoint
    
    $salesforce = new bjsmasth\Salesforce\Authentication\PasswordAuthentication($options);
    $salesforce->setEndpoint('https://test.salesforce.com/');
    $salesforce->authenticate();
 
    $access_token = $salesforce->getAccessToken();
    $instance_url = $salesforce->getInstanceUrl();

查询

    $query = 'SELECT Id,Name FROM ACCOUNT LIMIT 100';
    
    $crud = new \bjsmasth\Salesforce\CRUD();
    $result = $crud->query($query);

创建

    
    $data = [
       'Name' => 'some name',
    ];
    
    $crud->create('Account', $data);  #returns id

更新

    $new_data = [
       'Name' => 'another name',
    ];
    
    $crud->update('Account', $id, $new_data); #returns status_code 204
    

Upsert

    $new_data = [
       'Name' => 'another name',
    ];
    
    $crud->upsert('Account', 'API Name/ Field Name', 'value', $new_data); #returns status_code 204 or 201
    

删除

    $crud->delete('Account', $id);