2024 Apr 09 5:53 PM - edited 2024 Apr 09 6:13 PM
Dear SAP Community,
I am currently sending a post request with the following command in an if loop :
RestClient.Post(url, data, headers) . The paramaters url, data and headers are already specified . The problem is that i have further commands after sending the request from the CPQ system in the if loop, that I want to execute. Once The RestClient is run, the further requests are no longer executed.
Does anyone have any suggestions or idea, where or how I can solve such an issue ?
Best regards
Lola
Request clarification before answering.
Hi Cyrine,
It seems like you are attempting to include error messages in the event of a failed API call. If this is the case, it is likely that the scenario will occur when the RestClient.Post execution encounters errors such as HTTP 400/500 errors. In order to handle these potential errors, you will need to use a "try" command to catch them. Otherwise, the script will halt execution when an error occurs.
Sample syntax:
try:
response = RestClient.Post(url, data, headers)
except Exception as e:
context.Quote.AddMessage("message text", MessageLevel.Error, True)
When it comes to "loop" logic, you will need to incorporate "if" logic within a "for" loop.
Best Regards
Fancy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Fancy,
The command context.Quote.AddMessage("Message text", MessageLevel.Error, True) is not considered as an error handling command , it should be actually executed after the sucessful call of the API to inform the user that the post request was sucessful. That's why i am not getting why the post request is blocking any further commands.
Best regards
Lola
Hi Fancy,
if myvariable == myvalue:
response = RestClient.Post(url, data, headers)
context.Quote.AddMessage("message text", MessageLevel.Error, True)
The post request is running perfectly but the next command won't be executed.
Best regards
Lola
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.