Jump to content

cURL Options in Insert from URL Script Step


This topic is 1301 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I'm trying to use an API command using Insert from URL with cURL options, this is what I have in the cURL options:

curl -v -u <user>:<password> --header "Content-Type: application/json" -d '{"type": "typetest", "priority": 1, "description": "desctest", "subject": "subjecttest", "email": "[email protected]", "email_config_id":67 }' -X POST 'https://subdomain.freshdesk.com/api/v2/tickets/outbound_email'

As described in the API documentation: https://developer.freshdesk.com/api/#create_outbound_email

The command works well in the command line but not when executed through Insert from URL, do you know why? is there an error I can't spot?

Thank you,

Link to comment
Share on other sites

I've found the problem: json data must be formatted with JSONFormatElement, so the cURL option in FM must be:

curl -v -u <user>:<password> --header "Content-Type: application/json" --data @$json_parameters  -X POST

Where $json_parameters is a FM variable that stores the value of JSONFormatElement

Link to comment
Share on other sites

37 minutes ago, naio said:

json data must be formatted with JSONFormatElement

I doubt that is the case. JSON data is equally valid whether formatted or not. Unless your API uses a non-conforming parser, formatting should make no difference.

Using another API, i am able to post JSON data using either one of these cURL options:

--header "Content-type: application/json" -d {"name":"Adam","job":"Developer"}
--header "Content-type: application/json" -d @$postData

where the $postData variable contains the same JSON.
 

Note the absence of single quotes in the first option. Of course, if you want to enter this directly into the Insert From URL[] script step's 'Specify cURL options' calculation window, you will need to escape it properly as:

"--header \"Content-type: application/json\" -d {\"name\":\"Adam\",\"job\":\"Developer\"}"

 

Link to comment
Share on other sites

I've tried with my non-formatted json data (as in my first post) but now excluding the single quotes around it and it doesn't work, maybe the API doesn't use a non-conforming parser, I can't tell.

For debugging this I used the very useful tool offered by Mike Duncan here: https://www.soliantconsulting.com/blog/filemaker-rest/ and I see FM is not sending non-formatted data.

Link to comment
Share on other sites

  • 2 weeks later...

Good morning.  Thank you both again for your assistance with this.

What ended up working was formatting the data command with:

JSONSetElement ( "{}" ; ...     rather than
JSONSetElement ( "" ; ...

From what I've seen in other examples when reading forums, I have seen them used interchangeably with the same results. As the resulting text appeared the same whenI ran it (its quite robust) - go figure. Anyway, it's working now and I'm happy.  Thank you for your guidance. :)

Greg

Link to comment
Share on other sites

Haha - I believe in magic, but want NO part of it when doing code. Prefer consistency. :)
I don't understand either, but as the output code was the same it HAS to have the same result.

Thanks Comment.

Link to comment
Share on other sites

  • 2 weeks later...

Again, another picky API:

https://developers.sendinblue.com/reference#updatecontact

With this PUT command, I can't find the way to send the --data parameter to the server. 

These are the cURL options I'm using:

--request PUT \
--header \"accept: application/json\" \
--header \"api-key: " & $$my_api_key & "\" \
--header \"content-type: application/json\" \
--data @$parametre

I've tried to set the $parametre variable to:

JSONSetElement ( "{}" ; "emailBlacklisted" ; True ; JSONBoolean )

JSONFormatElements ( "{\"emailBlacklisted\":true}" )

and simply:

"{\"emailBlacklisted\":true}"

none of these options satisfies the server, which always returns the following error message:

{"code":"bad_request","message":"Input must be a valid JSON object"}

There may be something wrong in the syntax of the --data parameter but I can't find what it is. I've also tried to quote the parameter:

with single quotes --data '@$parametre'

and escaped double quotes --data \"@$parametre\"

None of this seems to work. I'm completely lost...

 

Link to comment
Share on other sites

This topic is 1301 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.