Categories
SAP Blogs

Best practices for web service calls

Best practices for web service calls

Hi, I’m Alexis Gaillot from SAP and I’m working on the SAP Intelligent RPA product in the adoption team.

In this blogpost I will show you how to work with web services using the ajax.call function of SAP Intelligent RPA 1.0 and how to investigate if your call does not work as expected.

This blogpost will be cut in different parts

  • Context
  • Reasons
  • Causes and Resolutions
    • Client Certificates
    • Server Certificates
    • Cookies
    • Tokens
  • Examples of Best Practices
    • Postman
    • cURL
    • Terminal commands
    • Ajax Call
  • Conclusion

Context

When you use the ajax.call function to communicate with a web service, you receive a status from the server such as:

  • 200.
  • 300.
  • And so on.

Sometimes, it seems that the call does not work and you receive a generic error message. This can be:

  • The status only.
  • A generic message.

It can be difficult to know where the issue comes from.

Reasons

Web services can combine many different settings:

  • Certificates on server/client side.
  • SSL Certificates, which encrypt information, provide authentication and so on. They are necessary if you want to authenticate on the server.
  • Tokens.

Causes and Resolutions

In this part, you can find the main causes of issues and how to resolve them.

In the following topics, you will learn more about:

  • Client certificates
  • Server certificates
  • Cookies
  • Tokens

Client Certificates

You use Client certificates to authenticate on a server. Sometimes you cannot connect to a server with a certificate.

Server Certificates

API may need such certificates. They are generally mandatory.

ctx.ajax.call is not able to force the call without those certificates.

Moreover, you cannot specify which certificates to use as you are not in a browser environment.

In this case you will need to use cURL, for more information see the chapter Examples of Best Practices below.

Cookies

Cookies allow you to authenticate client requests and keep all session information.

If you need to use cookies in your calls, you must set a cookie to keep this information. You will then be able to use it in another call.

Tokens

A token is a piece of data created by a server that contains information to identify a user and the token validity. If you use the token incorrectly in the Ajax call, it may lead to an issue. Like the cookies, the token needs two calls.

For instance, you make an API call in the Factory. You use the first call to get the token. The second call triggers the API call and it creates a job in the job queue. In this case, the calls are linked. The second call happens if the first one is successful.

Examples of the Best Practices

Here are some examples of the best practices for Web Service Calls.

As stated before, due to the complexity of the Ajax call, you may face different issues.

To assess these issues with the Ajax call, you can use multiple tools:

  • Postman
  • cURL
  • Terminal commands
  • Ajax Call

Let see first what are they exactly and what we can do with them.

Postman

Postman is a tool that allows you to interrogate and test Web services and API calls.

This tool has multiple features and is easy to use.

cURL

cURL is a command-line tool that you can use to get or send data including files using URL syntax.

On Windows 10 build 17063, cURL is included by default.

Terminal Commands

In the Command Prompt, you can test the cURL command during the assessment.

If the test is successful, the agent calls the cURL command through the terminal.

Ajax Call

How to configure your Ajax call function

If you do not know how to configure the Ajax call function, follow this process:

  • Make the request work on Postman
    • a. When it works, click the Code button.
    • b. Choose the programming language you work with (should be “JavaScript – jQuery“)
  • Use this code in the Ajax call function
  • Copy and paste this code in the Desktop Studio and adjust the code if necessary. For more information, see the official documentation on the call function

    How to deal with Ajax call issues

    If you still face issues during the call (issues from the xhr object) after you performed the test in the previous process, try the following tests:

    Try ctx.ajax.call with the option ignoreClientCertificate as true

    By default, the SSL certificate verification is not enabled in Postman. This means that it forces the call even if the certificate is not available.

    If the call on Postman does not work after you enabled this option, this means that this certificate is mandatory to make the call. As stated before, the Ajax call does not have this option.

    One solution could be to use cURL.

  • Try the cURL code given by Postman
    • Follow the How to configurate my Ajax call function process above, from step 1.a. to step 1.b., to retrieve the proper cURL code.
    • In this code, remove all characters \ and replace all the simple quotation marks with double quotation marks.
    • Run the cURL code on Command Prompt.

If you have an error message that appears with the cURL code, do a search on the Internet. The error messages are usually very explicit. If the code is successful, you can integrate it in an SAP Intelligent RPA call.

Conclusion

You know now how to use the web service calls and how to investigate when you encounter an issue.

With SAP Intelligent RPA 2.0 it will be easier. Stay Tune.

Leave a Reply

Your email address will not be published. Required fields are marked *

×
Placement Report
Best practices for web service calls

Best practices for web service calls
×
Interview Questions
Best practices for web service calls

Best practices for web service calls
×
Learn More
Best practices for web service calls

Best practices for web service calls
×
Sign Up Now
Best practices for web service calls

Best practices for web service calls
×
Join Us
Best practices for web service calls

Best practices for web service calls
×
Get started
Best practices for web service calls

Best practices for web service calls
×
Buy Now
Best practices for web service calls

Best practices for web service calls
×
Download Course Content
Best practices for web service calls

Best practices for web service calls
×
Call Back
Best practices for web service calls

Best practices for web service calls
×
Ask for Demo
Best practices for web service calls

Best practices for web service calls
×
Enquiry
Best practices for web service calls

Best practices for web service calls
×
Please fill form to see Video
Best practices for web service calls

Best practices for web service calls
×
Schedule Your Demo
Best practices for web service calls

Best practices for web service calls
×
Apply for scholarship