{"id":20456070,"url":"https://github.com/requestly/api-usage-examples","last_synced_at":"2026-04-20T14:32:02.362Z","repository":{"id":192519310,"uuid":"686854568","full_name":"requestly/api-usage-examples","owner":"requestly","description":"Examples of how to manage rules in a workspace through APIs. Documentation - https://developers.requestly.io/api/overview/","archived":false,"fork":false,"pushed_at":"2025-02-18T12:59:20.000Z","size":112,"stargazers_count":0,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-07-22T14:03:01.169Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/requestly.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-09-04T04:57:54.000Z","updated_at":"2025-02-18T12:59:20.000Z","dependencies_parsed_at":null,"dependency_job_id":"8af259c1-f296-4376-ab54-38c2435fd5f0","html_url":"https://github.com/requestly/api-usage-examples","commit_stats":null,"previous_names":["requestly/api-usage-examples"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/requestly/api-usage-examples","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/requestly%2Fapi-usage-examples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/requestly%2Fapi-usage-examples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/requestly%2Fapi-usage-examples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/requestly%2Fapi-usage-examples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/requestly","download_url":"https://codeload.github.com/requestly/api-usage-examples/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/requestly%2Fapi-usage-examples/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32050896,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-20T11:35:06.609Z","status":"ssl_error","status_checked_at":"2026-04-20T11:34:48.899Z","response_time":94,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-15T11:21:07.577Z","updated_at":"2026-04-20T14:32:02.339Z","avatar_url":"https://github.com/requestly.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Requestly API Usage Examples\nExamples of how to manage rules in a workspace through APIs.\n\n## References\n- Documentation - https://docs.requestly.com/public-apis/overview\n- Playground - https://requestly.readme.io/\n\n## Code Usage\n\n### Dependency\n\n```bash\nnpm install api --save\n```\n\n```js\nconst sdk = require('api')('@requestly/v1.0#2dp5to2dlm1spg1x');\nsdk.auth(process.env.TEAT1_WORKSPACE_API_KEY);\n```\n\n**You can get the API Key by contacting us**\n\n### Fetch All Rules\n\n```js\nasync function fetchAllRules() {\n    console.log('Fetching all rules...');\n    let allRules = null;\n\n    try {\n        const apiResponse = await sdk.getRules();\n        allRules = apiResponse.data;\n        console.log('Number of rules 👉👉👉👉', allRules.data.length);\n    } catch(e) {\n        console.error(e);\n    }\n    \n    return allRules;\n}\n```\n\n### Create a Rule\n```js\nasync function createNewRedirectRule(ruleName, ruleDesc, requestURL, destinationURL) {\n    try {\n        const postRulesAPIRresponse = await sdk.postRules({\n            objectType: 'rule',\n            ruleType: 'Redirect',\n            status: 'Active',\n            name: ruleName,\n            description: ruleDesc,\n            pairs: [\n                {\n                source: {\n                    key: 'Url',\n                    operator: 'Equals',\n                    value: requestURL\n                },\n                destination: destinationURL,\n                destinationType: 'url'\n                }\n            ]\n        });\n\n        if (postRulesAPIRresponse.data.success) {\n            console.log('👉 Rule created successfully!!');\n        }\n\n        return postRulesAPIRresponse.data;\n    } catch (e) {\n        console.error(e);\n    }\n}\n```\n\n### Update a Rule\n\n```js\nasync function updateRedirectRule(ruleId, ruleName, ruleDesc, requestURL, destinationURL) {\n    console.log(`👉 Updating a rule with Id=${ruleId} And name=${ruleName}`);\n\n    try {\n        const updateRulesAPIResponse = await sdk.putRulesRuleid({\n            objectType: 'rule',\n            ruleType: 'Redirect',\n            status: 'Active',\n            name: ruleName,\n            description: ruleDesc,\n            pairs: [\n              {\n                source: {\n                  key: 'Url',\n                  operator: 'Equals',\n                  value: requestURL\n                },\n                destination: destinationURL,\n                destinationType: 'url'\n              }\n            ]\n          }, {ruleId: ruleId})\n\n        if (updateRulesAPIResponse.data.success) {\n            console.log('👉 Rule updated successfully!!', updateRulesAPIResponse.data.data);\n        }\n\n        return updateRulesAPIResponse.data;\n    } catch (e) {\n        console.error(e);\n    }\n}\n```\n\n### Delete a Rule\n```js\nasync function deleteRule(ruleId) {\n    try {\n        deleteRuleAPIResponse = sdk.deleteRulesRuleid({ ruleId });\n    } catch (e) {\n        console.error(e);\n    }   \n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frequestly%2Fapi-usage-examples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frequestly%2Fapi-usage-examples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frequestly%2Fapi-usage-examples/lists"}