Forum Discussion

DrSuave's avatar
DrSuave
New Contributor
7 years ago

"Try it out!" button works - nothing else does.

Hi, I'm trying to use someone's Swagger API. The documentation is here: https://api.streetshirts.com/swagger/ui/index#/

 

When I use the Swagger "Try it out!" button for creating an order everything works as expected. But when I send the same curl as the UI in terminal or from my site it sends back "{"Message":"An error has occurred."}"

 

I've talked to the API owner and he's said this:

 

 

"If it works in swagger then it works out end and the data is also good. It must be how your encoding it, or how you are sending the curl.

As a c# developer I don’t know enough about this to help you further."

I agree with him that it should work regardless of where I sent the request from, but I can't figure it out. This is the command I sent from terminal:

 

curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'X-api-key: merchant_id|api_key' -d '{ \ 
"orderlines": [ \ 
{ \ 
"qty": 1, \ 
"sku": "GD05|Black|S", \ 
"mockup_url": "exampleURL", \ 
"front_print_file_url": "exampleURL", \ 
"back_print_file_url": "", \ 
"designkey": "" \ 
} \ 
], \ 
"partner_order_id": "Example_005", \ 
"address": { \ 
"delivery_name": "Example Name", \ 
"address1": "Example Address", \ 
"address2": "", \ 
"city": "London", \ 
"county": "", \ 
"postcode": "xxxxx", \ 
"countrycode": "GB" \ 
} \ 
}' 'https://api.streetshirts.com/orders/create'

 

Have I made some kind of outrageously simple mistake that I can't see?

 

Note the "partner_order_id" needs to be unique everytime, if you try it yourself give it a random string.

 

Any help or advice much appreciated.

 

  • Hey DrSuave ( cool name ),

     

    So it might be the apiKey header that still has dummy data in it, the `merchat_id|api_key` part, which I guess must come from the API provider. Replace `merchat_id` and/or `api_key` with those provided by the company.

    --header 'X-api-key: merchant_id|api_key'

     

    Hopefully that helps a bit!

     

    This doesn't appear to be an issue with the Swagger tooling, but if you feel it is, we'd recommend you look at the Open Source channels to seek help, such as https://swagger.io/support/. 

     

    PS: Please note that is an older version of https://github.com/swagger-api/swagger-ui

     

    • DrSuave's avatar
      DrSuave
      New Contributor

      Thanks for the response - the API owner says he doesn't issue the merchant_id or api_key until a successful test run has been made using just 

      merchant_id|api_key

      If I send the curl using  

      merchant_id_test|api_key

      (a different string) it returns 

      "status":"Not Authorised","message_text":"Invalid merchant_id and api_key combination"

      so it appears that the dummy test info isn't what's breaking this. 

      • HKosova's avatar
        HKosova
        SmartBear Alumni (Retired)

        Hi DrSuave,

         

        Are you on Windows or Mac/*nix?

         

        If on Windows, you need to 1) write the whole command on one line; 2) enclose curl arguments in double quotes instead of single quotes; 3) escape inner quotes in JSON as \" and 4) escape | as ^| in the API key and sku.

         

        The following works for me:

         

        curl -k -X POST "https://api.streetshirts.com/orders/create" -H "Content-Type: application/json" -H "Accept: application/json" -H "X-api-key: merchant_id|api_key" -d "{\"orderlines\": [{\"qty\": 1, \"sku\": \"GD05^|Black^|S\", \"mockup_url\": \"exampleURL\", \"front_print_file_url\": \"exampleURL\", \"back_print_file_url\": \"\", \"designkey\": \"\"}], \"partner_order_id\": \"Example_123\", \"address\": {\"delivery_name\": \"Example Name\", \"address1\": \"Example Address\", \"address2\": \"\", \"city\": \"London\", \"county\": \"\", \"postcode\": \"xxxxx\", \"countrycode\": \"GB\"}}"