How to add dynamic input at the end of the api request url?

Options

Hi! I have the following sample inputs:

data[Name]=John

data[LastName]=Cruz

data[InvoiceDate]=01/01/2023

and I would like to add them in the end of this sample URL:

https://www.pdfotter.com/api/v1/pdf_templates/tem_12345/fill?

the URL will look like this:

https://www.pdfotter.com/api/v1/pdf_templates/tem_12345/fill?data[Name]=John&data[LastName]=Cruz&data[InvoiceDate]=01/01/2023

Do I add the dynamic inputs as params to do this? I've already set them however whenever I run and debug it, the PDF comes out as empty, none of the dynamic inputs have been filled in the PDF. The request url in the debugger is also just: https://www.pdfotter.com/api/v1/pdf_templates/tem_12345/fill? and not like the expected URL above.

Thank you in advance to those who'll help!

Answers

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options

    hey @chrstnstl - can you share screenshots of how your external API call is set up?

  • chrstnstl
    Options

    The setup looks like this. I added the inputs as query params. @Michael Udinski

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options

    hmm, I see you have flat brackets in the path name of your parameters and a format of data[some_value], this seems unusual to me for an API call (it could be correct but I have not seen this format before). Do you have a link to their documentation of this API call?

  • chrstnstl
    Options

    The documentation for PDF otter is here: https://pdfotter.github.io/slate/#fill-in-a-pdf-template @Michael Udinski

    For the format, I just followed it based on the postman details. Unfortunately, I can't share the link for postman but here is a screenshot of how it looks.
    Similar to my sample:
    data[Name]=John

    data[LastName]=Cruz

    data[InvoiceDate]=01/01/2023

    with URL: https://www.pdfotter.com/api/v1/pdf_templates/tem_12345/fill?data[Name]=John&data[LastName]=Cruz&data[InvoiceDate]=01/01/2023

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    edited February 2023
    Options

    Hi @chrstnstl ! The immediate issue is that the API in question is a POST request,and you are sending using GET. You'll find that a lot of the encoding issues you are running into are really a side-effect of that considation. After making your method change, set params with an object with a single member, “data”. Then “set" members of data to be your key-values pairs with the fill-ins you're going for. I expect you'll have better results.

    This is the kind of intersectional, API-related problem is in the “hardest 5%” we often work on during our daily office hours at State Change Pro.

  • chrstnstl
    Options

    @Ray Deck The API request method I did was POST. For the params, will the JSON look like this?
    {

    data: [

    {

    "FirstName": "",

    "LastName": "",

    "InvoiceDate": "",

    }

    ]

    }
    I tried to import a JSON with this format but it still didn't give me the results I wanted.

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    edited February 2023
    Options

    Xano will take care of the square brackets part if you give it the object. Here's what might work better as JSON to import:

    {"data":{"FirstName":"Ray", “LastName”:"Deck", “InvoiceDate”:"2023-02-24"}}

    Note the lack of square brackets around the data.

    After importing an object with the above, Xano will transmit a form-encoded answer that looks like:

    data[FirstName]=Ray&data[“LastName”]=Deck&data[“InvoiceDate”]=2023-02-24


    Figuring out how to get complicated data into these APIs can be a little tricky! But I think you're very close.

  • chrstnstl
    Options

    @Ray Deck I tried your suggestion however, the PDF from PDF Otter is still empty. Here's the debugging info:

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options

    After more careful study, I see you have a header, “content-type: application/json" that is incompatible with the PDFOtter docs. The latter want www-form-encoding, which is the default from Xano if you don't add that header. Try removing it and see if it improves your situation?

  • chrstnstl
    chrstnstl Member
    edited February 2023
    Options

    I tried your suggestion however it still gave me a blank PDF. I tried adding the url with form encoded answer as the whole URL like in the screenshot and it worked. However I am unsure on how to pass the client's info into the URL @Ray Deck

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options

    You can replace known tokens in a string using the “replace” filter. If you want to go down this road, I would the values with something ALL CAPS so they are easy to spot, and then use replace to take the ALL CAPS template and replace with variable you got from the client.

    One more consideration: in this string-building approach, you might need to apply the url_encode filter to each of the variables you apply.

    Let us know how it turns out!

  • chrstnstl
    Options

    Thank you so much @Ray Deck! It worked! Much appreciated!