I have been stuck at this for a while now and cannot seem to find the answer specific to my case in previous posts.
In my app I have a data type for a sentence. The first field is text. Here is an image of a few sentence rows where the text is displayed in a repeating group:
Context
I now need to translate the sentences in bulk. Logically, I want to make as little API calls as possible. For a translation engine I chose DeepL. For translating multiple sentences at a time, their docs show the following:
This tells me I need to some way to pass a list of sentence texts’ to the API. I started doing some research and read this post: Array of parameters for an API - #10 by prajnyabaliga3186. Keith’s answer really helped me understand what I am dealing with. I did not manage to make it work though
What I do not understand
I am looking for help with how to format (or parse) the text. I need to do this in the JSON body field of the plugin editor.
DeepL description of the text parameter: “Text to be translated. Only UTF8-encoded plain text is supported. The parameter may be specified multiple times and translations are returned in the same order as they are requested. Each of the parameter values may contain multiple sentences. Up to 50 texts can be sent for translation in one request.”
Try making your "Body (JSON Object) match the same structure as in the example. You need to start with an object: {} and then that object needs a key called “translations” which is an array of objects: [{}]. and each object in that array has a key of “text”. That is the structure it is looking for and you are only giving an object.
Also the value of text cannot be an array. If you will pass up to fifty at any given time then you have to add this 50 times and put allow blank for the times you dont use all 50: { "text": "<text>", "target_lang": "<target_lang>" }
I’ve adjusted the code to send 3 sentences at a time (I think). I’m trying to only send one and allowed for blanks. How do you think I should format the text value to initialize the api call?
You have missing comma after the first two object for text
However you should not encoded your json this way. You will lack of flexibility around the text tring
You shoud use {"translaction":"[<texttotranslate>]}
In the field you will set {“text”:“the text to translate here”,“target_lang”:“EN”}
Initialize this way
In WF or Get data call, you will use :format as text to format it like {"text":"this thing text(dynamic)","target_lang":"This thing language(dynamic)"} with delimiter set to comma (,)
Also, the list of skills probable need to be format like: [“ThisVerso_job’s skills:join with (”,")"]
If this can be empty you will need to format as text too
I am not sure about if I need to define shared parameters for the call. Logically I have to define the two required parameters ‘text’ and ‘target_lang’, right?
Anyway, I built the object as you described (with one extra " to close the dynamic values) and tried to initialize the workflow as following:
Update: I did it. Thanks everyone for tips or asking the right questions! Apparently I do not even need to parse JSON but simply use parameters and text formatting. Just sharing the results/solution here for future references.
Here is a screenshot of the plugin editor (working):