Skip to content

Instantly share code, notes, and snippets.

@reganstarr
Last active May 24, 2018 21:48
Show Gist options
  • Save reganstarr/153968d6444b9281a9bc291277984be1 to your computer and use it in GitHub Desktop.
Save reganstarr/153968d6444b9281a9bc291277984be1 to your computer and use it in GitHub Desktop.
var mediumIntegrationToken = "REPLACE_WITH_YOUR_MEDIUM_INTEGRATION_TOKEN";
// That's it. No need to edit anything else below.
// split the comma-separated tags string into an array then remove any whitespace
var tagsArray = input.medium_tags.split(',');
for (var i = 0; i < tagsArray.length; i++) {
tagsArray[i] = tagsArray[i].trim();
}
var data = JSON.stringify({
"title": input.medium_title,
"contentFormat": "html",
"content": input.medium_content,
"canonicalUrl": input.medium_canonical_url,
"tags": tagsArray
});
// Look up the author id
fetch('https://api.medium.com/v1/me', {
method: 'GET',
headers: {
'Authorization': 'Bearer ' + mediumIntegrationToken
}
})
.then(function(res) {
return res.json();
})
.then(function(body) {
return body.data.id;
})
.then(function(authorId) {
// Now create the medium post
var apiUrl = 'https://api.medium.com/v1/users/' + authorId + '/posts';
fetch(apiUrl, {
method: 'POST',
body: data,
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + mediumIntegrationToken
}
})
.then(function(res) {
return res.json();
})
.then(function(body) {
var output = body.data;
callback(null, output);
})
.catch(callback);
});
@Rover73
Copy link

Rover73 commented Aug 17, 2016

Hallo guys,

thank you to provide us this code!
I tried to create a Zap with it to post automatically my Wordpress post in Medium but Zapier give me this error:

ReferenceError: zapier_code_create_medium_post is not defined theFunction (eval at (/var/task/index.js:52:23), :8:6) eval (eval at (/var/task/index.js:52:23), :72:5) /var/task/index.js:53:5 b (domain.js:183:18) Domain.run (domain.js:123:23) module.exports.handler (/var/task/index.js:51:5)

I'm not an expert in coding...can you tell me please how to fix this?

Thanks in advance for the support you will give me....

@markdmill
Copy link

Thanks so much for writing this up! I've got it all working great, based on an RSS trigger, but I'm getting an error:

We had trouble sending your test through. Please try again. Error:
2018-04-03T06:16:30.718Z 8c3e1353-3706-11e8-a5e6-d96b7cf2253e Task timed out after 1.00 seconds

Any suggestions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment