atlet / php-salesforce-rest-api
v0.4
2023-05-22 13:07 UTC
Requires
- php: >=5.5
- guzzlehttp/guzzle: ^7.5
This package is not auto-updated.
Last update: 2024-09-23 19:13:13 UTC
README
Bijesh Shrestha bjsmasth bjsmasth@gmail.com bjsmasth php rest api
安装
通过Composer
composer require bjsmasth/php-salesforce-rest-api
入门指南
设置连接应用
- 登录到您的Salesforce组织
- 点击右上角的设置
- 在构建部分点击
创建 > 应用 - 滚动到页面底部并点击连接应用下的
新建 - 为远程应用输入以下详细信息
- 连接应用名称
- API名称
- 联系邮箱
- 在API下拉菜单下启用OAuth设置
- 回调URL
- 选择访问范围(如果您需要刷新令牌,请在此处指定)
- 点击保存
保存后,您将获得消费者密钥和消费者密钥。更新您的配置文件,添加consumerKey和consumerSecret的值
设置
身份验证
$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(); $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);