云函数

触发云函数

POST https://cloud.minapp.com/oserve/v1/cloud-function/job/

推荐使用发起一个云函数请求触发云函数。

参数说明

Content-Type: Content-Type: application/json

参数类型必填说明
function_nameString云函数名
dataObject传递给云函数的参数
syncBool是否等待返回函数执行结果,默认为 true。同步与异步云函数有不同的超时时间,同步云函数为 5 秒,而异步云函数为 5 分钟(300 秒)

返回参数说明

在 sync 为 true 的情况下

参数类型描述
codeNumbercode 为 0 时表示成功执行云函数,否则为执行云函数失败
data由云函数返回的数据类型决定函数通过 callback 返回的数据
errorObject返回的错误信息,成功则返回空对象

测试云函数

接口地址

POST https://cloud.minapp.com/oserve/v1.3/cloud-function/:cloud_function_name/debug/

其中 :cloud_function_name 是云函数的名字。

参数说明

Content-Type: Content-Type: application/json

参数类型必填说明
dataObject自定义数据,没有则需要提供一个空对象
subjectString触发类型,若不提供默认为 sdk, 可选值有:sdk, open_api, cloud_function, flex_schema, wechat_pay_success, timer, file_operation
schema_idInteger表 ID,如果 subject 为 FlexSchema 则必填

返回参数

参数类型说明
billing_timeInteger计费时间
codeInteger函数调用正常:0,函数调用出错:1
data由云函数返回的数据类型决定函数通过 callback 返回的数据
errorObject包含三个键,错误信息:message, 错误堆栈:stack, 错误类型:type
execution_timeFloat执行时间,毫秒
job_idString任务 ID
logString日志
mem_usageInteger内存使用量,字节数

代码示例

  1. curl -X POST \
  2. https://cloud.minapp.com/oserve/v1.3/cloud-function/test/debug/ \
  3. -H "Authorization: Bearer cfb5912724dd7ff0b0c17683cc3074bb548bc7f4" \
  4. -H 'Content-Type: application/json' \
  5. -d '{
  6. "data": {}
  7. }'
  1. var request = require("request");
  2. var cloudFunctionName = '';
  3. var options = {
  4. method: 'POST',
  5. url: 'https://cloud.minapp.com/oserve/v1.3/cloud-function/' + cloudFunctionName + '/debug/',
  6. headers:
  7. {
  8. 'Content-Type': 'application/json',
  9. Authorization: 'Bearer 2323d124881bd3d63c9bb7845454f80a676b'
  10. },
  11. body: { data: {} },
  12. json: true
  13. };
  14. request(options, function (error, response, body) {
  15. if (error) throw new Error(error);
  16. console.log(body);
  17. });
  1. <?php
  2. $token = '';
  3. $cloud_function_name = ''; // 云函数的名字
  4. $url = "https://cloud.minapp.com/oserve/v1.3/cloud-function/{$cloud_function_name}/debug/";
  5. $ch = curl_init();
  6. $header = array(
  7. "Authorization: Bearer {$token}",
  8. 'Content-Type: application/json; charset=utf-8'
  9. );
  10. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  11. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  12. curl_setopt($ch, CURLOPT_URL, $url);
  13. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
  14. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  15. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
  16. curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"data\": {}}");
  17. $response = curl_exec($ch);
  18. $err = curl_error($ch);
  19. curl_close($ch);
  20. if ($err) {
  21. echo "CURL Error #:" . $err;
  22. } else {
  23. echo $response;
  24. }

返回示例

正常返回:

  1. {
  2. "billing_time": 100,
  3. "code": 0,
  4. "data": "hello world",
  5. "error": {},
  6. "execution_time": 13.46,
  7. "job_id": "490f08ff9b2e4a6b874581de53950e54",
  8. "log": "2018-09-21T03:46:26.026Z LOG event.data: {}\n2018-09-21T03:46:26.029Z LOG return: hello world\n",
  9. "mem_usage": 78340096
  10. }

