Write api fields (url)

I’m trying to use the write API to create pages dynamically. Unfortunately, the documentation is severely lacking, so I’ve had to guess at what field names should be. I’ve been able to determine the meta tags, title, description, but I cannot find what to use for the url / slug. Anyone had success with this or know where to find this information?

Builder content link

@nathan-applied any news on this? i’m running into the same problems.

Hi there,

Thank you for reaching out to support!

If you go to builder.io/api-explorer and check a content object for any entry, you can edit any field there and put it in the Write API and it should update in builder.

For the data that goes inside of the data object, these are typically found in the custom fields you set up when creating a model: Loom | Free Screen & Video Recording Software | Loom

Here’s a video of a sample post using the Write API and specifying the url path: Loom | Free Screen & Video Recording Software | Loom

Hope this was able to provide some clarification!

Hi @nicke920 , thanks for the reply. When I inspect a style-page that was created it shows the url as data.url in the object. However if I try to create a page with that attribute it is left empty.
This is a style-page object:

{
  "results": [
    {
      "createdDate": 1667233235611,
      "data": {
        "description": "adfasdf",
        "metaTags": "test,tag1",
        "target": "test123",
        "title": "Test PAGE",
        "url": "/test1234"
      },
      "id": "df85f31500e6406481ef8cc091fa9e86",
      "modelId": "109174e05be1415ba885ca1a1fccbb3c",
      "name": "TEST!",
      "published": "published",
      "target": {
        "urlPath": "test111"
      },
      "url": "/test123",
      "createdBy": "PfMzVdcytGZW3Cx5c0bt2wPcCan1",
      "lastUpdated": 1667234870129,
      "lastUpdatedBy": "PfMzVdcytGZW3Cx5c0bt2wPcCan1",
      "meta": {
        "kind": "page",
        "lastPreviewUrl": "https://site.fdc-dev.com/test1234?builder.space=16a0905ab0f6474197d24babc69e9bfc&builder.cachebust=true&builder.preview=style-page&builder.noCache=true&__builder_editing__=true&builder.overrides.style-page=df85f31500e6406481ef8cc091fa9e86&builder.overrides.df85f31500e6406481ef8cc091fa9e86=df85f31500e6406481ef8cc091fa9e86"
      },
      "query": [
        {
          "@type": "@builder.io/core:Query",
          "operator": "is",
          "property": "urlPath",
          "value": "/test1234"
        }
      ],
      "testRatio": 1,
      "variations": {},
      "firstPublished": 1667233385545,
      "rev": "4n1w13u1j4"
    }
  ]
}

But if I post to the Builder.io: Drag and drop Visual CMS endpoint with the following object, the url field is not populated. All other fields are:

{
   "name":"TEST!",
   "data":{
      "url":"/test12345",
      "title":"Test PAGE",
      "metaTags":"test,tag1",
      "description":"adfasdf"
   }
}
1 Like

Thank you for the video @nicke920. To clarify, the “Page url” or “Target” (as shown on list page) is what I’m having trouble creating via write API. The other fields are working.

Hi Nathan,

In order to pass in properly the url, you’ll need to query the urlPath to update/create it. See: Loom | Free Screen & Video Recording Software | Loom

To query, add this outside the data object, where the value is the url slug that you want to pass in:

"query": [
            {
              "property": "urlPath",
              "operator": "is", 
              "value": "/builder-demo-page" 
            }
          ],

Give the above a shot and please let me know how it goes.

1 Like

Hi @nicke920 , that worked! Thanks so much. I’m still a bit confused as to why the query is performing updates/inserts, but works for me.

Hi @nathan-applied ,

That is great news!

The reason is because technically urlPath is not an input attribute like ‘title’, ‘description’ , and such. urlPath and device are what we call targeting attributes, and not an input attribute on the content itself.

I’ve linked below two pieces of documentation regarding targeting:

1 Like

awesome! this worked for me also! thnx for the help

@wikkes That’s awesome to hear! I’m glad :slight_smile: