整理PostMan的基础用法31

Workspaces

   GET all workspaces: https://api.getpostman.com/workspaces

      /workspaces 端点返回一个可访问的workspaces集合。这个集合包含你自己的工作空间和你能访问的工作空间。

      响应包含了含有每个工作空间的name,id, type集合信息的一个数组。

          " Requires API Key作为X-Api-Key请求头或apikey URL query参数。

      头文件HEADERS

      X-Api-Key: {{postman_api_key}}

      Example Request

       Valid Request

           url --location --request GET "https://api.getpostman.com/workspaces"

              --header "X-Api-Key: {{postman_api_key}}"

      Example Response

       200 - OK

      { "workspaces": [ { "id": 4e6d34c2-cfdb-4b33-8862-12a875bebda3",

                    "name": "my workspaces", "type": "personal" },

        { "id": "f8801e9e03a4-4c7b-b31a-5db5cd771696", "name": "team workspace",

            "type": "team" }

    }

   GET single workspace: https://api.getpostman.com/workspaces

       用uid访问一个你有权限访问的工作空间,包括其中的集合,环境变量,模拟器和监视器。

         "Requires API Key作为X-Api-Key的请求头或apikey URL query参数。

     头文件HEADERS

     X-Api-Key: {{postman_api_key}}

  Example Request

    Workspace not found

      url --location --request GET "https://api.getpostman.com/workspaces/{{workspaces}}"

          --header "X-Api-Key: {{postman_api_key}}"

   Example Response

      404 - not found

    { "error": { "name": "instanceNotFoundError", "message": "Instance not found in the database." } }

   Example Request

     Successful Response

     url -- location --request POST "https://api.getpostman.com/workspaces"

            --header "x-api-key: {{postman_api_key}}"

          --header "Content-Type: application/json"

         --data" { "workspace": { "name": "New workspace", "type": "personal",

              "description": "some description","collections": [ { "id":"e1fc3c38-a0b8-44a3-bd44-d753a96b2e9d", "name": "Straw hats","uid":"8154-e1fc3c38-a0b8-44a3-bd44-d753a96b2e9d" } ],

             "environments": [ { "id": "83a1aaa2-a204-4bd8-9b92-4d486918906b",

             "name":"env", "uid": "8154-83a1aaa2-a204-4bd8-9b92-4d486918906b"

       } ],

         "mocks": [ { "id": "cda672ef-1375-40e9-baee-e20ece8d7b65"  } ],

         "monitors": [ { "id": "1e889bd2-3862-4be0-b2c2-9b1fe9673aec" } ]

    }  } "

 POST create workspace: https://api.getpostman.com/workspaces

   允许你去创建一个工作空间和将之使用uid来用尸体像collections, environments, mocks,monitors 居住。

   成功创建工作空间,响应返回的工作空间name, id.

        "Requires API Key 作为X-Api-Key请求头或apikey URL query参数。

   头文件HEADERS

     x-api-key : {{postman_api_key}}

     Content_Type: application/json

  BODY

      { "workspace": { "name": "new workspace", "type": "personal",

           "description": "some description",

          "collections": [ { "id": "e2fc3c38-a0b8-44a3-bb44-d754a96b2e9d",

              "name": "straw hats", "uid": "8154-e2fc3c38-a0b8-44a3-bb44-d754a96b2e9d" }

              ] } }

   Example Request

      Successful Response

       url --location --request POST "https://api.getpostman.com/workspaces"      

           --header "x-api-key: {{postman_api_key}}"

           --header "Content-type: application/json"

           --data " { "workspace": { "name": "new workspace", "type": "personal",

                 "description": "some description",

                "collections": [ { "id": "e2fc3c38-a0b8-44a3-bb44-d754a96b2e9d",

                         "name":"straw hats", "uid": "8154-e2fc3c38-a0b8-44a3-bb44-d754a96b2e9d"  } ],

               "environments" : [ { "id": "83a1aaa2-a240-4bd8-9b92-4b4896918906b",

                        "name":"env", "uid":"8154-83a1aaa2-a240-4bd8-9b92-4b4896918906b"

             } ],

       "mocks": [ { "id": "cda672ef-1375-40e9-baee--e20ece8d7b62" } ],

       "monitors": [ { "id": "1e889bd2-3864-4be0-b2c2-9b1fe963aec "  } ]

   } } "

 

   请求体

    { "workspace": { "name": "New workspace", "type": "personal",

            "description": "some description", "collections": { "id": "e2fc3c38-a368-44a3-bd11-d753a96b8e9d",  "name": "straw hats", "uid": "8154-e2fc3c38-a368-44a3-bd11-d753a96b8e9d" } } }

   PUT Update workspace: https://api.getpostman.com/workspaces

       允许更新一个工作空间和更新它跟使用uid的尸体如collections, environments, mocks和monitors之间的关联性。

       成功更新完工作空间,响应会返回工作空间的name, id.

         "Requires API Key作为X-Api-Key请求头或apikey URL query参数。

   注意: 端点期望你发送有关关联的尸体的工作空间的期望状态,因此要小心去试着更新这些尸体。

     例如,如果你的工作空间有集合A和B,而在这个更新的调用中,发送在集合数组中的D的uid,然后A和B将从工作空间中移除出去然后D被添加过来。

  头文件HEADERS

  x-api-key: {{postman_api_key}}

  Content-Type: application/json"

 BODY

  { “workspace": { "name": "new workspace updates", "description": "some description",

     "collections": [ { "id": "e1fc3c39-a0b9-44a3-bd44-d832a02b2e0d",

        "name": "straw hats", "uid": "8173-e1fc3c39-a0b9-44a3-bd44-d832a02b2e0d" } ] }

 Example Request

    Not enough permissions

       url --location --request PUT "https://api.getpostman.com/workspaces/{{workspaces}}"

             --header "x-api-key: {{postman_api_key}}"

            --header "Content-Type: application/json"

           --data " { "workspace": { "name": "new workspace updated",

              "type": "personal", "description": "some description",

              "collections": [ { "id": "e1fc3c39-a0b9-44a3-bd44-d832a02b2e0d",

                      "name": "straw hats", "uid": "8154-e1fc3c39-a0b9-44a3-bd44-d832a02b2e0d"   } ],

         "environments": [ { "id": "83a1aaa8-a042-4bd8-9b92-4d486918906b",

             "name": "env", "uid": "8154-83a1aaa8-a042-4bd8-9b92-4d486918906b" } ],

       "mocks": [ { "id": "cda612ef-1375-4089-baee-820ece8d7b62" } ],

       "monitors": [ { "id": "2e999bd2-3562-4b8e-b2c2-9b1fe9673aec" } ]

    }  } "

  Example Response

    403 - Forbidden

    { "error": { "name": "forbiddenError", "message": "You do not have any access to update this workspace." } }

   DEL delete workspace: https://api.getpostman.com/workspaces

     允许你删除一个已存在的工作空间。

     完全删除掉工作空间后,响应返回它的id.

        "Requires API Key作为X-Api-Key请求头或apikey URL query参数。

