I need to GET Auth credentials first and use them in a second API request

By: Haluk Kuruoglu | Asked: 09/01/2022
ForumsCategory: How-toI need to GET Auth credentials first and use them in a second API request
Haluk Kuruoglu asked 2 years ago
Hi there, I need to solve this: when a form is created:
1) It needs to login to [login address] and get the "ServiceTicket" response
2) It needs to enter automatically this "ServiceTicket" response to "Basic Auth" field of another API request made to [add member address] to send some form data. I can create an API autoresponder, retrieve the "ServiceTicket" response and add it to a hidden field in the form. Then I can create another API autoresponder which will trigger after a minute but I cannot figure out how will I add this response to the "Basic Auth" field. Can you please help?
5 Answers
Victor Font answered 2 years ago
Auth credentials are usually static. This means that when you create the original API key in the target system, it never changes. You hard code it into your process. What do you mean when say you need to add the first API response to the Basic Auth field? That is a very unusual approach to multiple API calls. I'm not fully understanding what you want to accomplish here.
Haluk Kuruoglu answered 2 years ago

Hello Victor, Thanks for the reply. I have a static username and password to retrieve a ServiceTicket response first, then I need to enter this ServiceTicket value into "Basic Auth" field in order to send form data via API. Maybe I misunderstood the process?Here what the documentation tells me:

InsertMemberDemography 

Url LIVE: https://api.relateddigital.com/resta/api/Member/InsertMemberDemography
Http verb POST
Parameters  
Header Content-Type: application/json
Authorization: Service Ticket value retrieved after Login action. 

My question is how to add this ServiceTicket value into my Send API data?
Thanks.

Victor Font replied 2 years ago

The link you provided doesn't work. It produces an error:

The requested resource does not support http method 'GET'.

The answer is I don't know. It would help to see what you're doing. If you want to post a video, please include the response from the first API call so we can see the JSON response.

Haluk Kuruoglu answered 2 years ago
Hello Victor thank you for your time. I contacted them and they told me the system does not support GET method and we need to use POST instead. I managed to get a valid response with an online testing form (see attached SS). All I need is to write this ServiceTicket value into the Basic Auth field of the second Send API data form which I don't know how. Best. Haluk
Attachments
Victor Font answered 2 years ago

Unless I'm missing something, add the hidden field's shortcode to the the second API auth string.

Haluk Kuruoglu replied 2 years ago

Victor, thank you for your reply. I was away so I can continue now. There are 2 problems:

1) When I enter username and password to the first form I got an error as response but when I test the API online and POST { "UserName" : "MyUserName","Password" : "MyPassword" } as content I got the proper response as I mentioned earlier. Is there a way to pass this step with some code in functions.php. If yes, how?

2) Even thought that I got the ServiceTicket value from the first response, there is no way to enter this automatically into the Basic Auth field of the second Send API data form. Shortcodes do not work there.

Best,

Haluk Kuruoglu answered 2 years ago
Victor, thank you for your reply. I was away so I can continue now. There are 2 problems: 1) When I enter username and password to the first form I got an error as response but when I test the API online and POST { "UserName" : "MyUserName","Password" : "MyPassword" } as content I got the proper response as I mentioned earlier. Is there a way to pass this step with some code in functions.php. If yes, how? 2) Even thought that I got the ServiceTicket value from the first response, there is no way to enter this automatically into the Basic Auth field of the second Send API data form. Shortcodes do not work there. Best,  
dee wright replied 1 year ago

Haluk, did you ever find a way to do this? I'm having the same problem trying to include a received Bearer token in the API header. The short code is ignored and it sends with the Basic auth.

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right