Need translation script to decode base64 content for Option List - get error "atob is not defined"

Hi, I’m trying to write a translation script for an Option List to decode the “content” part, encoded in base64, of a file requested from GitLab.

Response if curl command is executed from shell console:

{
    "file_name": "test.txt",
    "file_path": "test.txt",
    "size": 55,
    "encoding": "base64",
    "content_sha256": "xxxxxxxxxxxxxxxxxxxxxxx",
    "ref": "master",
    "blob_id": "xxxxxxxxxxxxxxxxxxxxxxx",
    "commit_id": "xxxxxxxxxxxxxxxxxxxxxxx",
    "last_commit_id": "xxxxxxxxxxxxxxxxxxxxxxx",
    "execute_filemode": false,
    "content":  "eyJmcnVpdCI6eyJuYW1lIjoiYXBwbGUiLCJjb2xvciI6ImdyZWVuIiwicHJpY2UiOjEuMjB9fQ=="
}

Decoded “content” is: {“fruit”:{“name”:“apple”,“color”:“green”,“price”:1.20}}

OPTION LIST configuration is as follow:

SOURCE URL: https://< Git server name >/api/v4/projects/17/repository/files/test.txt?ref=master
IGNORE SSL: checked
ADD HEADER:

  • NAME: PRIVATE-TOKEN
  • VALUE: < token >

TRANSLATION SCRIPT:

var jsontmp  = atob(data.content)
results = jsontmp.fruit

If I click “SAVE CHANGES” in Option List I get error “atob is not defined”

How can I add atob to use in my translation script?

Thanks in advance!

I’m checking internally if we can use something like buffers to interpret the data. I suspect we’re only expecting a string and are not allowing additional actions in the initial payload verification.

Just a heads up on a few things:

  1. I believe we assume content already so most likely your translation script should be:
var jsontmp  = atob(data)
results = jsontmp.fruit
  1. I believe the content should be an array of data, so a slight typo on your decoded content.
{"fruit":[{"name":"apple","color":"green","price":1.20}]}

Hi,
thanks for your reply and sorry for the delay.

I have already tried to use “Buffer” instead atob, and run in the similar error “buffer is not defined”.

I’ve also changed the file content to your proposed value:

{"fruit":[{"name":"apple","color":"green","price":1.20}]}

Would still be happy for a solution :wink:

Thank you!