404 error on API call

I’m trying to set up an API for a direct mail service. I successfully initialized the OAuth call although I’m not quite sure what to do with the resulting bearer token. Everything gets run through a single company platform account, so my users won’t be connecting to their own accounts.



Next I need to initialize the main call to place an order, but it’s returning a 404 error:

This is my setup:



I’ve tried to implement the docs correctly but clearly something is wrong:

curl --request POST \
  --url https://api.pcmintegrations.com/v2/directmail-api/order \
  --header 'Accept: application/json' \
  --header 'Content-Type: Postcard' \
  --data '[
  {
"extRefNbr": "PBI",
"orderConfig": {
  "designID": 2106,
  "mailClass": "FirstClass",
  "globalDesignVariables": [
    {
      "key": "frontcard",
      "value": "https://portal.pcmintegrations.com/uploads/hq3rlfzh.rli.jpg"
    },
    {
      "key": "backcard",
      "value": "https://portal.pcmintegrations.com/uploads/4ehladjf.qsz.jpg"
    },
    {
      "key": "companyaddress",
      "value": "10 Main St"
    },
    {
      "key": "companycity",
      "value": "Tampa"
    },
    {
      "key": "companyname",
      "value": "PostcardMania"
    },
    {
      "key": "companystate",
      "value": "FL"
    },
    {
      "key": "companyzipcode",
      "value": "33626"
    }
  ]
},
"recipientList": [
  {
    "firstName": "Brock",
    "lastName": "Lee",
    "address": "2145 Sunnydale Blvd",
    "address2": "",
    "city": "Clearwater",
    "state": "FL",
    "zipCode": "33765",
    "extRefNbr": "6912Test",
    "recipientDesignVariables": []
  }
]
  }
]'

If anyone could point me in the right direction I’d greatly appreciate it.

For starters, you’ve got a space in your orders endpoint that maybe shouldn’t be there.

1 Like

Good call, serves me right for lazily copying the POST url. Up to a 401 error now so I need to somehow authorize.

Edit: I set up an Authorization param w/ bearer token but now I’m getting a JSON error


[
  {
    "extRefNbr": "<extRefNbr>",
    "orderConfig": {
      "designID": <designID>,
      "mailClass": "<class>",
      "globalDesignVariables": [
        {
          "key": "<frontcard>",
          "value": "https://portal.pcmintegrations.com/uploads/hq3rlfzh.rli.jpg"
        },
        {
          "key": "<backcard>",
          "value": "https://portal.pcmintegrations.com/uploads/4ehladjf.qsz.jpg"
        },
        {
          "key": "<companyaddress>",
          "value": "10 Main St"
        },
        {
          "key": "<companycity>",
          "value": "Tampa"
        },
        {
          "key": "<companyname>",
          "value": "PostcardMania"
        },
        {
          "key": "<companystate>",
          "value": "FL"
        },
        {
          "key": "<companyzipcode>",
          "value": "33626"
        }
      ]
    },
    "recipientList": [
      {
        "firstName": "<firstName>",
        "lastName": "<lastName>",
        "address": "<address>",
        "address2": "",
        "city": "<city>",
        "state": "<state>",
        "zipCode": "<zip>"
      }
    ]
  }
]

Maybe your design id doesn’t have quotations

1 Like

Amateur hour from me tonight. Now just have to clean up the “Argument error, options.body”. Appreciate the help, @doug.burden!

Haha no problem. Can you send me a proper request from documentation?

You bet!

Request:

curl --request POST \
  --url https://api.pcmintegrations.com/v2/directmail-api/order \
  --header 'Accept: application/json' \
  --header 'Content-Type: Postcard' \
  --data '[
  {
    "extRefNbr": "PBI",
    "orderConfig": {
      "designID": 2106,
      "mailClass": "FirstClass",
      "globalDesignVariables": [
        {
          "key": "frontcard",
          "value": "https://portal.pcmintegrations.com/uploads/hq3rlfzh.rli.jpg"
        },
        {
          "key": "backcard",
          "value": "https://portal.pcmintegrations.com/uploads/4ehladjf.qsz.jpg"
        },
        {
          "key": "companyaddress",
          "value": "10 Main St"
        },
        {
          "key": "companycity",
          "value": "Tampa"
        },
        {
          "key": "companyname",
          "value": "PostcardMania"
        },
        {
          "key": "companystate",
          "value": "FL"
        },
        {
          "key": "companyzipcode",
          "value": "33626"
        }
      ]
    },
    "recipientList": [
      {
        "firstName": "Brock",
        "lastName": "Lee",
        "address": "2145 Sunnydale Blvd",
        "address2": "",
        "city": "Clearwater",
        "state": "FL",
        "zipCode": "33765",
        "extRefNbr": "6912Test",
        "recipientDesignVariables": []
      }
    ]
  }
]'

Response:

{
  "batchID": 0,
  "successfulOrders": [
    {
      "orderID": 0,
      "orderIndex": 0,
      "extRefNbr": "string",
      "errors": {
        "message": "string"
      },
      "successfulRecipientCount": 0,
      "failedRecipientCount": 0,
      "failedRecipientList": {
        "recipientIndex": 0,
        "extRefNbr": "string",
        "missingFields": [
          "string"
        ]
      }
    }
  ],
  "failedOrders": [
    {
      "orderID": 0,
      "orderIndex": 0,
      "extRefNbr": "string",
      "errors": {
        "message": "string"
      },
      "successfulRecipientCount": 0,
      "failedRecipientCount": 0,
      "failedRecipientList": {
        "recipientIndex": 0,
        "extRefNbr": "string",
        "missingFields": [
          "string"
        ]
      }
    }
  ]
}

Ok so right off the rip, your data is an array so you’re going to have to make use of the operator ‘format as text’ here with a nested format as text for both the global design variables and recipient list. So your body will look like

[<data>] and that’s it. Then in your bubble workflow in this api call is where you’ll search for your data and then use format as text and form your json body there.

1 Like

Like this?

Wow, I wouldn’t have had the slightest clue to do that. I’ll try to set up the rest in the workflow.

Make sure to untic private

1 Like

Indeed, kicking myself for posting that too early.


Still getting an undefined JSON error so I’m pouring over your array API thread now. I have a lot to learn…

I’m gonna fiddle around with this some more. In the meantime, I’ll mark your post above as the solution :white_check_mark:.

1 Like