如何将数据解析为MRPeasy的POST请求



TLDR

对于我的API项目,我需要向MRP发送POST请求来更新一些字段。我目前正在努力解决的是将参数解析为数据的能力,每次我发送请求时,我都会得到一个代码400。

完整解释

MRPeasy有一个文档页面,我在这个项目中大量使用,因为这是唯一的信息来源。在那篇文章中,他们给出了两个例子,一个用于GET,一个针对POST,我对GET请求没有任何问题,它运行得非常好。然而,POST没有,它们如下:

curl -X "GET" "https://app.mrpeasy.com/rest/v1/items" 
-H 'Content-Type: application/json' 
-H 'api_key: xxxxxxxxxxxxx' 
-H 'access_key: xxxxxxxxxxxxx'
curl -X "PUT" "https://app.mrpeasy.com/rest/v1/items/5" 
-H 'Content-Type: application/json' 
-H 'api_key: xxxxxxxxxxxxx' 
-H 'access_key: xxxxxxxxxxxxx' 
-d '{"selling_price": "2.54"}'

以下是我在python中对上述代码的表示:

```python
url = "https://app.mrpeasy.com/rest/v1/manufacturing-orders/69"
headers = {
"Content-Type": "application/json",
"api_key": my_api_key,
"access_key": my_access_key
}
print(requests.get(url, headers=headers).json()["custom_3338"])
url = "https://app.mrpeasy.com/rest/v1/manufacturing-orders/69"
headers = {
"Content-Type": "application/json",
"api_key": my_api_key,
"access_key": my_access_key
}
data = json.dumps({"custom_3338": "1654642800.0000000000"})
print(requests.post(url, headers=headers, data=data).status_code)
```

关于数据变量,我已经尝试了以下所有方法:

'{"custom_3338": "1654642800.0000000000"}'
{"custom_3338": "1654642800.0000000000"}
{"due_date": "1654642800.0000000000"}
{"quantity": 3}
'{"quantity": 3}'

我希望这是足够的信息。如果你还需要我提供什么,请告诉我,我会非常乐意提供的。

非常感谢,Greg

附言:这是我的第一篇帖子,所以如果我没有遵守一些规则或最佳实践,我深表歉意。

您可以创建一个json文件,该文件包含要作为数据发送的数据,并使用json文件本身发送请求。

  • JSON
{"custom_3338": "1654642800.0000000000"}
  • 卷曲
curl -X POST 
-H 'Content-Type: application/json' 
-H 'api_key: xxxxxxxxxxxxx' 
-H 'access_key: xxxxxxxxxxxxx'
--data "@./processGroup.json" 
https://app.mrpeasy.com/....

或者更简单的是,直接在正文中传递数据:

curl -X POST 
-H 'Content-Type: application/json' 
-H 'api_key: xxxxxxxxxxxxx' 
-H 'access_key: xxxxxxxxxxxxx'
--data '{"custom_3338": "1654642800.0000000000"}' 
https://app.mrpeasy.com/....

最新更新