39
Views
8
Comments
Pass Variable to OnBeforeRequest of API
Application Type
Reactive

Hi,


I want to know if it is possible to pass local variable into OnBeforeRequest of API.


I want to pass the Data through the  OnBeforeRequest because my generated key will based on what is the user's input.




Thank you

You can pass that data in your request by adding a new attribute <VarName> then in onbeforerequest you can JSON deserialise the request text and add it to the header.

Set the datatype of JSON deserialise to the same data type as your Request.

Then you can assign it to the header as JSONDeserialize.Data.<VarName>

Let me know if this works or not.



Hi Vibhor,


Can you please elaborate the adding new attribute and the JSON Deserialize part?


I don't quite catch.  Or do you mean that I do something Like this?




Thank you

I didn't get the loop part but yeah that's the gist of it I just meant if you are not getting the value you need for suite-signature in your request then you need to add it to your Request for the API.

Then when you deserialise the RequestText you will get that value and can assign it to the header.

 If this doesn't work then try the below.

Another option I can suggest is you create a server action and call the API in the server action/service action. In the API create a header by the name of suite-header of whatever the name is of the header you want. It will show up as input parameter in the API then.

The server action can have the inputs required to set the suite-signature as well as your API request. This can help you set the value of that header and the other attributes in a similar way. You can basically not use on before request and pass all headers by using the input params created by adding new headers to API then unless you want to use onbefore.

Thanks, I will try this out and get back to you

Hi Vibhor,


If you don't mind, can you give me an example oml of this flow? I can't visualize the flows that you are sharing although I get some gist of it.


Thank you so much

I have added this test OML for the server action approach I defined let me know if this would help. I just created a server action which can be called.

Test.oml

Thanks Vibhor,


One last thing, the same method can be applied when I want to pass value to the RequestText?


The request text is basically text form of your request JSON, so if it is present in your API request structure you will be seeing it there.

If you add some logic in the server action I created there you can add the value you want to the request and then you can get it in onbeforerequest if you need.

The method I posted was not manipulating the request text but if you want to do it maybe you could but I'd suggest to stick to one approach.

Hopefully your issue is resolved now.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.