异常返回:

  1. {
  2. "billing_time": 100,
  3. "code": 1,
  4. "data": null,
  5. "error": {
  6. "message": "Unexpected identifier",
  7. "stack": ":2\n callback(null, \"hello world\") fot debug\n ^^^\n\nSyntaxError: Unexpected identifier\n at createScript (vm.js:80:10)\n at Object.runInThisContext (vm.js:139:10)\n at Module._compile (module.js:607:28)\n at loadUserFunction (/opt/hydrogen/worker.js:37:11)\n at IncomingMessage.request.on.on (/opt/hydrogen/worker.js:82:18)\n at emitNone (events.js:106:13)\n at IncomingMessage.emit (events.js:208:7)\n at endReadableNT (_stream_readable.js:1055:12)\n at _combinedTickCallback (internal/process/next_tick.js:138:11)\n at process._tickCallback (internal/process/next_tick.js:180:9)",
  8. "type": "SyntaxError"
  9. },
  10. "execution_time": 18.46,
  11. "job_id": "9f9fe6f08be94888b8b56e981a5a041e",
  12. "log": "2018-09-21T07:49:54.792Z LOG event.data: {}\n2018-09-21T07:49:54.799Z ERROR :2\n callback(null, \"hello world\") fot debug\n ^^^\n\nSyntaxError: Unexpected identifier\n at createScript (vm.js:80:10)\n at Object.runInThisContext (vm.js:139:10)\n at Module._compile (module.js:607:28)\n at loadUserFunction (/opt/hydrogen/worker.js:37:11)\n at IncomingMessage.request.on.on (/opt/hydrogen/worker.js:82:18)\n at emitNone (events.js:106:13)\n at IncomingMessage.emit (events.js:208:7)\n at endReadableNT (_stream_readable.js:1055:12)\n at _combinedTickCallback (internal/process/next_tick.js:138:11)\n at process._tickCallback (internal/process/next_tick.js:180:9)\n",
  13. "mem_usage": 78528512
  14. }

状态码说明

200: 成功。

400: 参数校验失败,任务调度失败。

401: 未授权,请检查请求头中的 Authorization 字段是否正确。

获取某云函数的任务记录

接口地址

GET https://cloud.minapp.com/oserve/v1.3/cloud-function/:cloud-function-name/job/

其中 :cloud-function-name 是云函数的名字。

参数说明

参数类型必填说明
sourceString云函数任务来源,可选值:sdk, open_api, cloud_function, flex_schema, wechat_pay_success, timer, file_operation
statusString云函数任务状态,可选值:waiting, executing, fulfilled, schedule_failed, execution_rejected, deadline_exceeded, execution_failed
service_typeString云函数同步类型,可选值:time_sensitive, batch
created_atgteInteger创建时间大于,unix 时间戳
created_atlteInteger创建时间小于,unix 时间戳

返回参数

参数类型说明
idInteger任务 ID
created_atFloat创建时间
finished_atFloat完成时间
mem_usageInteger内存用量
service_typeString可能的值:time_sensitive, batch
sourceString任务来源
statusString任务状态
user_log_urlString日志地址

代码示例

  1. curl -X GET \
  2. https://cloud.minapp.com/oserve/v1.3/cloud-function/test/job/ \
  3. -H 'Authorization: Bearer 2323d124881bd3d63c9bb78458252454f676b'
  1. var request = require("request");
  2. var cloudFunctionName = '';
  3. var options = {
  4. method: 'GET',
  5. url: 'https://cloud.minapp.com/oserve/v1.3/cloud-function/' + cloudFunctionName + '/job/',
  6. headers:
  7. {
  8. 'Content-Type': 'application/json',
  9. Authorization: 'Bearer 2323d124881bd3d63c9bb78458252454f80ab'
  10. },
  11. json: true
  12. };
  13. request(options, function (error, response, body) {
  14. if (error) throw new Error(error);
  15. console.log(body);
  16. });
  1. <?php
  2. $token = '';
  3. $cloud_function_name = ''; // 云函数的名字
  4. $url = "https://cloud.minapp.com/oserve/v1.3/cloud-function/{$cloud_function_name}/job/";
  5. $ch = curl_init();
  6. $header = array(
  7. "Authorization: Bearer {$token}",
  8. 'Content-Type: application/json; charset=utf-8'
  9. );
  10. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  11. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  12. curl_setopt($ch, CURLOPT_URL, $url);
  13. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
  14. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  15. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
  16. $response = curl_exec($ch);
  17. $err = curl_error($ch);
  18. curl_close($ch);
  19. if ($err) {
  20. echo "CURL Error #:" . $err;
  21. } else {
  22. echo $response;
  23. }

