Hi Rehan,

Rehan Iftikhar <rehan.iftik...@gmail.com> writes:

> Hello
>
> I have a .org file where I am using sh code blocks to interact with a
> REST API via curl. My first call is to authenticate with the REST API
> which returns a token in the HTTP response. I would like to parse that
> HTTP response (ie. with elisp via a subsequent code block) and use the
> token in subsequent sh code blocks. 
>
> Right now I am doing this via a manual step where I step where I run
> the first sh code block, set a :var PROPERTY, and then run the rest of
> the sh code blocks. I would like to automate it if possible.
>
> Thanks,
> -Rehan 


I am not sure, if I understand your question correctly.  But passing the
token to another code block is easy.

There are two straight forwards ways:

1. As a variable

--8<---------------cut here---------------start------------->8---
#+name: authenticate
#+begin_src sh
  ## do sth to generate a token
  token="uagpb"
  echo "$token"
#+end_src

#+name: usethetoken
#+header: :var token=authenticate()
#+begin_src sh
  echo "${token}.ext"
#+end_src

#+results: usethetoken
: uagpb.ext
--8<---------------cut here---------------end--------------->8---

2. Using noweb

--8<---------------cut here---------------start------------->8---
#+name: authenticate
#+begin_src sh
  ## do sth to generate a token
  token="uagpb"
  echo "$token"
#+end_src

#+name: usethetokenvianoweb
#+begin_src sh :noweb yes
  token=<<authenticate()>>
  echo "${token}.ext"
#+end_src

#+results: usethetokenvianoweb
: uagpb.ext
--8<---------------cut here---------------end--------------->8---

HTH,
Andreas


Reply via email to