Skip to main content
LAWRENCE RIZZO
New Participant
Jan 7, 2021 5:49 PM UTC
Solved

Error code 2 with SetRequestHeader / Authorization

Hello,

I am receiving an error code 2 when trying to use the createRequestHeader function.:
Source:    stat = setRequestHeader (restPUT, 'Authorization', 'Basic ':AUTHORIZATION.STRING)

The REST API I am working with uses an API KEY that is created and converted to base64 and added to the "Authorization" header.  I am receiving the correct response when I test in the Postman software, but cannot get the Universe code to work.  I do see in the documentation that the it seems to be expecting the "normal" format for basic user authentication of user:password.  My guess is that is what's throwing the error as my API KEY is just a long string of characters.  

Lastly, I am running Universe v11.3 running on AIX.  Please let me know if you need any other information.

Thanks,
Larry

From the documentation:
This function supports Base64 encoding for Basic authentication. If header_name
contains either “Authorization” or “Proxy-Authorization,”the header_value should
then contain ASCII text user credential information in the format of
“userid:password the header_value should then contain ASCII text user credential
information in the format of “userid:password” as specified by RFC 2617. This
function will then encode the text based on Base64 encoding.
Only Basic authentication is supported. Digest authentication may be supported in
the future. Basic authentication is not safe and is not recommended for use with
transferring secured data.
    Michael Belme
    Inspiring
    Jan 8, 2021 12:35 PM UTC
    Hello,

    I am receiving an error code 2 when trying to use the createRequestHeader function.:
    Source:    stat = setRequestHeader (restPUT, 'Authorization', 'Basic ':AUTHORIZATION.STRING)

    The REST API I am working with uses an API KEY that is created and converted to base64 and added to the "Authorization" header.  I am receiving the correct response when I test in the Postman software, but cannot get the Universe code to work.  I do see in the documentation that the it seems to be expecting the "normal" format for basic user authentication of user:password.  My guess is that is what's throwing the error as my API KEY is just a long string of characters.  

    Lastly, I am running Universe v11.3 running on AIX.  Please let me know if you need any other information.

    Thanks,
    Larry

    From the documentation:
    This function supports Base64 encoding for Basic authentication. If header_name
    contains either “Authorization” or “Proxy-Authorization,”the header_value should
    then contain ASCII text user credential information in the format of
    “userid:password the header_value should then contain ASCII text user credential
    information in the format of “userid:password” as specified by RFC 2617. This
    function will then encode the text based on Base64 encoding.
    Only Basic authentication is supported. Digest authentication may be supported in
    the future. Basic authentication is not safe and is not recommended for use with
    transferring secured data.
    Hi Larry,

    The correct format would not include the word 'Basic ' in the credentials. That is automatically generated when the request is sent, so your code should look more like this:
    stat = setRequestHeader(HANDLE, "Authorization","username:password")

    username and password will be base64 encoded once the request is sent, so don't base64 encode AUTHORIZATION.STRING before setting it as the variable there. If you turn on protocolLogging() you'll see the log will show your request with this header in the proper format if you use my code sample above:
    Authorization: Basic ********************

    Please open a support ticket if you need further assistance.

    Regards,
    Michael Belme
    Rocket U2 Support

    1 reply

    Michael Belme
    Inspiring
    Jan 8, 2021 12:35 PM UTC
    Hello,

    I am receiving an error code 2 when trying to use the createRequestHeader function.:
    Source:    stat = setRequestHeader (restPUT, 'Authorization', 'Basic ':AUTHORIZATION.STRING)

    The REST API I am working with uses an API KEY that is created and converted to base64 and added to the "Authorization" header.  I am receiving the correct response when I test in the Postman software, but cannot get the Universe code to work.  I do see in the documentation that the it seems to be expecting the "normal" format for basic user authentication of user:password.  My guess is that is what's throwing the error as my API KEY is just a long string of characters.  

    Lastly, I am running Universe v11.3 running on AIX.  Please let me know if you need any other information.

    Thanks,
    Larry

    From the documentation:
    This function supports Base64 encoding for Basic authentication. If header_name
    contains either “Authorization” or “Proxy-Authorization,”the header_value should
    then contain ASCII text user credential information in the format of
    “userid:password the header_value should then contain ASCII text user credential
    information in the format of “userid:password” as specified by RFC 2617. This
    function will then encode the text based on Base64 encoding.
    Only Basic authentication is supported. Digest authentication may be supported in
    the future. Basic authentication is not safe and is not recommended for use with
    transferring secured data.
    Hi Larry,

    The correct format would not include the word 'Basic ' in the credentials. That is automatically generated when the request is sent, so your code should look more like this:
    stat = setRequestHeader(HANDLE, "Authorization","username:password")

    username and password will be base64 encoded once the request is sent, so don't base64 encode AUTHORIZATION.STRING before setting it as the variable there. If you turn on protocolLogging() you'll see the log will show your request with this header in the proper format if you use my code sample above:
    Authorization: Basic ********************

    Please open a support ticket if you need further assistance.

    Regards,
    Michael Belme
    Rocket U2 Support