返回示例

  1. {
  2. "meta": {
  3. "limit": 20,
  4. "next": "/oserve/v1.3/cloud-function/test/job/?limit=20&offset=20",
  5. "offset": 0,
  6. "previous": null,
  7. "total_count": 1525
  8. },
  9. "objects": [
  10. {
  11. "created_at": 1537505171.419368,
  12. "finished_at": 1537505171.605735,
  13. "id": 779734,
  14. "mem_usage": 78336000,
  15. "service_type": "batch",
  16. "source": "flex_schema",
  17. "started_at": 1537505171.5807,
  18. "status": "fulfilled",
  19. "user_log_url": "https://hydrogen-faas-logs.s3.cn-north-1.amazonaws.com.cn/ticket_778289.log?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Expires=86400&X-Amz-Security-Token=FQoDYXdzEP3%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaDM50xRDK8JETeulNLiK%2FA08zFCZM8zvsnb6VG81mDV0onfgVwXhAjUi6p3Y250g9GiVeWVs%2FpI6S9d0S6mD9xPjmkWw9ven%2BkRVME2xAbzfgio8%2BUbQkrOgvnFx%2BziHj0DGGvMEZYnoT6ui4QD8y8YQaJd7oWH%2B0hdIUGdE%2BFTSiZzSicuVgdr6WLkxipnuujV2yS9%2ByrXK4A0g1HaUifZVnD3K2Bz1AiHrr9abaFSFoWzyzhGYGcyp7TM4iodW%2FTI5CkPFj2f%2BNvCOSCBWWWOsY%2FUyaAdCFZFqXJoJ6uuXFZ5yl7xd5W28egT5Jgfeq%2FG5j9xp9OVu8sAlnPre8WoSpspHt8R%2BRMDPr6klJE3yxXIxRODlt4nHAA30wcwunO09x8zoK54pgrveIWNlIRYeSSMG%2FGAzYXNq%2FxXjcpQOa3ekyirC%2Bj0n45dBZY4oS8c3au32WjoLjD2gnPAZsvBg1gR2wcUxs3PFi30ochY9VAxXQyXeqcy1Jw0LXQnBLT6Uw9pVV8%2BikrK13EBUiIAow1FEeKJ3xjng7mrPz60pEDYZcymJ0Uj4VkNBXMQwPHBfsfChxsLWYXaQ3EitWD3GhBaim65Tz%2FoZHU6TPRijP5ZHdBQ%3D%3D&X-Amz-Date=20180921T044620Z&X-Amz-Signature=f5d74870d8b52cbb490fae4d81fc486b09da1e026bf9571c172b4d8d29c84a66&X-Amz-Credential=ASIAQUWH6XTCOEBVBVFG%2F20180921%2Fcn-north-1%2Fs3%2Faws4_request&X-Amz-SignedHeaders=host"
  20. },
  21. ...
  22. ]
  23. }

状态码说明

200: 成功。

400: 参数错误。

401: 未授权,请检查请求头中的 Authorization 字段是否正确。

发起一个云函数请求

接口地址

POST https://cloud.minapp.com/oserve/v1.3/cloud-function/:cloud-function-name/job/

其中 :cloud-function-name 是云函数的名字。

