Sugarcrm支持产品指南糖开发人员糖开发人员指南10.0食谱网页服务休息API.PHP. 如何收藏一个记录

如何收藏一个记录

概述

A PHP example demonstrating how to favorite a record using the v11 <module>/:record/favorite REST PUT API endpoint.

有利于记录

验证

首先,您需要对Sugar API进行身份验证。一个例子如下所示:

<?php

$instance_url = "http://{site_url}/rest/v11";
$username = "admin";
$password = "password";

//Login - POST /oauth2/token
$auth_url = $instance_url . "/oauth2/token";

$oauth2_token_arguments = array(
    "grant_type" => "password",
    //client id - default is sugar. 
    //It is recommended to create your own in Admin > OAuth Keys
    "client_id" => "sugar", 
    "client_secret" => "",
    "username" => $username,
    "password" => $password,
    //platform type - default is base.
    //It is recommend to change the platform to a custom name such as "custom_api" to avoid authentication conflicts.
    "platform" => "custom_api" 
);

$auth_request = curl_init($auth_url);
curl_setopt($auth_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($auth_request, CURLOPT_HEADER, false);
curl_setopt($auth_request, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($auth_request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($auth_request, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($auth_request, CURLOPT_HTTPHEADER, array(
    "Content-Type: application/json"
));

//convert arguments to json
$json_arguments = json_encode($oauth2_token_arguments);
curl_setopt($auth_request, CURLOPT_POSTFIELDS, $json_arguments);

//execute request
$oauth2_token_response = curl_exec($auth_request);

//decode oauth2 response to get token
$oauth2_token_response_obj = json_decode($oauth2_token_response);
$oauth_token = $oauth2_token_response_obj->access_token;

有关验证的更多信息可以在其中找到 如何进行身份验证和注销 示例和 / oauth2 / logout 端点文档。

有利于记录

Next, we can favorite a specific record using the /<module>/:record/favorite endpoint.

//Favorite record - PUT //:record/favorite

$favorite_url = $instance_url . "/Accounts/ae8b1783-404a-fcb8-1e1e-56f1cc52cd1a/favorite";

$favorite_request = curl_init($favorite_url);

curl_setopt($favorite_request, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($favorite_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($favorite_request, CURLOPT_HEADER, false);
curl_setopt($favorite_request, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($favorite_request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($favorite_request, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($favorite_request, CURLOPT_HTTPHEADER, array(
    "Content-Type: application/json",
    "oauth-token: {$oauth_token}"
));

//execute request
$favorite_response = curl_exec($favorite_request);

有关Favorite API的更多信息可以在其中找到 /<module>/:记录/最喜欢的放置 documentation.

请求有效载荷

发送到服务器的数据如下所示:

This endpoint does not accept any request arguments.

回复

从服务器接收的数据如下所示:

{
    "id": "ae8b1783-404a-fcb8-1e1e-56f1cc52cd1a",
    "name": "Union Bank",
    "date_entered": "2016-03-22T17:49:50-05:00",
    "date_modified": "2016-03-30T17:44:20-05:00",
    "modified_user_id": "1",
    "modified_by_name": "Administrator",
    "modified_user_link": {
        "full_name": "Administrator",
        "id": "1",
        "_acl": {
            "fields": [],
            "delete": "no",
            "_hash": "8e11bf9be8f04daddee9d08d44ea891e"
        }
    },
    "created_by": "1",
    "created_by_name": "Administrator",
    "created_by_link": {
        "full_name": "Administrator",
        "id": "1",
        "_acl": {
            "fields": [],
            "delete": "no",
            "_hash": "8e11bf9be8f04daddee9d08d44ea891e"
        }
    },
    "description": "",
    "deleted": false,
    "facebook": "",
    "twitter": "",
    "googleplus": "",
    "account_type": "Customer",
    "industry": "Banking",
    "annual_revenue": "",
    "phone_fax": "",
    "billing_address_street": "67321 West Siam St.",
    "billing_address_street_2": "",
    "billing_address_street_3": "",
    "billing_address_street_4": "",
    "billing_address_city": "Ohio",
    "billing_address_state": "CA",
    "billing_address_postalcode": "25159",
    "billing_address_country": "USA",
    "rating": "",
    "phone_office": "(065) 489-6104",
    "phone_alternate": "",
    "website": "www.qahr.edu",
    "ownership": "",
    "employees": "",
    "ticker_symbol": "",
    "shipping_address_street": "67321 West Siam St.",
    "shipping_address_street_2": "",
    "shipping_address_street_3": "",
    "shipping_address_street_4": "",
    "shipping_address_city": "Ohio",
    "shipping_address_state": "CA",
    "shipping_address_postalcode": "25159",
    "shipping_address_country": "USA",
    "parent_id": "",
    "sic_code": "",
    "duns_num": "",
    "parent_name": "",
    "member_of": {
        "name": "",
        "id": "",
        "_acl": {
            "fields": [],
            "_hash": "654d337e0e912edaa00dbb0fb3dc3c17"
        }
    },
    "campaign_id": "",
    "campaign_name": "",
    "campaign_accounts": {
        "name": "",
        "id": "",
        "_acl": {
            "fields": [],
            "_hash": "654d337e0e912edaa00dbb0fb3dc3c17"
        }
    },
    "following": true,
    "my_favorite": true,
    "tag": [],
    "assigned_user_id": "seed_sarah_id",
    "assigned_user_name": "Sarah Smith",
    "assigned_user_link": {
        "full_name": "Sarah Smith",
        "id": "seed_sarah_id",
        "_acl": {
            "fields": [],
            "_hash": "654d337e0e912edaa00dbb0fb3dc3c17"
        }
    },
    "team_count": "",
    "team_count_link": {
        "team_count": "",
        "id": "West",
        "_acl": {
            "fields": [],
            "_hash": "654d337e0e912edaa00dbb0fb3dc3c17"
        }
    },
    "team_name": [{
        "id": "East",
        "name": "East",
        "name_2": "",
        "primary": false
    }, {
        "id": 1,
        "name": "Global",
        "name_2": "",
        "primary": false
    }, {
        "id": "West",
        "name": "West",
        "name_2": "",
        "primary": true
    }],
    "email": [{
        "email_address": "hr.support.kid@example.info",
        "invalid_email": false,
        "opt_out": false,
        "primary_address": true,
        "reply_to_address": false
    }, {
        "email_address": "info.support.the@example.com",
        "invalid_email": false,
        "opt_out": false,
        "primary_address": false,
        "reply_to_address": false
    }],
    "email1": "hr.support.kid@example.info",
    "email2": "info.support.the@example.com",
    "invalid_email": false,
    "email_opt_out": false,
    "email_addresses_non_primary": "",
    "_acl": {
        "fields": {}
    },
    "_module": "Accounts"
}

下载

您可以下载完整的API示例 这里.

最后修改:2020-03-16 17:09:01