Skip to main content
1-Visitor
October 28, 2014
Question

consuming external API

  • October 28, 2014
  • 4 replies
  • 1954 views

I'm trying to use an external API that requires a curl request. Is this possible using the content loader functions?

    4 replies

    19-Tanzanite
    October 29, 2014

    Hi David,

    I think the functions in 05.01.03.03 ContentLoaderFunctions, specifically GetText will be perfect for this (but also check the other functions there).
    Available of course in the snippets 🙂

    BR,
    Vladimir



    davidcor1-VisitorAuthor
    1-Visitor
    October 29, 2014

    can you provide me with an example? I'm trying to use an API that requires the request

    curl https://api.domain.com/v2/shipments \
    -u {YOUR API KEY}:

    I've used GetXML for other APIs but can't see how I would be able to consume this one.



    davidcor1-VisitorAuthor
    1-Visitor
    October 29, 2014

    I've tried this:
    var url = https://api.domain.com/v2/shipments
    var params = {

        url: url /* STRING /,<br>    username: apiKey / STRING */,
    };
    var result = Resources["ContentLoaderFunctions"].PostText(params);

    but get "unauthorized 401" as a response.



    1-Visitor
    October 30, 2014

    are you having trouble with the spaces and the slash? Did you try using things like %20 or escape characters?

    davidcor1-VisitorAuthor
    1-Visitor
    October 30, 2014

    Pai - I don't see what you mean.  there are no spaces in the url.  I opened a ticket with support and they said that the code below worked, but I still receive an unauthenticated error

    result = Resources["ContentLoaderFunctions"].PostJSON({
    url: "https://api.easypost.com/v2/shipments",
    password: "",
    username: "d7WlVQmMEFlzQ5a9GvbfXA",
    timeout: 30
    });



    5-Regular Member
    October 30, 2014

    David,

    I assume you replaced the example API key I supplied as the value for username with the API key associated with your account?