请求参数说明

Content-Type: Content-Type: application/json

参数类型必填说明
dataObject传递给云函数的参数,如果没有需要提供一个空对象
syncBool是否等待返回函数执行结果,默认为 true。同步与异步云函数有不同的超时时间,同步云函数为 5 秒,而异步云函数为 5 分钟(300 秒)

返回参数说明

sync 为 true 时:

参数类型说明
codeNumbercode 为 0 时表示成功执行云函数,否则为执行云函数失败
data由云函数返回的数据类型决定函数通过 callback 返回的数据
errorObject返回的错误信息,成功则返回空对象

sync 为 false 时:

参数类型说明
statusString默认为 'ok'

代码示例

  1. curl -X POST \
  2. https://cloud.minapp.com/oserve/v1.3/cloud-function/test/job/ \
  3. -H 'Authorization: Bearer 2323d124881bd3d63c9bb78458252454f676b' \
  4. -H "Content-Type: application/json" \
  5. -d '{
  6. "data": {}
  7. }'
  1. var request = require("request");
  2. var cloudFunctionName = 'come_from_hahah';
  3. var options = {
  4. method: 'POST',
  5. url: 'https://cloud.minapp.com/oserve/v1.3/cloud-function/' + cloudFunctionName + '/job/',
  6. headers:
  7. {
  8. 'Content-Type': 'application/json',
  9. Authorization: 'Bearer 2323d124881bd3d63c9bb78458252454f80a676b'
  10. },
  11. body:
  12. { data: {} },
  13. json: true
  14. };
  15. request(options, function (error, response, body) {
  16. if (error) throw new Error(error);
  17. console.log(body);
  18. });
  1. <?php
  2. $token = '';
  3. $cloud_function_name = ''; // 云函数的名字
  4. $url = "https://cloud.minapp.com/oserve/v1.3/cloud-function/{$cloud_function_name}/job/";
  5. $ch = curl_init();
  6. $header = array(
  7. "Authorization: Bearer {$token}",
  8. 'Content-Type: application/json; charset=utf-8'
  9. );
  10. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  11. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  12. curl_setopt($ch, CURLOPT_URL, $url);
  13. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
  14. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  15. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
  16. curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"data\": {}}");
  17. $response = curl_exec($ch);
  18. $err = curl_error($ch);
  19. curl_close($ch);
  20. if ($err) {
  21. echo "CURL Error #:" . $err;
  22. } else {
  23. echo $response;
  24. }

返回示例

sync 为 true:

  1. {
  2. "code": 1,
  3. "data": null,
  4. "error": {
  5. "message": "Unexpected identifier",
  6. "type": "SyntaxError"
  7. }
  8. }

sync 为 false:

  1. {
  2. "status": "ok"
  3. }

状态码说明

200: 成功。

401: 未授权,请检查请求头中的 Authorization 字段是否正确。

404: 没有找到对应的云函数。

新建云函数

接口地址

POST https://cloud.minapp.com/oserve/v1.3/cloud-function/

请求参数说明

参数类型必填说明
nameString云函数名,不能为空字符串
function_codeString云函数代码,不能为空字符串
remarkString备注

返回参数说明

参数类型说明
audit_statusString可能的值: approved, rejected, waiting
created_byString创建者昵称
function_codeString云函数代码
idInteger云函数 ID
nameString云函数名
plan_circleString套餐类型
remarkString备注
updated_atInteger最近一次更新时间
updated_byString更新者昵称

