Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Curl code from postman doesn't work #186

Closed
forenheith opened this issue Feb 29, 2020 · 5 comments · Fixed by #392
Closed

Curl code from postman doesn't work #186

forenheith opened this issue Feb 29, 2020 · 5 comments · Fixed by #392

Comments

@forenheith
Copy link

forenheith commented Feb 29, 2020

I created request at postman, tested it, all works fine, then I clicked on Code button at the right top corner, copied CURL code, and tried to use it in Windows Shell and got the errors

`At line:2 char:3

  • --header 'x-pr-tenantid: 2720F16E-1E5B-4AA5-93CB-6169E36B5C9E' \
  • ~
    Missing expression after unary operator '--'.
    At line:2 char:3
  • --header 'x-pr-tenantid: 2720F16E-1E5B-4AA5-93CB-6169E36B5C9E' \

Unexpected token 'header' in expression or statement.
At line:3 char:3

  • --header 'x-pr-apikey: <<>> ...
  • ~
    Missing expression after unary operator '--'.
    At line:3 char:3
  • --header 'x-pr-apikey: <<>> ...

Unexpected token 'header' in expression or statement.
At line:4 char:3

  • --header 'Authorization: Bearer <> ...
  • ~
    Missing expression after unary operator '--'.
    At line:4 char:3
  • --header 'Authorization: Bearer <> ...

Unexpected token 'header' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingExpressionAfterOperator`

Then I changed --header on -h and got the new ones

`Invoke-WebRequest : A positional parameter cannot be found that accepts argument '--request'.
At line:1 char:1

  • curl --location --request GET 'http://localhost:60513//sip/transactio ...
  •   + CategoryInfo          : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException
      + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
    
    

-h : The term '-h' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:2 char:1

  • -h 'x-pr-tenantid: 2720F16E-1E5B-4AA5-93CB-6169E36B5C9E' \
  • ~~
    • CategoryInfo : ObjectNotFound: (-h:String) [], CommandNotFoundException
    • FullyQualifiedErrorId : CommandNotFoundException

-h : The term '-h' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:3 char:1

  • -h 'x-pr-apikey: <<>> ...
  • ~~
    • CategoryInfo : ObjectNotFound: (-h:String) [], CommandNotFoundException
    • FullyQualifiedErrorId : CommandNotFoundException

-h : The term '-h' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:4 char:1

  • -h 'Authorization: Bearer <> ...
  • ~~
    • CategoryInfo : ObjectNotFound: (-h:String) [], CommandNotFoundException
    • FullyQualifiedErrorId : CommandNotFoundException`
@sastava007
Copy link
Contributor

@forenheith Let me look into this!

@umeshp7
Copy link
Member

umeshp7 commented Mar 1, 2020

@forenheith
Please don't add your API-Key and Auth tokens in on the public issues. I have removed it from the comment and request you to please rotate all of your API keys and other Authentication tokens.

Also, we'll need more details about this. Can you please provide us with the following information:

Postman App version:
code generators version (if known):
Code Generators setting in App:
[Click on the Wrench Icon (Top right) > Settings > General > 'New Code Generation Mode' (Can you tell us if this is switched on or not?)]
If the above setting is OFF, please turn it on and try to generate the cURL code again and let us know if you still face the same issue.

Finally, can you share the exact Postman Request and the cURL code generated here? (Remove all sensitive information).

@eugenenekh
Copy link

I guess when you say 'Windows Shell' you mean PowerShell.
If that's true, you need to use another delimiter (backtick - `) instead of \ when you split command into several lines.

Guys, it would be great to have backtick (`) as an option for Line continuation character in addition to \ and ^.
Looks like a super easy to do (:

@vJRoF
Copy link

vJRoF commented Mar 10, 2020

I hope i can comment my similar situation within this issue.
If i try to export simple post request with body into cURL and import it back into postman i get new request without any body.

I ended up with such request, for example:
curl -X POST 'http://example.com/api/v1/orders' -H 'Content-Type: application/json' --data-raw '{ "entityId":100, "count":1 }'
Postman verison i have is v7.19.1.

@forenheith
Copy link
Author

forenheith commented Mar 23, 2020

I can't change the delimiter using the Postman. Also for using PowerShell I should change curl to curl.exe and run this script from the Curl's directory.
Another way that I found is disabling option: Split cUrl command across multiple lines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants