Using API to post videos to Stream, "DNS lookup failed. Please make sure your hostname is valid."

I am trying to create a Zapier Action that posts a video to Stream using a URL. No matter what I do, I get error: “DNS lookup failed. Please make sure your hostname is valid.”

Here is the JSON, in which I have included my Cloudflare account ID in the URL, my email address and API key in the header, and my video URL as a parameter:

const options = {
url: ‘https://api.cloudflare.com/client/v4/accounts/804cd43fdc72b09396cb8548433d7870/stream/copy’,
method: ‘POST’,
headers: {
‘X-AUTH-EMAIL’: {redacted}
‘X-AUTH-KEY’: {redacted}
},
params: {
‘url’: ‘https://media.slapfive.com/ckpfrnj5s00013ba086h3sdtr.mp4
},
body: {

}
}

return z.request(options)
.then((response) => {
response.throwForStatus();
const results = response.json;

// You can do any parsing you need for results here before returning them

return results;
});

Please help.

Hey @jeff23! The url field needs to be in the body like so:

const options = {
  url: 'https://api.cloudflare.com/client/v4/accounts/804cd43fdc72b09396cb8548433d7870/stream/copy',
  method: 'POST',
  headers: {
    'Accept': 'application/json'
    ‘X-AUTH-EMAIL’: {redacted}
    ‘X-AUTH-KEY’: {redacted}
  },
  params: {

  },
  body: {
    'url': 'https://media.slapfive.com/ckpfrnj5s00013ba086h3sdtr.mp4'
  }
}
...

If you’re planning on developing this Zapier Action for others, I suggest that you also offer an input to take the Authorization header as some users prefer to use API Tokens.


I also wanted to point out others who might be reading this that you can use the Webhooks Action to make a request to Stream too!

1 Like

@renan Thank you, that did it, and now that I got the hard-coded string to work, I was able to insert the authData variables for authenticating and inputData variables for the account_id and url.

Quick question, do you suggest I use API Token instead of API Key for authenticating in Zapier? Is one more universal or more current than the other?

1 Like

Bearer tokens are better than the API Key since you can do things like limit what products they can access within your account.

Please also change your Cloudflare global api key given your original post may have exposed it.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.