Home > Software engineering >  Can I utilize cURL parameters without using cURL?
Can I utilize cURL parameters without using cURL?

Time:04-07

This is probably a stupid question but I'm pretty out of my depth here. I'm trying to utilize an API for my business, and while most of the API has the parameters in the form of "site?param1=one&param2=two", one of them does not. Instead it's in the form

required parameters -> key

optional parameters

params: a key-value array of where clauses for the query

I would love to be able to put the parameters in directly in the link, but I'm not sure how to parse this or if it's possible.

Example

https://thepetresorts.gingrapp.com/api/v1/animals?key=KEY&params=[{animal_id=1},{name=Charlie}]

This is the example they provided using cURL, but I'm really not interested in actually programming with the API, I just need to make specific pulls every once in a while, and I cannot for the life of me figure out how to utilize cURL.

curl "https://{your-subdomain-here}.gingrapp.com/api/v1/animals" \
     -H 'Content-Type: application/x-www-form-urlencoded; charset=utf-8' \
     --data-urlencode "params[month(from_unixtime(birthday))]=11" \
     --data-urlencode "key={your-key-here}"

Any advice would be extremely appreciated!

CodePudding user response:

If you're working with an API, it's even better if you can use POSTMAN or INSOMNIA.

CodePudding user response:

The API your describing has two types of requests, GET and POST - the GET request is usually used to "get to view" but occasionally some use it to also modify and push data - this uses parameters within the URL (what you described), POST however is generally used to push data into the body to make a modification, the parameters are posted within the body of the request instead of in the actual URL like GET requests.

You won't be able to modify the endpoint (unless its your own) you will need to GET where its needed and POST when its needed, the POST request will likely deny a GET request as it's not the intended method - you can create a jump page (your own API) to accept GET parameters and generate a POST request to your API - as @muklis mentioned POSTMAN is great you can create the request in there, generate the code in any language and use that to produce a simple PHP page or so that'll take in $_GET[] variables and pass them into the generated POSTMAN request - it's probably your best bet.

-- Edit

You can also use Zapier, forgot about that - Zapier is amazing for easy code-less integrations; you can use the Webhook zap to receive your parameters in repost them in two easy steps within the zap.

Just another idea for you.

  • Related