代码示例

  1. curl -X POST \
  2. https://cloud.minapp.com/oserve/v1.3/cloud-function/ \
  3. -H 'Authorization: Bearer 2323d124881bd3d63c9bb78458252454f676b' \
  4. -H "Content-Type: application/json" \
  5. -d '{
  6. "function_code": "exports.main = function functionName(event, callback) {\n callback(null, \"hello world\")\n}",
  7. "remark": "你好,云函数"
  8. }'
  1. var request = require("request");
  2. var options = {
  3. method: 'POST',
  4. url: 'https://cloud.minapp.com/oserve/v1.3/cloud-function/',
  5. headers:
  6. {
  7. 'Content-Type': 'application/json',
  8. Authorization: 'Bearer 2323d124881bd3d63c9bb78458252454f80a676b'
  9. },
  10. body:
  11. {
  12. function_code: 'exports.main = function functionName(event, callback) {\n callback(null, "hello world")\n}',
  13. remark: '你好,云函数'
  14. },
  15. json: true
  16. };
  17. request(options, function (error, response, body) {
  18. if (error) throw new Error(error);
  19. console.log(body);
  20. });
  1. <?php
  2. $token = '';
  3. $url = "https://cloud.minapp.com/oserve/v1.3/cloud-function/";
  4. $ch = curl_init();
  5. $header = array(
  6. "Authorization: Bearer {$token}",
  7. 'Content-Type: application/json; charset=utf-8'
  8. );
  9. $payload = json_encode(
  10. array(
  11. 'function_code'=> "exports.main = function functionName(event, callback) {\n callback(null, \"hello world\")\n}",
  12. 'remark'=> '你好,云函数'
  13. )
  14. );
  15. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  16. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  17. curl_setopt($ch, CURLOPT_URL, $url);
  18. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
  19. curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
  20. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  21. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
  22. $response = curl_exec($ch);
  23. $err = curl_error($ch);
  24. curl_close($ch);
  25. if ($err) {
  26. echo "CURL Error #:" . $err;
  27. } else {
  28. echo $response;
  29. }

返回示例

  1. {
  2. "audit_status": "approved",
  3. "created_at": 1537704381,
  4. "created_by": "",
  5. "function_code": "exports.main = function functionName(event, callback) {\n callback(null, \"hello world\")\n}",
  6. "id": 1105,
  7. "name": "come_from_open_api",
  8. "plan_circle": "P_FREE",
  9. "remark": "你好,云函数",
  10. "updated_at": 1537704381,
  11. "updated_by": ""
  12. }

状态码说明

201: 创建成功。

400: 参数不合法:云函数名或代码为字段为空。

401: 未授权,请检查请求头中的 Authorization 字段是否正确。

获取当前小程序的所有云函数

接口地址

GET https://cloud.minapp.com/oserve/v1.3/cloud-function/

返回参数说明

参数类型说明
audit_statusString可能的值: approved, rejected, waiting
created_byString创建者昵称
function_codeString云函数代码
idInteger云函数 ID
nameString云函数名
plan_circleString套餐类型
remarkString备注
updated_atInteger最近一次更新时间
updated_byString更新者昵称

代码示例

  1. curl -X GET \
  2. https://cloud.minapp.com/oserve/v1.3/cloud-function/ \
  3. -H 'Authorization: Bearer 2323d124881bd3d63c9bb78458252454f676b'
  1. var request = require("request");
  2. var options = {
  3. method: 'GET',
  4. url: 'https://cloud.minapp.com/oserve/v1.3/cloud-function/',
  5. headers:
  6. {
  7. Authorization: 'Bearer 2323d124881bd3d6bb78458252454f80a676b'
  8. },
  9. json: true
  10. };
  11. request(options, function (error, response, body) {
  12. if (error) throw new Error(error);
  13. console.log(body);
  14. });
  1. <?php
  2. $token = '';
  3. $url = "https://cloud.minapp.com/oserve/v1.3/cloud-function/";
  4. $ch = curl_init();
  5. $header = array(
  6. "Authorization: Bearer {$token}",
  7. 'Content-Type: application/json; charset=utf-8'
  8. );
  9. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  10. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  11. curl_setopt($ch, CURLOPT_URL, $url);
  12. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
  13. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  14. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
  15. $response = curl_exec($ch);
  16. $err = curl_error($ch);
  17. curl_close($ch);
  18. if ($err) {
  19. echo "cURL Error #:" . $err;
  20. } else {
  21. echo $response;
  22. }

