"use strict";(self.webpackChunknewoaks_help=self.webpackChunknewoaks_help||[]).push([[6057],{9615:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>c,contentTitle:()=>h,default:()=>p,frontMatter:()=>d,metadata:()=>n,toc:()=>l});const n=JSON.parse('{"id":"api/get-message-credits-usage","title":"Get Message Credits Usage","description":"The  API provides functionality to retrieve message credits usage information by sending a POST request to the /chat/Chatbot/GetMessageCreditsUsage endpoint.","source":"@site/developer/api/111.get-message-credits-usage.md","sourceDirName":"api","slug":"/api/get-message-credits-usage","permalink":"/guides/developer/api/get-message-credits-usage","draft":false,"unlisted":false,"tags":[],"version":"current","sidebarPosition":111,"frontMatter":{"sidebar_position":111},"sidebar":"sidebar","previous":{"title":"Send Twilio Message","permalink":"/guides/developer/api/send-twilio-message"},"next":{"title":"Get Messages History","permalink":"/guides/developer/api/get-message-history"}}');var r=s(4848),i=s(8453),a=s(767),o=(s(9357),s(8175));const d={sidebar_position:111},h="Get Message Credits Usage",c={},l=[{value:"Endpoint",id:"endpoint",level:2},{value:"Request Headers",id:"request-headers",level:2},{value:"Example Request",id:"example-request",level:2},{value:"Response",id:"response",level:2},{value:"Error Handling",id:"error-handling",level:2}];function u(e){const t={code:"code",h1:"h1",h2:"h2",header:"header",p:"p",...(0,i.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(t.header,{children:(0,r.jsx)(t.h1,{id:"get-message-credits-usage",children:"Get Message Credits Usage"})}),"\n",(0,r.jsxs)(t.p,{children:["The ",(0,r.jsx)(o.A,{})," API provides functionality to retrieve message credits usage information by sending a ",(0,r.jsx)(t.code,{children:"POST"})," request to the ",(0,r.jsx)(t.code,{children:"/chat/Chatbot/GetMessageCreditsUsage"})," endpoint."]}),"\n",(0,r.jsx)(t.h2,{id:"endpoint",children:"Endpoint"}),"\n",(0,r.jsx)(a.TM,{path:"/chat/Chatbot/GetMessageCreditsUsage",method:"POST"}),"\n",(0,r.jsx)(t.h2,{id:"request-headers",children:"Request Headers"}),"\n",(0,r.jsx)(a.iW,{headers:{Authorization:"<Your-Secret-Key>"}}),"\n",(0,r.jsx)(t.h2,{id:"example-request",children:"Example Request"}),"\n",(0,r.jsx)(a.r3,{method:"POST",path:"/chat/Chatbot/GetMessageCreditsUsage",headers:{Authorization:"<Your-Session-Key>"},requestBody:{}}),"\n",(0,r.jsx)(t.h2,{id:"response",children:"Response"}),"\n",(0,r.jsx)(a.zV,{responseExample:{Data:{Total:-1,Used:243,Remain:-1}},responseComments:{Data:"object - Message credits usage information","Data.Total":"integer - Total number of message credits allocated (-1 indicates unlimited credits)","Data.Used":"integer - Number of message credits that have been used","Data.Remain":"integer - Number of message credits remaining (-1 indicates unlimited remaining credits)"}}),"\n",(0,r.jsx)(t.h2,{id:"error-handling",children:"Error Handling"}),"\n",(0,r.jsx)(a.NH,{})]})}function p(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(u,{...e})}):u(e)}},767:(e,t,s)=>{s.d(t,{Ay:()=>g,NH:()=>p,TM:()=>d,VQ:()=>c,iW:()=>h,r3:()=>l,zV:()=>u});s(6540);var n=s(3532),r=s(8069),i=s(9303),a=s(4848);const o=function(e,t){void 0===t&&(t={});const s=JSON.stringify(e,null,2).split("\n"),n=[];return s.forEach((e=>{const s=e.match(/"([^"]+)":/);if(s&&t[s[1]]){const r=e.match(/^\s*/)?.[0]||"";n.push(`${r}// ${t[s[1]]}`)}n.push(e)})),n.join("\n")},d=e=>{let{path:t,method:s="POST"}=e;const r=(0,n.r)()(t)||`https://usapi.hottask.com${t}`;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("p",{children:[(0,a.jsx)("strong",{children:"Request URL:"})," ",r]}),(0,a.jsxs)("p",{children:[(0,a.jsx)("strong",{children:"Method:"})," ",s]})]})},h=e=>{let{headers:t={Authorization:"<Your-Secret-Key>","Content-Type":"application/json"},headersDescription:s={Authorization:"string, required - The secret key for authenticating the API request","Content-Type":"string, required - The content type of the request payload (must be application/json)"}}=e;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("p",{children:"The API request must include the following headers:"}),(0,a.jsx)("ul",{children:Object.entries(t).map((e=>{let[t,n]=e;return(0,a.jsxs)("li",{children:[(0,a.jsxs)("code",{children:[t,": ",n]})," - ",s[t]]},t)}))})]})},c=e=>{let{requestBody:t,requestBodyParams:s,addCommentsToJson:n=o}=e;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("p",{children:"The request body should contain the following parameters:"}),(0,a.jsx)(r.A,{language:"json",children:n(t,s)}),(0,a.jsx)("ul",{children:Object.entries(s).map((e=>{let[t,s]=e;return(0,a.jsxs)("li",{children:[(0,a.jsx)("code",{children:t})," - ",s]},t)}))})]})},l=e=>{let{method:t="POST",path:s,requestBody:o,headers:d={Authorization:"<Your-Secret-Key>","Content-Type":"application/json"}}=e;const h=(0,n.r)()(s),c="undefined"==typeof window?"usapi.hottask.com":new URL(h||`https://usapi.hottask.com${s}`).host,l={javascript:`const res = await fetch('${h||`https://usapi.hottask.com${s}`}', {\n  method: '${t}',\n  headers: ${JSON.stringify(d,null,2)},\n  body: JSON.stringify(${JSON.stringify(o,null,2)})\n});\n\nconst data = await res.json();\nconsole.log(data);`,python:`import requests\nimport json\n\nurl = '${h||`https://usapi.hottask.com${s}`}'\nheaders = ${JSON.stringify(d,null,4)}\ndata = ${JSON.stringify(o,null,2)}\n\nresponse = requests.${t.toLowerCase()}(url, headers=headers, json=data)\ndata = response.json()\nprint(data)`,bash:`curl '${h||`https://usapi.hottask.com${s}`}' \\\n  -X ${t} \\\n${Object.entries(d).map((e=>{let[t,s]=e;return`  -H '${t}: ${s}' \\`})).join("\n")}\n  -d '${JSON.stringify(o)}'`,http:`${t} ${s} HTTP/1.1\nHost: ${c}\n${Object.entries(d).map((e=>{let[t,s]=e;return`${t}: ${s}`})).join("\n")}\n\n${JSON.stringify(o,null,2)}`};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(i.A,{as:"h3",children:"JavaScript (Fetch API)"}),(0,a.jsx)(r.A,{language:"javascript",children:l.javascript}),(0,a.jsx)(i.A,{as:"h3",children:"Python (Requests Library)"}),(0,a.jsx)(r.A,{language:"python",children:l.python}),(0,a.jsx)(i.A,{as:"h3",children:"cURL"}),(0,a.jsx)(r.A,{language:"bash",children:l.bash}),(0,a.jsx)(i.A,{as:"h3",children:"HTTP Request"}),(0,a.jsx)(r.A,{language:"http",children:l.http})]})},u=e=>{let{responseExample:t,responseComments:s,addCommentsToJson:n=o}=e;const i={...t,Version:"1.0.0",Success:!0,Code:200,Message:""},d={...s,Version:"string - API version",Success:"boolean - Operation success status",Code:"integer - HTTP status code",Message:"string - Error message if any"};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("p",{children:"The API response will be a JSON object with the following structure:"}),(0,a.jsx)(r.A,{language:"json",children:n(i,d)})]})},p=e=>{let{errorHandling:t="If the request fails, you should:\n1. Check the HTTP status code for network-level errors\n2. Examine the `Code` and `Message` fields in the response for business-level errors\n3. The `Message` field will contain detailed error information"}=e;return(0,a.jsx)("div",{style:{whiteSpace:"pre-line"},children:t})};function g(e){let{title:t,path:s,method:r="POST",description:i="",requestBody:g={timeZone:"Asia/Shanghai",type:0},requestBodyDescription:m={timeZone:"The time zone of the chatbot. The standard time zone format: e.g., Asia/Shanghai or America/New_York.",type:"Create a generic chatbot with a fixed value of 0"},requestBodyComments:j={timeZone:"string, required",type:"integer, required"},responseExample:x={Data:"3254a9d0424c4806b9ea3d0763xxxxxx",Version:"1.0.0",Success:!0,Code:200,Message:""},responseComments:f={Data:"chatbot id"},headers:y={Authorization:"<Your-Secret-Key>","Content-Type":"application/json"},headersDescription:w={Authorization:"The secret key for authenticating the API request.","Content-Type":"The content type of the request payload."},errorHandling:T="If it's an HTTP network error, you should check the `HTTP status code`. If it's a business exception, you need to examine the `Code` and `Message` fields, which will provide the error details."}=e;const b=(0,n.r)()(s),v="undefined"==typeof window?"usapi.hottask.com":new URL(b||`https://usapi.hottask.com${s}`).host;JSON.stringify(y,null,2),o(g,j),JSON.stringify(y,null,4),o(g,j),r.toLowerCase(),Object.entries(y).map((e=>{let[t,s]=e;return`  -H '${t}: ${s}' \\`})).join("\n"),JSON.stringify(g),Object.entries(y).map((e=>{let[t,s]=e;return`${t}: ${s}`})).join("\n"),o(g,j);return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(d,{path:s,method:r}),(0,a.jsx)(h,{headers:y,headersDescription:w}),(0,a.jsx)(c,{requestBody:g,requestBodyParams:m,addCommentsToJson:o}),(0,a.jsx)(l,{method:r,path:s,requestBody:g,headers:y}),(0,a.jsx)(u,{responseExample:x,responseComments:f,addCommentsToJson:o}),(0,a.jsx)(p,{errorHandling:T})]})}},8175:(e,t,s)=>{s.d(t,{A:()=>i});s(6540);var n=s(5872),r=s(4848);function i(){let e=(0,n.K)()();return["newoaks.ai","www.newoaks.ai","eu.newoaks.ai"].includes(e)&&(e="NewOaks AI"),"appointify.ai"===e&&(e="Appointify AI"),(0,r.jsx)("code",{children:e})}},9357:(e,t,s)=>{s.d(t,{A:()=>a});s(6540);var n=s(5872),r=s(5363),i=s(4848);function a(e){let{children:t}=e;return(0,i.jsx)(r.A,{children:()=>{const e=(0,n.K)()();if("function"==typeof t){const s=t(e);return(0,i.jsx)("div",{className:"markdown markdown--section",children:s})}return(0,i.jsx)("code",{children:e})}})}},3532:(e,t,s)=>{function n(){return function(e){if("undefined"==typeof window)return"";const t=window.location.hostname;let s="";return s="www.newoaks.ai"==t||"newoaks.ai"==t?"https://usapi.hottask.com":"eu.newoaks.ai"==t?"https://euapi.hottask.com":`https://${t}`,e?`${s}${e.startsWith("/")?e:`/${e}`}`:s}}s.d(t,{r:()=>n})},5872:(e,t,s)=>{function n(){return function(){return"undefined"==typeof window?"":window.location.hostname}}s.d(t,{K:()=>n})}}]);