User

    GET API Key Owner: https://api.getpostman.com/me

       /me端点是去获取正在使用中的关于API Key相关的信息。

       "Requires API Key作为X-Api-Key请求头或apikey URL query参数。

    头文件HEADERS

     X-Api-Key: {{postman_api_key}}

  Example Request

     Valid Response

        url --location --request GET "https://api.getpostman.com/me"

             --header "X-Api-Key: {{postman_api_key}}"

   Example Response

      200 - OK

      { "user" : { "id" : "123212" } }

Import

    POST Import external API specification:https://api.getpostman.com/{{importType}}

     允许引入外部API说明规格书到Postman去。

     目前,这个端点只支持OpenAPI说明规格书,这样importType就会是openapi.

     成功引入后,响应会是一个由每个包含id,name,uid的被创建的尸体的一个数组。

     支持的type有: string, json, file

     input 参数应该基于type来定义。

        要引入一个文件,请求体必须是有设置到file到带有type参数的form-data.

     注意:参考不同场景下的例子。

         "Requires API Key作为X-Api-Key请求头。"

  头文件HEADERS

   x-api-key: {{postman_api_key}}

   Content_Type: application/json

   BODY

    { "type": "json", "input": { "openapi": "3.0.0", "info": { "version": "1.0.0",

                "title": "swagger petstore", "license": {"name": "MIT" } } } }

    Example Request

      Error: Invalid Params

    url --location --request POST "https://api.getpostman.com/import/openapi"

           --header "x-api-key: {{postman_api_key}}"

           --header "Content-Type: application/json"

         --data " { "type": "invalid_type", "input": { "openapi": "3.0.0",

           "info": { "version": "1.0.0", "title": "swagger petstore",

           "license": { "name": "MIT" } },

         "servers": [ { "url": "http://petstore.swagger.io/v1"  } ],

         "paths": { "pets": { "get":  { "summary": "List all pets",

              "operationId": "listPets" , "parameters": [ { "name": "limit",

               "in": "query", "description": "limit", "required": false,

               "schema": { "type": "integer", "format": "int32" } } ],

         "responses": { "default": { "description": "unexpected error",

            "content": { "schema": { "$ref": "#/componets/schemas/Error" } } } }

      } } } } ,

     "components": { "schemas": { "Error": { "required": [ "code". "message" ],

    "properties": { "code": { "type": "integer"; "format": "int32" },

    "message" : { "type": "string" } }  } } } } }"

 

      Example Response

       400 - Bad Request

       { "error": { "name": "invalidParamsError", "message": "The request body has invaliid values for the type parameter", "details": { "param": "type" } } }

            

    POST Import exported data: https://api.getpostman.com/import/exported

        端点允许引入外部的postman数据。

        成功的引入后,响应会是包含创建的尸体的id,name,uid的每个元素的一个数组。

   注意:"Requires API Key作为X-Api-Key请求头。

    头文件HEADERS

    x-api-key: {{postman_api_key}}

   Content-Type: application/json

    BODY

    type: 文件

    input: 包含有进口的集合或环境变量

Example Request

   Success: Import the exported file

    url --location --request POST "https://api.getpostman.com/import/exported"

        --header "x-api-key: {{postman_api_key}}"

       --form "type=file"

       --form "input=@"

 Example Response

    200 - OK

   { "collections": [ { "id": "c74f2162-0d59-48f4-b04y-fdec4aba4db2",

        "name": "good", "uid": "2281-c74f2162-0d59-48f4-b04y-fdec4aba4db2" } ,

  { "id": "48b08194-4e22-4851-88d1-dqww0ec2ee6a0",

    "name": "demo",

    "uid": "2281-48b08194-4e22-4851-88d1-dqww0ec2ee6a0" } ] }

这最后一篇整理,花了2小时13分,下午刚做好massage,肩颈还是很酸,原来只是左边酸的,现在右边也酸了。疏通的结果让人大跌眼镜啊。

是人是鬼,拉出来溜溜。 是人是熊,靠上去看看。 是龙是虫,用嘴巴讲讲。 是好是赖,用心去窥探。
原文地址:https://www.cnblogs.com/fangyuc/p/10513951.html