• Resolved haakonme

    (@haakonme)


    I need to connect JSON Content Importer to an API which requires a slightly different authentication format than what may currently be available on the “Basic Settings” page.

    I get

    “Missing Authorization field in HTTP-Header…”

    and have tried the two different ways offered there, and some variations to transform to those formats, but without any luck so far.

    I can connect and receive data from the endpoint with both Postman and cURL without any troubl

    Postman: Authorization, Type = API Key, Key = some_access_key, Value = some_password.

    cURL: curl –location ‘endpoint URL’ –header ‘some_access_key: some_password’

    Apologies if I am doing it wrong, but I currently believe that in addition to

    “Bearer Authorization:ACCESSKEY”
    “Authorization:ACCESSKEY”

    I think I need


    “Authorization: SOME_ACCESS_KEY:SOME_PASSWORD”

    in the header, and I do not understand how or if I can currently do that.

    Cheers,

    Haakon

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author berkux

    (@berkux)

    Hi,

    try

    nobearer Authorization: SOME_ACCESS_KEY:SOME_PASSWORD

    in the general JCI settings at Tab “Basic Settings”

    Bernhard

    Thread Starter haakonme

    (@haakonme)

    Thank you, Bernhard, but I am afraid this did not work. I get the same error message.

    When I look at the cURL header, which works, it contains only SOME_ACCESS_KEY:SOME_PASSWORD, i.e. not the Authorization: bit.

    I tried to use your suggestion without the Authorization bit, i.e.

    nobearer SOME_ACCESS_KEY:SOME_PASSWORD

    but this does not work either.

    Does the code perhaps add “Authorization:” to the header automatically?

    Cheers,

    Haakon

    Plugin Author berkux

    (@berkux)

    Hi,
    <<Does the code perhaps add “Authorization:” to the header automatically?>>
    Yes.
    In a few days, the next version will have a way to add http-headers as you need it.

    Thread Starter haakonme

    (@haakonme)

    Thank you, Bernard! ??

    I did a minor hack to get it working, with

    ??// Extract API key and API password from user input
    ???????$user_input = $acckey;
    ???????list($api_key, $api_password) = explode(':', $user_input, 2);

    ???????$header = array( $api_key => $api_password)

    and then I added a conditional header, as I needed to pass the header a bit differently with this API.

    I have used a log tool to log the HTTP request from two WordPress-plugins which fetch the same API.

    This works:

    “headers”: {
    “SOME_KEY”: “SOME_PASSWORD”
    }

    This does not work, which is what I got from JSON Content Importer:

    “headers”: [
    “SOME_KEY:SOME_PASSWORD”
    ]

    Once I got it working, I noticed a few things.

    First, the plugin works very well – thank you! ??

    Three issues has surfaced.

    1. The template generator says the valid JSON from the API is invalid JSON. I have verified the API does provide valid JSON. When I ignore this, and write the template according to the documentation myself, the plugin works wonderfully.
    2. When using the JCILISTITEM with a subloop-array, it is sometimes not possible to have another {key} above it, then the above {key} will not be displayed at all, but the JCILISTITEM is still shown. I suspect the disappearing above {key} may contain some characters that are not properly escaped, but I have not looked into it. I found a work-around in creating another JCI-block for the above {key}.
    3. I need to add two or more different API sources, and they all have different authentication methods. The JCI Settings page currently allows one API authentication to be set. If this could be a list for different APIs, then that would be really nice. The JCI block does allow different authentication methods, but it currently does not support the header method I need – looking forward to the enhancement.

    Cheers,

    Haakon

    Plugin Author berkux

    (@berkux)

    Hi Haakon,

    ok, this is a way to do that.
    In the new Version 1.5.3 you can set http-Headerfieldpairs in the Tab “Basic Settings”.

    Bernhard

    Thread Starter haakonme

    (@haakonme)

    Thank you, Bernhard, sorry for the untimely answer – this is great! ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘API key in HTTP header – key:value’ is closed to new replies.