Can we dynamically add data source headers

  • 1
  • Question
  • Updated 11 months ago
  • Answered
I'm working with a legacy proprietary REST API. The initial authentication token is returned in the body of one API call and I can retrieve it with no problem. For subsequent calls, an authentication token must be passed in a header variable.

Just to make things more interesting, on each call, the system may return a new token and/or a new header variable. For example:

Request 1
    HeaderA : tokenZ
Response 1
    HeaderA : tokenY

Request 2 HeaderA : tokenY Response 2 HeaderB : tokenY
Request 3 HeaderB : tokenY Response 3 HeaderA : tokenX
Request 4 HeaderA : tokenX etc...
The header variable can be one of two possibilities, so identifying it is not difficult. However, I need some way to save the header variable and value from the response and set it on the next request. As far as I can tell there is no way to retrieve header variables in the model nor can I see a way to add a header variable to the data source before the request is made.

Anyone have any suggestions?
Photo of telennar

telennar

  • 90 Points 75 badge 2x thumb

Posted 11 months ago

  • 1
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
The short answer is: we don't have any way to do this declaratively.

When REST Models are loaded, we don't store the returned headers anywhere, so this is not currently doable using REST Models. We could add that in the future, but nothing there right now.

So, right now, if you're desperate to do this, you're left with some pretty involved workarounds involving JavaScript. We can go into more depth on this if needed.
Photo of telennar

telennar

  • 90 Points 75 badge 2x thumb
So it seems the next option would be to define UI-only models, build and send the request using XHR, and manually populate the models with the result.

Is there a documented API or accepted technique for doing this? Something that will be supported in future releases?