返回示例

{
    "meta": {
        "limit": 20,
        "next": null,
        "offset": 0,
        "previous": null,
        "total_count": 2
    },
    "objects": [
        {
            "audit_status": "approved",
            "created_at": 1537924886,
            "created_by": "somebody",
            "function_code": "exports.main = function functionName(event, callback) {\n  callback(null, \"hello world\")\n}",
            "id": 1121,
            "name": "come_from_open_API_v1.3",
            "plan_circle": "P_FREE",
            "remark": "你好,云函数",
            "updated_at": 1537924886,
            "updated_by": ""
        },
        {
            "audit_status": "approved",
            "created_at": 1537704269,
            "created_by": "somebody",
            "function_code": "exports.main = function functionName(event, callback) {\n  callback(null, \"hello world\")\n}",
            "id": 1102,
            "name": "测试",
            "plan_circle": "P_FREE",
            "remark": "你好,云函数",
            "updated_at": 1537704426,
            "updated_by": "somebody"
        },
    ]
}

状态码说明

200: 成功。

401: 未授权,请检查请求头中的 Authorization 字段是否正确。

401: 参数不合法:云函数名或代码为字段为空

获取云函数详细信息

接口地址

GET https://cloud.minapp.com/oserve/v1.3/cloud-function/:cloud-function-name/

其中 :cloud-function-name 为云函数的名字。

返回参数说明

参数类型说明
audit_statusString可能的值: approved, rejected, waiting
created_byString创建者昵称
function_codeString云函数代码
idInteger云函数 ID
nameString云函数名
plan_circleString套餐类型
remarkString备注
updated_atInteger最近一次更新时间
updated_byString更新者昵称

代码示例

curl -X GET \
  https://cloud.minapp.com/oserve/v1.3/cloud-function/test/ \
  -H 'Authorization: Bearer 2323d124881bd3d63c9bb78458252454f676b'
var request = require("request");

var cloudFunctionName = '';
var options = {
  method: 'GET',
  url: 'https://cloud.minapp.com/oserve/v1.3/cloud-function/' + cloudFunctionName + '/',
  headers:
  {
    Authorization: 'Bearer 2323d124881bd3d63c9bb78458252454f80a676b'
  },
  json: true
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);
  console.log(body);
});
<?php
$token = '';
$cloud_function_name = '';
$url = "https://cloud.minapp.com/oserve/v1.3/cloud-function/{$cloud_function_name}/";

$ch = curl_init();
$header = array(
  "Authorization: Bearer {$token}",
  'Content-Type: application/json; charset=utf-8'
);

curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);

$response = curl_exec($ch);
$err = curl_error($ch);

curl_close($ch);

if ($err) {
  echo "CURL Error #:" . $err;
} else {
  echo $response;
}

返回示例

{
    "audit_status": "approved",
    "created_at": 1535903214,
    "created_by": "somebody",
    "function_code": "exports.main = function functionName(event, callback) {\n  callback(null, \"hello world\")  fot debug\n}",
    "id": 847,
    "name": "test",
    "plan_circle": "P_FREE",
    "remark": "",
    "updated_at": 1537516164,
    "updated_by": "somebody"
}

状态码说明

200: 成功。

401: 未授权,请检查请求头中的 Authorization 字段是否正确。

404: 云函数不存在。

修改云函数

接口地址

PATCH https://cloud.minapp.com/oserve/v1.3/cloud-function/:cloud-function-name/

其中 :cloud-function-name 为云函数名字。

请求参数说明

参数类型必填说明
nameString云函数名,不能为空字符串
function_codeString云函数代码,不能为空字符串
plan_circleString套餐类型,可能的值:P_FREE(128 MB 内存), P_PERSONAL(256 MB 内存)
remarkString备注

返回参数说明

