sn_race
Member
- Joined
- Feb 27, 2022
- Messages
- 11
- Programming Experience
- 5-10
Hello,
could you help me convert the JavaScript code of the POST call found in the function:
In a C # code, I can't find the right way, I don't know much JavaScript, I tried like this:
but it gives me this error on WebResponse:
//System.Net.WebException: 'Remote server error: (400) Invalid request.'
This is the request curl:
could you help me convert the JavaScript code of the POST call found in the function:
JavaScript:
async function ryte ({useCaseId, inputContexts})
documentation/samples/node/index.js at main · rytr-me/documentation
API documentation. Contribute to rytr-me/documentation development by creating an account on GitHub.
github.com
In a C # code, I can't find the right way, I don't know much JavaScript, I tried like this:
C#:
private void GetRytrContent (string _langID, string _toneID, string _usecaseID)
{
string api_key = "<MY-API-KEY>";
WebRequest wr = WebRequest.Create ("https://api.rytr.me/v1/ryte");
wr.ContentType = "application / json";
wr.Method = "POST";
wr.Headers.Add ("Authentication", "Bearer" + api_key);
using (StreamWriter sw = new StreamWriter (wr.GetRequestStream ()))
{
string data = "{" +
"\" languageId \ ": \" "+ _langID +" \ "," +
"\" toneId \ ": \" "+ _toneID +" \ "," +
"\" useCaseId \ ": \" "+ _usecaseID +" \ "," +
"\" inputContexts \ ": \" {\ "<USE-CASE CONTEXT-INPUT KEY-LABEL> \": \ "<VALUE> \"}, "+
"\" variations \ ": \" 1 \ "," +
"\" userId \ ": \" <UNIQUE USER ID> \ "," +
"\" format \ ": \" html \ "," +
"\" creativityLevel \ ": \" default \ "," +
"}";
sw.Write (date);
}
WebResponse httpResponse = (WebResponse) wr.GetResponse (); //System.Net.WebException: 'Remote server error: (400) Invalid request.'
using (StreamReader streamReader = new StreamReader (httpResponse.GetResponseStream ()))
{
var result = streamReader.ReadToEnd ();
TxtDisplay.Text = result.ToString ();
}
}
but it gives me this error on WebResponse:
//System.Net.WebException: 'Remote server error: (400) Invalid request.'
This is the request curl:
C#:
curl \
-H "Authentication: Bearer <API KEY>" \
-H "Content-Type: application / json" \
-d '{"languageId": "<LANUGAGE ID>", "toneId": "<TONE ID>", "useCaseId": "<USE-CASE ID>", "inputContexts": {"<USE-CASE CONTEXT -INPUT KEY-LABEL> ":" <VALUE> "}," variations ": 1," userId ":" <UNIQUE USER ID> "," format ":" html "," creativityLevel ":" default "} ' \
-X POST https://api.rytr.me/v1/ryte
documentation/README.md at main · rytr-me/documentation
API documentation. Contribute to rytr-me/documentation development by creating an account on GitHub.
github.com