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

How do I post the json file using twurl? #150

Open
selvipt opened this issue Jul 14, 2020 · 3 comments
Open

How do I post the json file using twurl? #150

selvipt opened this issue Jul 14, 2020 · 3 comments
Labels

Comments

@selvipt
Copy link

selvipt commented Jul 14, 2020

I am getting The JSON string format is invalid error, When I tried to add the tailored audience user via JSON file. When I tried using the actual payload and it was successful. Does the twurl support file upload? I am expecting something similar the curl has the support like [curl -vX POST http://server/api/v1/places.json -d @testplace.json
--header "Content-Type: application/json"]

URL:
twurl --header 'Content-Type: application/json' -X POST -H "https://ads-api.twitter.com" "/7/accounts/ddg12333/tailored_audiences/33444/users" -r "@/home/k/Downloads/2020-06-30_emails.json"

Response:
{
"errors": [
{
"code": "INVALID",
"message": "The JSON string format is invalid"
}
],
"request": [],
"operation_errors": []
}

@andypiper
Copy link
Contributor

The syntax here is not exactly the same as that used by curl (there's a good opportunity to improve the documentation here!).

As described in this forum post, you can try using a subshell to cat the file contents into your command using the -d option instead of -r

Trying something like

twurl --header 'Content-Type: application/json' -X POST -H "https://ads-api.twitter.com" "/7/accounts/ddg12333/tailored_audiences/33444/users" -d "$(/home/k/Downloads/2020-06-30_emails.json)"

@andypiper andypiper self-assigned this Jul 15, 2020
@selvipt
Copy link
Author

selvipt commented Jul 15, 2020

@andypiper I tried the above command still getting the same error

Command:
twurl --header 'Content-Type: application/json' -X POST -H "https://ads-api.twitter.com" "/7/accounts/ddg12333/tailored_audiences/333444/users" -d "$(home/k/Downloads/2020-06-30-50K_emails.json)"

Response:
{"errors":[{"code":"INVALID","message":"The JSON string format is invalid"}],"request":[],"operation_errors":[]

@andypiper
Copy link
Contributor

I'm not sure it will work with a large file (if you have 50K emails there...) but I'm using zsh and was able to get the contents of a JSON file passed to the command using

-d "$(</home/myuser/file.json)"

If you add the -t option to the twurl command, can you see the contents of the file being picked up and passed to the command?

@andypiper andypiper removed their assignment Dec 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants