<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: Send Image CL_HTTP_CLIENT in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/send-image-cl-http-client/qaa-p/12666166#M4751964</link>
    <description>&lt;P&gt;NB:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;The link to POST /now/attachment/file is exactly this link: &lt;A href="https://developer.servicenow.com/dev.do#!/reference/api/rome/rest/c_AttachmentAPI#attachment-POST-file"&gt;https://developer.servicenow.com/dev.do#!/reference/api/rome/rest/c_AttachmentAPI#attachment-POST-file&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;The documentation concerning the Request Body is wrong twice concerning "XML or JSON" and "Path to the binary file...", as it seems that only the binary content is expected, without anything else.&lt;/LI&gt;&lt;/OL&gt;</description>
    <pubDate>Tue, 28 Feb 2023 17:03:53 GMT</pubDate>
    <dc:creator>Sandra_Rossi</dc:creator>
    <dc:date>2023-02-28T17:03:53Z</dc:date>
    <item>
      <title>Send Image CL_HTTP_CLIENT</title>
      <link>https://community.sap.com/t5/technology-q-a/send-image-cl-http-client/qaq-p/12666158</link>
      <description>&lt;P&gt;Hello Experts,&lt;/P&gt;
  &lt;P&gt;I need to send an image via the post method of cl_http_client. The target system is expecting the image in binary format. I have tried using 'SCMS_XSTRING_TO_BINARY' but this gives the result in hexadecimal format. I then tried passing xstring and base 64 encoded file but the target system is unable to convert it. Is there anyway to achieve this? &lt;/P&gt;
  &lt;P&gt;This is Service Now API, I am trying to add an attachment to an Incident. This is the link for API documentation.&lt;/P&gt;
  &lt;P&gt;&lt;A href="https://developer.servicenow.com/dev.do#!/reference/api/rome/rest/c_AttachmentAPI#attachment-POST-file"&gt;https://developer.servicenow.com/dev.do#!/reference/api/rome/rest/c_AttachmentAPI#attachment-POST-file&lt;/A&gt;&lt;/P&gt;
  &lt;P&gt;I am using POST/now/attachment/file&lt;/P&gt;
  &lt;P&gt;I need to add the image in request body. here is the documentation screenshot for your reference. &lt;/P&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/2144603-image.png" /&gt;&lt;/P&gt;
  &lt;P&gt;Below is the sample code I am using &lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;
REPORT ztest_api_call.

DATA:
  ls_desc        TYPE soli,
  lv_response    TYPE string,
  lv_data        TYPE string,

*   Data Declarations for http client.
  lo_http_client TYPE REF TO if_http_client,
  lo_rest_client TYPE REF TO cl_rest_http_client,

*   Data Declarations for http client header.
  lt_headers     TYPE tihttpnvp,
  ls_headers     LIKE LINE OF lt_headers.

* create an instance of type CL_HTTP_CLIENT to perform the HTTP communication in ABAP
DATA(lv_url) = 'https://instance.servicenow.com/api/now/attachment/file?table_name=incident&amp;amp;table_sys_id=d71f7935c0a8016700802b64c67c11c6&amp;amp;file_name=Issue_screenshot.jpg'.
cl_http_client=&amp;gt;create_by_url(
  EXPORTING
    url = CONV string( lv_url )
  IMPORTING
    client = lo_http_client
  EXCEPTIONS
    argument_not_found = 1
    plugin_not_active = 2
    internal_error = 3
    OTHERS = 4 ).

CHECK lo_http_client IS BOUND.
* Disable the authentication Pop-up
lo_http_client-&amp;gt;propertytype_logon_popup = if_http_client=&amp;gt;co_disabled.

* Authenticate using the Service now user id and pwd.
CALL METHOD lo_http_client-&amp;gt;authenticate
  EXPORTING
    username = 'username'
    password = 'password'.

* Set method as post method.
lo_http_client-&amp;gt;request-&amp;gt;set_method(
  EXPORTING
    method = if_http_entity=&amp;gt;co_request_method_post ).

* Set content type as json
lo_http_client-&amp;gt;request-&amp;gt;set_content_type(
  EXPORTING
    content_type = 'image/png' ).

*Get the current active screen as screen shot.
CALL METHOD cl_gui_frontend_services=&amp;gt;get_screenshot
  IMPORTING
    mime_type_str        = DATA(lv_mime)
    image                = DATA(lv_img)
  EXCEPTIONS
    access_denied        = 1
    cntl_error           = 2
    error_no_gui         = 3
    not_supported_by_gui = 4
    OTHERS               = 5.

lo_http_client-&amp;gt;request-&amp;gt;set_cdata(
  EXPORTING
    data =  CONV string( lv_img ) ).

*Prepare header of the API call.
CREATE OBJECT lo_rest_client
  EXPORTING
    io_http_client = lo_http_client.

ls_headers-name  = lc_content_type..
ls_headers-value = 'image/png'.
APPEND ls_headers TO lt_headers.

CALL METHOD lo_rest_client-&amp;gt;if_rest_client~set_request_headers
  EXPORTING
    it_header_fields = lt_headers.

* Send and recieve the data to and from Service now API
lo_http_client-&amp;gt;send(
  EXCEPTIONS
    http_communication_failure = 1
    http_invalid_state = 2 ).


CHECK sy-subrc = 0.
lo_http_client-&amp;gt;receive(
  EXCEPTIONS
    http_communication_failure = 1
    http_invalid_state = 2
    http_processing_failed = 3 ).

* Response manipulation to get the incident number.
lv_response = lo_http_client-&amp;gt;response-&amp;gt;get_cdata( ).


&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;Regards,&lt;/P&gt;
  &lt;P&gt;Siddhesh &lt;/P&gt;</description>
      <pubDate>Mon, 27 Feb 2023 17:08:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/send-image-cl-http-client/qaq-p/12666158</guid>
      <dc:creator>sid_07_</dc:creator>
      <dc:date>2023-02-27T17:08:38Z</dc:date>
    </item>
    <item>
      <title>Re: Send Image CL_HTTP_CLIENT</title>
      <link>https://community.sap.com/t5/technology-q-a/send-image-cl-http-client/qaa-p/12666159#M4751957</link>
      <description>&lt;P&gt;An image is always in "binary format". Anything is binary anyway when it's about computers. So, the question is: &lt;STRONG&gt;which exact format?&lt;/STRONG&gt; Please complete the question e.g. maybe you want in &lt;A href="https://en.wikipedia.org/wiki/Base64"&gt;Base64&lt;/A&gt; in HTTP Request Body, within a given XML request, in a given XML element of ... Or within JSON? Or what?&lt;/P&gt;&lt;P&gt;Or do you want to send a request full binary containing the image? (Content-Type: image/png)&lt;/P&gt;&lt;P&gt;Or anything else?&lt;/P&gt;&lt;P&gt;After that, we can tell  you what to use in ABAP.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2023 08:19:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/send-image-cl-http-client/qaa-p/12666159#M4751957</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2023-02-28T08:19:52Z</dc:date>
    </item>
    <item>
      <title>Re: Send Image CL_HTTP_CLIENT</title>
      <link>https://community.sap.com/t5/technology-q-a/send-image-cl-http-client/qaa-p/12666160#M4751958</link>
      <description>&lt;P&gt;Can you edit your question and share example code where you are trying to send XSTRING ? Do you have any documentation for the target system API ?&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2023 08:45:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/send-image-cl-http-client/qaa-p/12666160#M4751958</guid>
      <dc:creator>Tomas_Buryanek</dc:creator>
      <dc:date>2023-02-28T08:45:03Z</dc:date>
    </item>
    <item>
      <title>Re: Send Image CL_HTTP_CLIENT</title>
      <link>https://community.sap.com/t5/technology-q-a/send-image-cl-http-client/qaa-p/12666161#M4751959</link>
      <description>&lt;P&gt;Can you share the current sample code of how you call CL_HTTP_CLIENT? XSTRING should be fine for a binary body, but I suspect you are missing the correct Content-Type header, so that the server doesn't recognize the content correctly?!&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2023 11:44:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/send-image-cl-http-client/qaa-p/12666161#M4751959</guid>
      <dc:creator>Ulrich_Schmidt1</dc:creator>
      <dc:date>2023-02-28T11:44:19Z</dc:date>
    </item>
    <item>
      <title>Re: Send Image CL_HTTP_CLIENT</title>
      <link>https://community.sap.com/t5/technology-q-a/send-image-cl-http-client/qaa-p/12666162#M4751960</link>
      <description>&lt;P&gt;Hi  &lt;SPAN class="mention-scrubbed"&gt;sandra.rossi&lt;/SPAN&gt;   &lt;SPAN class="mention-scrubbed"&gt;tomas.buryanek&lt;/SPAN&gt;   &lt;SPAN class="mention-scrubbed"&gt;ulrich.schmidt&lt;/SPAN&gt; I have added the requested detail. Thank you for the help.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2023 12:43:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/send-image-cl-http-client/qaa-p/12666162#M4751960</guid>
      <dc:creator>sid_07_</dc:creator>
      <dc:date>2023-02-28T12:43:44Z</dc:date>
    </item>
    <item>
      <title>Re: Send Image CL_HTTP_CLIENT</title>
      <link>https://community.sap.com/t5/technology-q-a/send-image-cl-http-client/qaa-p/12666163#M4751961</link>
      <description>&lt;P&gt;Hello Siddhesh,&lt;BR /&gt;you should not use method REQUEST-&amp;gt;SET_CDATA. It is for character data. Instead use REQUEST-&amp;gt;SET_DATA which is for binary data.&lt;/P&gt;&lt;P&gt;Description from class CL_HTTP_REQUEST:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;IF_HTTP_ENTITY~SET_CDATA - Sets the HTTP body of this entity to the given char. data&lt;/LI&gt;&lt;LI&gt;IF_HTTP_ENTITY~SET_DATA - Sets the HTTP body of this entity to the given binary data&lt;BR /&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Otherwise your code seems to be OK, but it is hard to read. You should use "CODE" tool in your post editor to properly format the code.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2023 12:49:55 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/send-image-cl-http-client/qaa-p/12666163#M4751961</guid>
      <dc:creator>Tomas_Buryanek</dc:creator>
      <dc:date>2023-02-28T12:49:55Z</dc:date>
    </item>
    <item>
      <title>Re: Send Image CL_HTTP_CLIENT</title>
      <link>https://community.sap.com/t5/technology-q-a/send-image-cl-http-client/qaa-p/12666164#M4751962</link>
      <description>&lt;P&gt;Thanks  &lt;SPAN class="mention-scrubbed"&gt;tomas.buryanek&lt;/SPAN&gt;, the solution worked. Going forward I will make use of the CODE tool. &lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2023 13:12:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/send-image-cl-http-client/qaa-p/12666164#M4751962</guid>
      <dc:creator>sid_07_</dc:creator>
      <dc:date>2023-02-28T13:12:39Z</dc:date>
    </item>
    <item>
      <title>Re: Send Image CL_HTTP_CLIENT</title>
      <link>https://community.sap.com/t5/technology-q-a/send-image-cl-http-client/qaa-p/12666165#M4751963</link>
      <description>&lt;P&gt;&lt;SPAN class="mention-scrubbed"&gt;sid_07_&lt;/SPAN&gt; You can even edit your question right now and fix it with the CODE tool, to be kind with today and future visitors of your question.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2023 16:47:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/send-image-cl-http-client/qaa-p/12666165#M4751963</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2023-02-28T16:47:57Z</dc:date>
    </item>
    <item>
      <title>Re: Send Image CL_HTTP_CLIENT</title>
      <link>https://community.sap.com/t5/technology-q-a/send-image-cl-http-client/qaa-p/12666166#M4751964</link>
      <description>&lt;P&gt;NB:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;The link to POST /now/attachment/file is exactly this link: &lt;A href="https://developer.servicenow.com/dev.do#!/reference/api/rome/rest/c_AttachmentAPI#attachment-POST-file"&gt;https://developer.servicenow.com/dev.do#!/reference/api/rome/rest/c_AttachmentAPI#attachment-POST-file&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;The documentation concerning the Request Body is wrong twice concerning "XML or JSON" and "Path to the binary file...", as it seems that only the binary content is expected, without anything else.&lt;/LI&gt;&lt;/OL&gt;</description>
      <pubDate>Tue, 28 Feb 2023 17:03:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/send-image-cl-http-client/qaa-p/12666166#M4751964</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2023-02-28T17:03:53Z</dc:date>
    </item>
    <item>
      <title>Re: Send Image CL_HTTP_CLIENT</title>
      <link>https://community.sap.com/t5/technology-q-a/send-image-cl-http-client/qaa-p/12666167#M4751965</link>
      <description>&lt;P&gt;yeah  &lt;SPAN class="mention-scrubbed"&gt;sandra.rossi&lt;/SPAN&gt;, even I had the same confusion. &lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2023 08:02:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/send-image-cl-http-client/qaa-p/12666167#M4751965</guid>
      <dc:creator>sid_07_</dc:creator>
      <dc:date>2023-03-01T08:02:06Z</dc:date>
    </item>
    <item>
      <title>Re: Send Image CL_HTTP_CLIENT</title>
      <link>https://community.sap.com/t5/technology-q-a/send-image-cl-http-client/qaa-p/12666168#M4751966</link>
      <description>&lt;P&gt;Thanks  &lt;SPAN class="mention-scrubbed"&gt;sandra.rossi&lt;/SPAN&gt;, I have updated the code and documentation link.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2023 08:03:04 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/send-image-cl-http-client/qaa-p/12666168#M4751966</guid>
      <dc:creator>sid_07_</dc:creator>
      <dc:date>2023-03-01T08:03:04Z</dc:date>
    </item>
  </channel>
</rss>

