Using Advanced REST Client to test REST Request.

来源:互联网 发布:深圳软件产业园 编辑:程序博客网 时间:2024/05/21 10:01

APP - auth2.0验证使用

Connected App设置后可以获得Consumer KeyConsumer Secret.

Consumer Key: 3MVG9ZL0ppGP5UrBPEyfde5VESRlM30EznnBnO3FlL49ozmrF97ee9NOgIUtbi5Nm8uPttY2Vsczpave8Jsxl

Consumer Secret: 4710087710557659561

How to connect Advanced REST Client?

Connected Link:

https://login.salesforce.com/services/oauth2/token?grant_type=password&client_id=3MVG9ZL0ppGP5UrBPEyfde5VESRlM30EznnBnO3FlL49ozmrF97ee9NOgIUtbi5Nm8uPttY2Vsczpave8Jsxl&client_secret=4710087710557659561&username=itsme@delloitte.com&password=admin123yF0cOjR6qMVFVN4IRJr4E6Hs


Do POST Request to get access_token and token_type:

{

"access_token": "00D28000000bNDI!AQMAQAziOABzixdUqHrVXsPt_SXeM455m4WsoqXbh4UaE1gU7yeZI8Cvui6Ycy1GRqE2nhXeDXC9vFUq.ipL2X3kDNXHu_tN1”,

"instance_url": "https://componentstest-dev-ed.my.salesforce.com",

"id": "https://login.salesforce.com/id/00D28000000bNDIEA2/00528000005ENAIAA4",

"token_type": "Bearer",

"issued_at": "1504051357502",

"signature": "FdYNUzrkxeJApcivQAX0QIB5EmaNQjcKs7xIe5byYfk="

}


1.使用GET方法查找数据:GET - R

https://componentstest-dev-ed.my.salesforce.com/services/data/v40.0/query?q=select id, name from account

返回码:200,请求成功response the objects information


2.使用POST方法创建记录:POST - C

https://componentstest-dev-ed.my.salesforce.com/services/data/v40.0/sobjects/account

返回码:201,创建成功response the record id


3.使用PATCH方法更新记录:PATCH - U

https://componentstest-dev-ed.my.salesforce.com/services/data/v40.0/sobjects/account/0012800001VJIzuAAH

返回码:204,更新成功,无返回值no response


4.使用DELETE方法删除记录:DELETE - DContent-Type is not required.

https://componentstest-dev-ed.my.salesforce.com/services/data/v40.0/sobjects/account/0012800001VJIzuAAH

返回码:204,删除成功,无返回值no response


Q:: 为啥用同一个connect url post请求返回的access_token不一样?并且昨天使用的access_token今天使用会过期?

A:: access_token有有效时间的,外部系统对sf数据操作时,需要不定期获取access_token,当然sf可以设置过期时间如2h12h等。

参考资料:https://www.slideshare.net/asagarwal/a-60-minutes-step-by-step-diy-guide-to-salesforce-rest-api-for-non-developers?qid=e6011c30-3581-4bcf-916f-30b7844c51da&v=&b=&from_search=1