参数类型说明
audit_statusString可能的值: approved, rejected, waiting
created_byString创建者昵称
function_codeString云函数代码
idInteger云函数 ID
nameString云函数名
plan_circleString套餐类型,可能的值:P_FREE(128 MB 内存), P_PERSONAL(256 MB 内存)
remarkString备注
updated_atInteger最近一次更新时间
updated_byString更新者昵称

代码示例

curl -X PATCH \
  https://cloud.minapp.com/oserve/v1.3/cloud-function/test/ \
  -H 'Authorization: Bearer 2323d124881bd3d63c9bb78458252454f676b' \
  -H "Content-Type: application/json" \
  -d '{
  "function_code": "exports.main = function functionName(event, callback) {\n  callback(null, \"hello world\")\n}",
  "remark": "你好,云函数"
}'
var request = require("request");

var cloudFunctionName = '';
var options = {
  method: 'PATCH',
  url: 'https://cloud.minapp.com/oserve/v1.3/cloud-function/' + cloudFunctionName + '/',
  headers:
  {
    'Content-Type': 'application/json',
    Authorization: 'Bearer 2323d124881bd3d63c9bb784582554f80a676b'
  },
  body:
  {
    remark: '你好,云函数',
  },
  json: true
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);
  console.log(body);
});
<?php
$token = '';
$cloud_function_name = '';
$url = "https://cloud.minapp.com/oserve/v1.3/cloud-function/{$cloud_function_name}/";

$ch = curl_init();
$header = array(
  "Authorization: Bearer {$token}",
  'Content-Type: application/json; charset=utf-8'
);

$payload = json_encode(
  array(
    'function_code'=> "exports.main = function functionName(event, callback) {\n  callback(null, \"hello world\")\n}",
    'remark'=> '你好,云函数'
  )
);

curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);

$response = curl_exec($ch);
$err = curl_error($ch);

curl_close($ch);

if ($err) {
  echo "CURL Error #:" . $err;
} else {
  echo $response;
}

返回示例

{
    "audit_status": "approved",
    "created_at": 1535903214,
    "created_by": "somebody",
    "function_code": "exports.main = function functionName(event, callback) {\n  callback(null, \"hello world\")\n}",
    "id": 847,
    "name": "modify_from_open_api",
    "plan_circle": "P_FREE",
    "remark": "",
    "updated_at": 1537710962,
    "updated_by": "somebody"
}

状态码说明

202: 修改成功。

400: 参数不合法:云函数名或代码为空。

401: 未授权,请检查请求头中的 Authorization 字段是否正确。

401: 参数不合法:云函数名或代码为空

删除一个云函数

接口地址

DELETE https://cloud.minapp.com/oserve/v1.3/cloud-function/:cloud-function-name/

其中 :cloud-function-name 是云函数的名字。

代码示例

curl -X DELETE \
  https://cloud.minapp.com/oserve/v1.3/cloud-function/test/ \
  -H 'Authorization: Bearer 2323d124881bd3d63c9bb78458252454f676b'
var request = require("request");

var cloudFunctionName = '';
var options = {
  method: 'DELETE',
  url: 'https://cloud.minapp.com/oserve/v1.3/cloud-function/' + cloudFunctionName + '/',
  headers:
  {
    Authorization: 'Bearer 2323d124881bd3d63c9bb784582524540a676b'
  },
  json: true
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);
  console.log(response.statusCode);
});
<?php
$token = '';
$cloud_function_name = ''; // 云函数的名字
$url = "https://cloud.minapp.com/oserve/v1.3/cloud-function/{$cloud_function_name}/";

$ch = curl_init();
$header = array(
  "Authorization: Bearer {$token}",
  'Content-Type: application/json; charset=utf-8'
);

curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);

$response = curl_exec($ch);

$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$err = curl_error($ch);

curl_close($ch);

if ($err) {
  echo "CURL Error #:" . $err;
} else {
  echo $httpCode;
}

返回示例

返回体为空。

状态码说明

204: 删除成功。

401: 未授权,请检查请求头中的 Authorization 字段是否正确。

404: 没有找到对应的云函数。