🐛 fix(utils.ts): change parameter name from apiKey to api_key to improve consistency and readability

✨ feat(utils.ts): add support for x-api-key header in run_flow function to pass the API key as a header instead of a query parameter
🔧 chore(utils.ts): update getCurlCode function to use x-api-key header instead of api-key header for authentication
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-09-26 11:45:12 -03:00
commit 8deeeb5ba3

View file

@ -327,7 +327,7 @@ TWEAKS = ${
} }
def run_flow(inputs: dict, flow_id: str, tweaks: Optional[dict] = None${ def run_flow(inputs: dict, flow_id: str, tweaks: Optional[dict] = None${
!isAuth ? `, apiKey: str=""` : "" !isAuth ? `, api_key: Optional[str] = None` : ""
}) -> dict: }) -> dict:
""" """
Run a flow with a given message and optional tweaks. Run a flow with a given message and optional tweaks.
@ -340,18 +340,19 @@ def run_flow(inputs: dict, flow_id: str, tweaks: Optional[dict] = None${
api_url = f"{BASE_API_URL}/{flow_id}" api_url = f"{BASE_API_URL}/{flow_id}"
payload = {"inputs": inputs} payload = {"inputs": inputs}
headers = None
if tweaks: if tweaks:
payload["tweaks"] = tweaks payload["tweaks"] = tweaks
${!isAuth ? 'headers = {"api-key": apiKey}' : ""} if api_key:
response = requests.post(api_url, json=payload,headers=headers) headers = {"x-api-key": api_key}
response = requests.post(api_url, json=payload, headers=headers)
return response.json() return response.json()
# Setup any tweaks you want to apply to the flow # Setup any tweaks you want to apply to the flow
inputs = ${inputs} inputs = ${inputs}
${!isAuth ? `api_key = "<your api key>"` : ""} ${!isAuth ? `api_key = "<your api key>"` : ""}
print(run_flow(inputs, flow_id=FLOW_ID, tweaks=TWEAKS${ print(run_flow(inputs, flow_id=FLOW_ID, tweaks=TWEAKS${
!isAuth ? `, apiKey=api_key` : "" !isAuth ? `, api_key=api_key` : ""
}))`; }))`;
} }
@ -374,8 +375,9 @@ export function getCurlCode(
${window.location.protocol}//${ ${window.location.protocol}//${
window.location.host window.location.host
}/api/v1/process/${flowId} \\ }/api/v1/process/${flowId} \\
-H 'Content-Type: application/json'\\ -H 'Content-Type: application/json'\\${
${!isAuth ? `-H 'api-key: <your api key>'\\` : ""} !isAuth ? `\n -H 'x-api-key: <your api key>'\\` : ""
}
-d '{"inputs": ${inputs}, "tweaks": ${ -d '{"inputs": ${inputs}, "tweaks": ${
tweak && tweak.length > 0 tweak && tweak.length > 0
? buildTweakObject(tweak) ? buildTweakObject(tweak)