on 12-07-2023 1:34 PM
Hello team,
I am trying to create a destination so that I can consume the REST API of Decision from Build process automation in my BTP abap instance.
I get the error as 401: Unauthorized.
When I tested by creating environment using the service key details directly in apihub https://api.sap.com/api/SPA_Decision/tryout I was successful.
Testing with the code snippet available works fine until I use the generated bearer token.
When I wanted to replace the code based on the option to get the HTTP destination via destination service, I am unable to achieve this due to this 401 error.
DATA(lo_http_destination) =
cl_http_destination_provider=>create_by_url( 'https://spa-api-gateway-bpi-eu-prod.cfapps.eu10.hana.ondemand.com/public/rule/runtime/rest/v2/rule-services' ).
"alternatively create HTTP destination via destination service
"cl_http_destination_provider=>create_by_cloud_destination( i_name = '<...>'
" i_service_instance_name = '<...>' )
"SAP Help: https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/f871712b816943b0ab5e04b6079...
"create HTTP client by destination
DATA(lo_web_http_client) = cl_web_http_client_manager=>create_by_http_destination( lo_http_destination ) .
"adding headers
DATA(lo_web_http_request) = lo_web_http_client->get_http_request( ).
lo_web_http_request->set_header_fields( VALUE #(
( name = 'Authorization' value = <'Bearer token'>
( name = 'DataServiceVersion' value = '2.0' )
( name = 'Accept' value = 'application/json' )
( name = 'Content-Type' value = 'application/json' )
) ).
Could you please let me know what was the error in creating the destination?
Once this would be achieved, I am trying to consume destination as per the help document. Is this the right approach?
Any feedback on this topic would be highly appreciated.
Thank you
Regards
Arunkumar
Hello Arunkumar,
You can ignore this error with destination. If the icon shown is green which means the connection is fine. You can process with using this destination in your process.
Hope that helps,
Archana
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi archana.shukla ,
Thanks for the feedback. But when I passed this destination to this code below, it raised exception.
"cl_http_destination_provider=>create_by_cloud_destination( i_name = '<...>' )
I followed then the approach of creating communication arrangement as mentioned above by ivan.mirisola and it worked for me. But still is it good idea to go with creating a destination or using the communication arrangement from your point of view?
Thanks & Regards
Arunkumar
User | Count |
---|---|
77 | |
9 | |
8 | |
6 | |
6 | |
6 | |
6 | |
6 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.