Skip to content

Fails to POST article #8

@davidmaceachern

Description

@davidmaceachern

Steps to recreate

  1. Install with Cargo, or clone main and compile locally with cargo build.
  2. Export a key for a Dev.to account, an account that contains an article that was created on Dev.to Web version.
  3. Navigate to a directory that contains 4 articles, 3 that have previously been uploaded to Dev.to and 1 new article.
  4. Run devtogo.
  5. Expect Dev.to to return a 422 error.
Dev.to error: 422 {"error":"article param must be a JSON object. You provided article as NilClass","status":422}

Investigation

Have traced it to the POST operation and have removed the send and await from the POST request.

        async move {
            let resp = client
                .post("https://dev.to/api/articles")
                .header("api-key", api_key.as_str())
                .json(&CreateArticleInput {
                    body_markdown: content,
                });
            println!("{:?}", resp);
            Ok(())
            }

Which when printing returns the following without the article param.

RequestBuilder { method: POST, url: "https://dev.to/api/articles", headers: {"api-key": "API_KEY", "content-type": "application/json"} }

It looks like the POST is being made with no value for the article which is why Dev.to throws a nilclass error which is what Ruby does when a value is nil or doesn't exist.

When printing the content that is to be converted by the reqwest json feature

        let content2 = content.clone();
        println!("{}", content2);

It outputs the content without an issue.

---
title: Hello, World!
published: false
tags: discuss, help
series: Hello series
canonical_url: https://example.com/blog/hello
---

Hello DEV, this is my first post

Ideas about what to try next

  • Check whether content.clone() is an issue
  • Check Reqwest and the json feature maybe they have issues?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions